zipmark 0.0.1.beta.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 182b2e5fcdd45ab02d17a1bb1929a15e8ff32dd6
4
+ data.tar.gz: ffb4526a00d6b9a25c9b85d9a8ecac58f716fe6e
5
+ SHA512:
6
+ metadata.gz: 4f8931c22d63a4fa904994cdc366034e4ade4e654bc4dcb8d9768a924954b65168027fa68d667c262ffa358718550c9138cece796c368fb9861cf6dd18b6a967
7
+ data.tar.gz: d4659a17ce9cc02c5bacc5ed4d71220d06f6abcfd5fc566e33fc50b493a14a488eac538e78e9c2f11030e6d8e89d6305919d1cf55245e6895b81b96ab64c6011
data/README.md CHANGED
@@ -123,10 +123,36 @@ The Zipmark_Iterator can be used to iterate through all objects of a given resou
123
123
 
124
124
  The client is able to process, verify and extract data from callbacks received from the Zipmark service.
125
125
 
126
+ #### Setting up a Callback
127
+
128
+ Callbacks have to be enabled by creating a callback with an event type and the callback URL. To enable Zipmark to send a callback:
129
+
130
+ ```ruby
131
+ callback = client.callbacks.create(
132
+ :url => 'https://example.com/callback',
133
+ :event => 'name_of_event')
134
+ ```
135
+
136
+ The possible event names include:
137
+
138
+ * bill.create
139
+ * bill.update
140
+ * bill_payment.create
141
+ * bill_payment.update
142
+
126
143
  #### Loading a callback response
127
144
 
128
145
  #### Verifying a callback
129
146
 
147
+ To verify a callback, you need the entire request (headers, request body, etc.) so it has to be done from the context of the controller layer (or a model that is passed the entire request).
148
+
149
+ ```ruby
150
+ # In a controller:
151
+ client.build_callback(request).valid?
152
+ ```
153
+
154
+ Will return true or false, based on a signed header from Zipmark.
155
+
130
156
  #### Retrieving the callback data
131
157
 
132
158
  Valid callbacks contain events, object types and objects. The below functions will return their respective values/objects, or null if the callback is invalid.
@@ -144,3 +170,53 @@ bundle install
144
170
 
145
171
  bundle exec rake spec
146
172
  ```
173
+
174
+
175
+ #### Creating a Token
176
+
177
+ For a Workflow
178
+ ```
179
+ workflow = client.workflow.create(name: 'enrollment', data: { customer_id: 'some unique permanent id' })
180
+ workflow.token
181
+ ```
182
+
183
+ For a Display
184
+ ```
185
+ display = client.display.create(name: 'recent-transaction', data: { customer_id: 'some unique permanet id' })
186
+ display.token
187
+ ```
188
+
189
+
190
+ #### Deposits Resource
191
+
192
+ **Get deposits**
193
+ `client.get('deposits')`
194
+
195
+ **Get a specific deposit**
196
+ `client.get('deposits/DEPOSIT_ID')`
197
+
198
+ **Cancel a deposit**
199
+ `client.put('deposits/DEPOSIT_ID/cancel', '')`
200
+
201
+ **Make a Depost**
202
+ ```ruby
203
+ body = { :deposit => { :customer_identifier => 'their unique and permanent identifier', :amount_cents => 1000, :memo => 'an example memo' } }
204
+ client.post('deposits', body)
205
+ ```
206
+
207
+ #### Customers Resource
208
+
209
+ **Get Customers**
210
+ `client.get('customers')`
211
+
212
+ **Get a specific customer**
213
+ `client.get('customers/CUSTOMER_ID')`
214
+
215
+ #### Accounts Resource
216
+
217
+ **Get accounts**
218
+ `client.get('accounts')`
219
+
220
+ **Get a specific account**
221
+ `client.get('accounts/ACCOUNT_ID')`
222
+
@@ -9,6 +9,11 @@ require 'zipmark/pagination'
9
9
  require 'zipmark/resource'
10
10
  require 'zipmark/util'
11
11
  require 'zipmark/version'
12
+ require 'zipmark/token'
13
+ require 'zipmark/display'
14
+ require 'zipmark/display_proxy'
15
+ require 'zipmark/workflow'
16
+ require 'zipmark/workflow_proxy'
12
17
 
13
18
  require 'zipmark/adapters/httpclient_adapter'
14
19
 
@@ -21,7 +26,7 @@ module Zipmark
21
26
  SANDBOX_API_ENDPOINT = 'https://sandbox.zipmark.com'
22
27
 
23
28
  # Public: String Representing the Current Zipmark API Version
24
- API_VERSION = 'v2'
29
+ API_VERSION = 'v3'
25
30
 
26
31
  # Public: Error that is raised when a client is expected but not found
27
32
  class ClientError < StandardError; end
@@ -14,7 +14,11 @@ module Zipmark
14
14
  end
15
15
 
16
16
  def initialize_client
17
- client = HTTPClient.new
17
+ client = HTTPClient.new(
18
+ default_header: { 'Content-Type' => 'application/json', 'Accept' => api_accept_mime },
19
+ force_basic_auth: true
20
+ )
21
+ client.ssl_config.ssl_version = :TLSv1
18
22
  client.set_auth(api_endpoint, username, password)
19
23
  return client
20
24
  end
@@ -28,19 +32,19 @@ module Zipmark
28
32
  end
29
33
 
30
34
  def get(path)
31
- httpclient.get(url_for(path), adapter_options)
35
+ httpclient.get(url_for(path))
32
36
  end
33
37
 
34
38
  def post(path, body)
35
- httpclient.post(url_for(path), adapter_options.merge(:body => body.to_json))
39
+ httpclient.post(url_for(path), :body => body.to_json)
36
40
  end
37
41
 
38
42
  def put(path, body)
39
- httpclient.put(url_for(path), adapter_options.merge(:body => body.to_json))
43
+ httpclient.put(url_for(path), :body => body.to_json)
40
44
  end
41
45
 
42
46
  def delete(path)
43
- httpclient.delete(url_for(path), adapter_options)
47
+ httpclient.delete(url_for(path))
44
48
  end
45
49
 
46
50
  def url_for(path)
@@ -57,13 +61,6 @@ module Zipmark
57
61
  def validation_error?(response)
58
62
  response.code == 422
59
63
  end
60
-
61
- private
62
- def adapter_options
63
- {
64
- :header => { 'Content-Type' => 'application/json', 'Accept' => api_accept_mime }
65
- }
66
- end
67
64
  end
68
65
  end
69
66
  end
@@ -92,13 +92,21 @@ module Zipmark
92
92
  @resources[meth.to_s] || raise(NoMethodError, "No resource or method: '#{meth}'")
93
93
  end
94
94
 
95
+ def display
96
+ DisplayProxy.new(self)
97
+ end
98
+
99
+ def workflow
100
+ WorkflowProxy.new(self)
101
+ end
102
+
95
103
  private
96
104
  def load_resources
97
105
  hash = {}
98
106
  response = get("/")
99
107
  object = JSON.parse(response.body)
100
108
  if successful?(response)
101
- object["vendor_root"]["links"].each {|link| hash[link["rel"]] = Resource.new({ :client => self }.merge(link)) }
109
+ object["root"]["links"].each {|link| hash[link["rel"]] = Resource.new({ :client => self }.merge(link)) }
102
110
  else
103
111
  raise Zipmark::Error.new(object)
104
112
  end
@@ -0,0 +1,21 @@
1
+ class Display
2
+ attr_accessor :client, :data, :name
3
+
4
+ def initialize(options = {})
5
+ self.client = options[:client]
6
+ self.data = options[:data]
7
+ self.name = options[:name]
8
+ end
9
+
10
+ def token
11
+ JWT.encode(
12
+ {
13
+ display: name,
14
+ application_id: client.adapter.username,
15
+ iat: Time.now.to_i,
16
+ data: data
17
+ },
18
+ client.adapter.password
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ class DisplayProxy
2
+ attr_accessor :client
3
+
4
+ def initialize(client)
5
+ self.client = client
6
+ end
7
+
8
+ def create(options = {})
9
+ Display.new(options.merge(client: client))
10
+ end
11
+ end
@@ -29,6 +29,10 @@ module Zipmark
29
29
  attributes["id"]
30
30
  end
31
31
 
32
+ def indentifier
33
+ attributes['identifier']
34
+ end
35
+
32
36
  def method_missing(meth, *args, &block)
33
37
  if meth =~ /=$/
34
38
  dirty_attributes[meth.to_s.sub(/=$/, '')] = args.first
@@ -60,7 +64,7 @@ module Zipmark
60
64
  end
61
65
 
62
66
  def valid?
63
- !!(id && errors.empty?)
67
+ !!((id ||identifier) && errors.empty?)
64
68
  end
65
69
 
66
70
  def updated_at
@@ -1,6 +1,6 @@
1
1
  module Zipmark
2
2
  class Link
3
- attr_accessor :name, :title, :href
3
+ attr_accessor :rel, :title, :href
4
4
 
5
5
  def initialize(options)
6
6
  link = Util.stringify_keys(options)
@@ -8,17 +8,5 @@ module Zipmark
8
8
  @title = link["title"]
9
9
  @href = link["href"]
10
10
  end
11
-
12
- def rel
13
- @rel
14
- end
15
-
16
- def title
17
- @title
18
- end
19
-
20
- def href
21
- @href
22
- end
23
11
  end
24
12
  end
@@ -0,0 +1,9 @@
1
+ require 'jwt'
2
+
3
+ module Zipmark
4
+ class Token
5
+ def self.encode(payload, application_secret)
6
+ JWT.encode(payload, application_secret)
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module Zipmark
2
- VERSION = '0.0.1.beta.10'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,21 @@
1
+ class Workflow
2
+ attr_accessor :client, :data, :name
3
+
4
+ def initialize(options = {})
5
+ self.client = options[:client]
6
+ self.data = options[:data]
7
+ self.name = options[:name]
8
+ end
9
+
10
+ def token
11
+ JWT.encode(
12
+ {
13
+ workflow: name,
14
+ application_id: client.adapter.username,
15
+ iat: Time.now.to_i,
16
+ data: data
17
+ },
18
+ client.adapter.password
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ class WorkflowProxy
2
+ attr_accessor :client
3
+
4
+ def initialize(client)
5
+ self.client = client
6
+ end
7
+
8
+ def create(options = {})
9
+ Workflow.new(options.merge(client: client))
10
+ end
11
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta.10
5
- prerelease: 6
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jake Howerton
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-08 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Simple Client Library to connect to the Zipmark API
15
14
  email: jake@zipmark.com
@@ -17,6 +16,10 @@ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
19
+ - CONTRIBUTING.md
20
+ - LICENSE
21
+ - README.md
22
+ - lib/zipmark.rb
20
23
  - lib/zipmark/action.rb
21
24
  - lib/zipmark/adapters/httparty_adapter.rb
22
25
  - lib/zipmark/adapters/httpclient_adapter.rb
@@ -24,6 +27,8 @@ files:
24
27
  - lib/zipmark/callback.rb
25
28
  - lib/zipmark/client.rb
26
29
  - lib/zipmark/collection.rb
30
+ - lib/zipmark/display.rb
31
+ - lib/zipmark/display_proxy.rb
27
32
  - lib/zipmark/documentation.rb
28
33
  - lib/zipmark/entity.rb
29
34
  - lib/zipmark/error.rb
@@ -32,34 +37,32 @@ files:
32
37
  - lib/zipmark/link.rb
33
38
  - lib/zipmark/pagination.rb
34
39
  - lib/zipmark/resource.rb
40
+ - lib/zipmark/token.rb
35
41
  - lib/zipmark/util.rb
36
42
  - lib/zipmark/version.rb
37
- - lib/zipmark.rb
38
- - LICENSE
39
- - CONTRIBUTING.md
40
- - README.md
43
+ - lib/zipmark/workflow.rb
44
+ - lib/zipmark/workflow_proxy.rb
41
45
  homepage: http://rubygems.org/gems/zipmark
42
46
  licenses: []
47
+ metadata: {}
43
48
  post_install_message:
44
49
  rdoc_options: []
45
50
  require_paths:
46
51
  - lib
47
52
  required_ruby_version: !ruby/object:Gem::Requirement
48
- none: false
49
53
  requirements:
50
- - - ! '>='
54
+ - - ">="
51
55
  - !ruby/object:Gem::Version
52
56
  version: '0'
53
57
  required_rubygems_version: !ruby/object:Gem::Requirement
54
- none: false
55
58
  requirements:
56
- - - ! '>'
59
+ - - ">="
57
60
  - !ruby/object:Gem::Version
58
- version: 1.3.1
61
+ version: '0'
59
62
  requirements: []
60
63
  rubyforge_project:
61
- rubygems_version: 1.8.25
64
+ rubygems_version: 2.2.2
62
65
  signing_key:
63
- specification_version: 3
66
+ specification_version: 4
64
67
  summary: Zipmark API Client Library
65
68
  test_files: []