Class Request::Query
In: lib/violet/request.rb
Parent: Object
Event Action TtsMessage SetEarsPosition EventCollection Enumerable Query GET_EARS_POSITION Base Request dot/f_8.png

this class is used to "translate" our Events into URLs. Examples:

    TODO

see api.nabaztag.com/docs/home.html

Methods

new   send!   to_url  

Public Class methods

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.

[Source]

    # File lib/violet/request.rb, line 87
87:     def initialize h
88:       raise ArgumentError.new('event parameter has no "to_url" method or is empty') unless h[:event] and h[:event].respond_to?(:to_url)
89:       raise ArgumentError.new('need a :serial') unless h[:serial]
90:       raise ArgumentError.new('need a :token' ) unless h[:token]
91: 
92:       @event, @serial, @token = h[:event], h[:serial], h[:token]
93:     end

Public Instance methods

TODO

[Source]

     # File lib/violet/request.rb, line 101
101:     def send! response_type=nil
102:       # TODO: rescue ?
103:       rsp = open(self.to_url) { |rsp| rsp.read }
104:       if response_type == :xml then rsp else Response.parse(rsp) end
105:     end

return the complet url: API_URL with the serial, token and options.

[Source]

    # File lib/violet/request.rb, line 96
96:     def to_url
97:       API_URL+'?' << [ "token=#{@token}", "sn=#{@serial}", @event.to_url ].join('&')
98:     end

[Validate]