Class: Ondotori::WebAPI::Api::DataParams
- Inherits:
-
ParamsBase
- Object
- ParamsBase
- Ondotori::WebAPI::Api::DataParams
- Defined in:
- lib/ondotori/webapi/api/params.rb
Instance Method Summary collapse
-
#initialize(param, serial, from: nil, to: nil, limit: nil) ⇒ DataParams
constructor
A new instance of DataParams.
- #to_ondotori_param ⇒ Object
- #validate(serial, from, to, _limit) ⇒ Object
Constructor Details
#initialize(param, serial, from: nil, to: nil, limit: nil) ⇒ DataParams
Returns a new instance of DataParams.
84 85 86 87 88 89 90 91 |
# File 'lib/ondotori/webapi/api/params.rb', line 84 def initialize(param, serial, from: nil, to: nil, limit: nil) super(param) validate(serial, from, to, limit) @serial = serial @from = from @to = to @limit = limit.nil? ? 0 : [0, limit].max end |
Instance Method Details
#to_ondotori_param ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/ondotori/webapi/api/params.rb', line 108 def to_ondotori_param params = super params["remote-serial"] = @serial params["unixtime-from"] = @from.to_i unless @from.nil? params["unixtime-to"] = @to.to_i unless @to.nil? params["number"] = @limit if @limit != 0 params end |
#validate(serial, from, to, _limit) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ondotori/webapi/api/params.rb', line 93 def validate(serial, from, to, _limit) unless serial.instance_of?(String) raise Ondotori::WebAPI::Api::Errors::InvaildParameter.new( "serial must be String.", 9991 ) end [from, to].each do |param| next if param.nil? || param.instance_of?(Time) raise Ondotori::WebAPI::Api::Errors::InvaildParameter.new( "from and to parameter must be nil or Time.", 9992 ) end end |