Class: Vertigo::Client
- Inherits:
-
Object
- Object
- Vertigo::Client
- Defined in:
- lib/vertigo/client.rb
Overview
Simple wrapper around the VerticalResponse SOAP API.
API Versioning
As of 2011.08.15, VerticalResponse changes and remove API calls, but still call it API “v1.0” each time. These mandatory API changes could break your code (although we have never experienced that personally).
Inquiring about their versioning policy got this response: “For a variety of internal reasons, this is still considered the 1.0 release of our API. We’re currently exploring adding real versioning to our API to avoid these kinds of issues going forward.”
Because of this, Vertigo::Client regenerates the RPC driver when instantiated as the generated code for VRAPI.wsdl becomes stale over time. Generating the driver incurs a startup cost, but it’s minimal.
Constant Summary collapse
- DURATION_MINUTES =
4
- WSDL_URL =
'https://api.verticalresponse.com/partner-wsdl/1.0/VRAPI.wsdl'
Instance Method Summary collapse
-
#initialize(username, password, opts = {}) ⇒ Client
constructor
A new instance of Client.
-
#method_missing(name, *args, &block) ⇒ Object
This modification lets us write API calls in a more “Rubyish” manner.
Constructor Details
#initialize(username, password, opts = {}) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vertigo/client.rb', line 31 def initialize(username, password, opts = {}) session_duration_minutes = opts[:duration_minutes] || DURATION_MINUTES wsdl_url = opts[:wsdl_url] || WSDL_URL @api = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver @session_id = @api.login( 'username' => username.to_s, 'password' => password.to_s, 'session_duration_minutes' => session_duration_minutes ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
camelCase method names are still supported.
This modification lets us write API calls in a more “Rubyish” manner.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vertigo/client.rb', line 54 def method_missing(name, *args, &block) = args[0] vr_name = camelize_meth(name).intern if args.length > 1 raise ArgumentError, 'Unexpected number of arguments (not 0 or 1)' elsif && !.respond_to?(:keys) raise ArgumentError, "options does not respond to :keys (options.class: #{.class}, options: #{.inspect})" end if @api.respond_to?(vr_name) vr_args = ? stringify_keys() : {} @api.send(vr_name, {'session_id' => @session_id}.merge(vr_args)) else raise NoMethodError, "Undefined VerticalResponse API call: #{vr_name.inspect}" end end |