Class: Zipmark::Client
- Inherits:
-
Object
- Object
- Zipmark::Client
- Defined in:
- lib/zipmark/client.rb
Overview
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Public: Gets the Adapter.
Instance Method Summary collapse
- #build_callback(request) ⇒ Object
-
#delete(path) ⇒ Object
Public: Send a DELETE Request to the given API Path.
- #display ⇒ Object
-
#get(path) ⇒ Object
Public: Send a GET Request to the given API Path.
- #identifier ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
Public: Initialize a Zipmark Client.
- #method_missing(meth, *args, &block) ⇒ Object
-
#post(path, body) ⇒ Object
Public: Send a POST Request to the given API Path.
-
#put(path, body) ⇒ Object
Public: Send a PUT Request to the given API Path.
- #resources ⇒ Object
-
#successful?(response) ⇒ Boolean
Public: Check for an ok response code (200-299).
-
#validation_error?(response) ⇒ Boolean
Public: Check for a validation error response (422).
- #workflow ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Public: Initialize a Zipmark Client
options - Hash options used to configure the Client (default: {}) application_id - The Identifier for your application application_secret - The Secret for your Application
:adapter - The Instance of an Adapter that wraps your preferred HTTP Client
:production - The Boolean determining if Production Mode is enabled
26 27 28 29 30 31 32 33 |
# File 'lib/zipmark/client.rb', line 26 def initialize( = {}) @adapter = [:adapter] || Zipmark::Adapters::HTTPClientAdapter.new adapter.production = [:production] adapter.username = [:application_id] adapter.password = [:application_secret] @identifier = [:vendor_identifier] @resources = load_resources end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
91 92 93 |
# File 'lib/zipmark/client.rb', line 91 def method_missing(meth, *args, &block) @resources[meth.to_s] || raise(NoMethodError, "No resource or method: '#{meth}'") end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Public: Gets the Adapter.
11 12 13 |
# File 'lib/zipmark/client.rb', line 11 def adapter @adapter end |
Instance Method Details
#build_callback(request) ⇒ Object
87 88 89 |
# File 'lib/zipmark/client.rb', line 87 def build_callback(request) Zipmark::Callback.new(request, :client => self) end |
#delete(path) ⇒ Object
Public: Send a DELETE Request to the given API Path
path - A String which can be a relative path to the API root, or a full URL
69 70 71 |
# File 'lib/zipmark/client.rb', line 69 def delete(path) adapter.delete(path) end |
#display ⇒ Object
95 96 97 |
# File 'lib/zipmark/client.rb', line 95 def display DisplayProxy.new(self) end |
#get(path) ⇒ Object
Public: Send a GET Request to the given API Path
path - A String which can be a relative path to the API root, or a full URL
46 47 48 |
# File 'lib/zipmark/client.rb', line 46 def get(path) adapter.get(path) end |
#identifier ⇒ Object
35 36 37 |
# File 'lib/zipmark/client.rb', line 35 def identifier @identifier end |
#post(path, body) ⇒ Object
Public: Send a POST Request to the given API Path
path - A String which can be a relative path to the API root, or a full URL
body - A Object which responds to to_json and represents the body of the POST
54 55 56 |
# File 'lib/zipmark/client.rb', line 54 def post(path, body) adapter.post(path, body) end |
#put(path, body) ⇒ Object
Public: Send a PUT Request to the given API Path
path - A String which can be a relative path to the API root, or a full URL
body - A Object which responds to to_json and represents the body of the PUT
62 63 64 |
# File 'lib/zipmark/client.rb', line 62 def put(path, body) adapter.put(path, body) end |
#resources ⇒ Object
39 40 41 |
# File 'lib/zipmark/client.rb', line 39 def resources @resources end |
#successful?(response) ⇒ Boolean
Public: Check for an ok response code (200-299)
response - A response object specific to the adapter
76 77 78 |
# File 'lib/zipmark/client.rb', line 76 def successful?(response) adapter.successful?(response) end |
#validation_error?(response) ⇒ Boolean
Public: Check for a validation error response (422)
response - A response object specific to the adapter
83 84 85 |
# File 'lib/zipmark/client.rb', line 83 def validation_error?(response) adapter.validation_error?(response) end |
#workflow ⇒ Object
99 100 101 |
# File 'lib/zipmark/client.rb', line 99 def workflow WorkflowProxy.new(self) end |