Class: Request::Query
- Inherits:
-
Object
- Object
- Request::Query
- Defined in:
- lib/violet/request.rb
Overview
this class is used to “translate” our Events into URLs. Examples:
TODO
Instance Method Summary collapse
-
#initialize(h) ⇒ Query
constructor
create a new Query object with the give parameters.
-
#send!(response_type = nil) ⇒ Object
TODO.
-
#to_url ⇒ Object
return the complet url: API_URL with the
serial,tokenand options.
Constructor Details
#initialize(h) ⇒ Query
create a new Query object with the give parameters. serial and token parameters should be checked at a higher level. event parameter is usually an Event object, but you can give any Object that respond to to_url.
87 88 89 90 91 92 93 |
# File 'lib/violet/request.rb', line 87 def initialize h raise ArgumentError.new('event parameter has no "to_url" method or is empty') unless h[:event] and h[:event].respond_to?(:to_url) raise ArgumentError.new('need a :serial') unless h[:serial] raise ArgumentError.new('need a :token' ) unless h[:token] @event, @serial, @token = h[:event], h[:serial], h[:token] end |
Instance Method Details
#send!(response_type = nil) ⇒ Object
TODO
101 102 103 104 105 |
# File 'lib/violet/request.rb', line 101 def send! response_type=nil # TODO: rescue ? rsp = open(self.to_url) { |rsp| rsp.read } if response_type == :xml then rsp else Response.parse(rsp) end end |
#to_url ⇒ Object
return the complet url: API_URL with the serial, token and options.
96 97 98 |
# File 'lib/violet/request.rb', line 96 def to_url API_URL+'?' << [ "token=#{@token}", "sn=#{@serial}", @event.to_url ].join('&') end |