Class: Zanox::API::Client
- Inherits:
-
Object
- Object
- Zanox::API::Client
- Defined in:
- lib/zanox_api.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(service_name, options = {}) ⇒ Client
constructor
Service name is one of ‘publisherservice’, ‘dataservice’ or ‘connectservice’ Valid options are: * connect_id * secret_key * api_url (optional, defaults to the current API url: api.zanox.com/wsdl/2011-03-01’) * normalize_responses: Get the responses normalized.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize(service_name, options = {}) ⇒ Client
Service name is one of ‘publisherservice’, ‘dataservice’ or ‘connectservice’ Valid options are:
* connect_id
* secret_key
* api_url (optional, defaults to the current API url: http://api.zanox.com/wsdl/2011-03-01')
* normalize_responses: Get the responses normalized.
This means that if the response is an array it will return just the array itself, for example
* log, log_level, logger, pretty_print_xml: This options are passed directly to `Savon.client`
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/zanox_api.rb', line 63 def initialize(service_name, = {}) @service_name = service_name @connect_id = [:connect_id] @secret_key = [:secret_key] @base_api_url = [:api_url] || 'https://api.zanox.com/wsdl/2011-03-01' @normalize_responses = [:normalize_responses] @savon_client = Savon.client({ wsdl: @base_api_url, log: [:log], log_level: [:log_level], logger: [:logger], pretty_print_xml: [:pretty_print_xml], }) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/zanox_api.rb', line 79 def method_missing(name, *args, &block) name = name.to_s params = if name.start_with?('authenticated_') name = name.gsub(/^authenticated_/, '') Zanox::API.params_for_method(@service_name, name.gsub('_', '').downcase, @secret_key) else {} end params.merge!(connect_id: @connect_id) params.merge!(args[0] || {}) response = @savon_client.call(name.to_sym, message: params) contents = response.body[(name + '_response').to_sym] if @normalize_responses Zanox::API.normalize_response(contents) else contents end end |