Class: ObiWan::XmlClient
- Inherits:
-
Object
- Object
- ObiWan::XmlClient
- Defined in:
- lib/obi-wan/messages.rb,
lib/obi-wan/xml-client.rb
Defined Under Namespace
Modules: CancelOffer, Functions, Instrument, ListInstruments, ListSubscriptions, RegisterOfferSubscription
Constant Summary collapse
- @@DEFAULT_CALLS =
{ :register_offer_subscription => RegisterOfferSubscription, :create_instrument => Instrument, :edit_instrument => Instrument, :list_instruments => ListInstruments, :list_subscriptions => ListSubscriptions, :cancel_offer => CancelOffer }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ XmlClient
constructor
A new instance of XmlClient.
- #register(method, message_handler, synchronous = true) ⇒ Object
- #set_asynchronous(method, target = ) ⇒ Object
- #set_synchronous(method, target = ) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ XmlClient
Returns a new instance of XmlClient.
57 58 59 60 61 62 |
# File 'lib/obi-wan/xml-client.rb', line 57 def initialize(={}) @config = @@DEFAULT_CALLS.each do |k,v| register k, v, true end end |
Instance Method Details
#register(method, message_handler, synchronous = true) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/obi-wan/xml-client.rb', line 23 def register(method, , synchronous = true) method = method.to_sym self.send(:define_singleton_method, method) do |tg, *args| query = { :devId => @config[:dev_id], :cipherdata => @config[:cipherdata], :hexresult => @config[:hexresult], :tg => tg, :sg => @config[:sg] } header = [['Content-Type', 'text/xml'], ['Accept','*/*'], ['User-Agent', 'obi-wan-0.0.1']] req = HTTPClient.new req.debug_dev = @config[:debug] if @config[:debug] if synchronous res = req.request(:POST, @config[:base_url], query, .obi_request(*args), header) return resp_to_xml(res) else return req.request_async(:POST, @config[:base_url], query, .obi_request(*args), header) end end end |
#set_asynchronous(method, target = ) ⇒ Object
49 50 51 |
# File 'lib/obi-wan/xml-client.rb', line 49 def set_asynchronous(method, target = @@DEFAULT_CALLS[method]) register method, @@DEFAULT_CALLS[method], false end |
#set_synchronous(method, target = ) ⇒ Object
53 54 55 |
# File 'lib/obi-wan/xml-client.rb', line 53 def set_synchronous(method, target = @@DEFAULT_CALLS[method]) register method, @@DEFAULT_CALLS[method], true end |