Class: Zipmark::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/zipmark/client.rb

Overview

Public: The Zipmark API Client.

Examples

client = Zipmark::Client.new("app-id", "app-secret", :production => false)
client.get("/")

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @adapter = options[:adapter] || Zipmark::Adapters::HTTPClientAdapter.new
  adapter.production = options[:production]
  adapter.username = options[:application_id]
  adapter.password = options[:application_secret]
  @identifier = options[: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

#adapterObject (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

#displayObject



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

#identifierObject



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

#resourcesObject



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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


83
84
85
# File 'lib/zipmark/client.rb', line 83

def validation_error?(response)
  adapter.validation_error?(response)
end

#workflowObject



99
100
101
# File 'lib/zipmark/client.rb', line 99

def workflow
  WorkflowProxy.new(self)
end