Class: RemoteAPI
- Inherits:
-
Object
- Object
- RemoteAPI
- Defined in:
- lib/remote_api/version.rb,
lib/remote_api/xml.rb,
lib/remote_api/base.rb,
lib/remote_api/xml_response.rb
Overview
:nodoc:
Direct Known Subclasses
Defined Under Namespace
Modules: VERSION Classes: ResponseFailure, XML
Class Method Summary collapse
-
.call(params = {}) ⇒ Object
Instatiate and call the API in one step.
Instance Method Summary collapse
-
#call ⇒ Object
Execute an instance of an API object that has not been sent to the remote server yet.
-
#initialize(params = {}) ⇒ RemoteAPI
constructor
Prepare a new API object.
Constructor Details
#initialize(params = {}) ⇒ RemoteAPI
Prepare a new API object. This will not make the actual remote call until the call
method is used. To execute the API call immediately, use the call
class method.
Any options you pass in as a hash will be created as instance variables. So the below example will have an instance variable @foo
in the generated API object.
api = MyApi.new(:foo => 'bar')
api.call
api.some_result #=> "You said bar!"
24 25 26 27 28 |
# File 'lib/remote_api/base.rb', line 24 def initialize(params = {}) params.each do |k, v| instance_variable_set "@#{k}", v end end |
Class Method Details
.call(params = {}) ⇒ Object
Instatiate and call the API in one step.
api = MyApi.call(:foo => 'bar')
api.some_result #=> "You said bar!"
35 36 37 38 39 |
# File 'lib/remote_api/base.rb', line 35 def self.call(params = {}) returning new(params) do |api| api.call end end |
Instance Method Details
#call ⇒ Object
Execute an instance of an API object that has not been sent to the remote server yet.
api = MyApi.new(:foo => 'bar')
api.call
api.some_result #=> "You said bar!"
48 49 50 51 52 53 54 |
# File 'lib/remote_api/base.rb', line 48 def call returning self do send_request assert_success process end end |