zipmark 0.0.1.beta.2 → 0.0.1.beta.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,20 +4,49 @@ The Zipmark Ruby Client library is used to interact with Zipmark's [API](https:/
4
4
 
5
5
  ## Installation
6
6
 
7
- ### Requirements
7
+ ```sh
8
+ gem install zipmark
9
+ ```
10
+ or in your Gemfile
8
11
 
9
- ## Initialization
10
-
11
- ## Usage Examples
12
+ ```ruby
13
+ gem "zipmark"
14
+ ```
12
15
 
13
16
  ### Instantiating a client
14
17
 
15
- Application Identifier and Application Secret should be replaced with the vendor application identifier and secret provided by Zipmark.
18
+ ```ruby
19
+ require 'zipmark'
20
+
21
+ client = Zipmark::Client.new(
22
+ :application_id => "app-id",
23
+ :application_secret => "my-secret",
24
+ :vendor_identifier => "vendor-ident"
25
+ )
26
+ ```
27
+
28
+ Vendor Identifier, Application Identifier, Application Secret should be replaced with the
29
+ values provided by Zipmark.
30
+
16
31
 
17
32
  ### Production Mode
18
33
 
34
+ By default, Zipmark::Client sends all requests to our sandbox environment. This environment is identical to production except money never actually is moved. When you are putting your application into production and want people to actually be able to pay, you need to turn production mode on.
35
+
36
+ ```ruby
37
+ client = Zipmark::Client.new(
38
+ :application_id => "app-id",
39
+ :application_secret => "my-secret",
40
+ :vendor_identifier => "vendor-ident",
41
+ :production => true
42
+ )
43
+ ```
44
+
19
45
  ### Loading a Bill from a known Bill ID
20
46
 
47
+ ```ruby
48
+ client.bills.find("bill-id")
49
+ ```
21
50
 
22
51
  ### Discovering available resources
23
52
 
@@ -37,6 +37,14 @@ module Zipmark
37
37
  self.class.delete(path, adapter_options)
38
38
  end
39
39
 
40
+ def successful?(response)
41
+ response.code >= 200 && response.code < 300
42
+ end
43
+
44
+ def validation_error?(response)
45
+ response.code == 422
46
+ end
47
+
40
48
  private
41
49
  def adapter_options
42
50
  {
@@ -50,6 +50,14 @@ module Zipmark
50
50
  end
51
51
  end
52
52
 
53
+ def successful?(response)
54
+ response.code >= 200 && response.code < 300
55
+ end
56
+
57
+ def validation_error?(response)
58
+ response.code == 422
59
+ end
60
+
53
61
  private
54
62
  def adapter_options
55
63
  {
@@ -60,6 +60,20 @@ module Zipmark
60
60
  adapter.delete(path)
61
61
  end
62
62
 
63
+ # Public: Check for an ok response code (200-299)
64
+ #
65
+ # response - A response object specific to the adapter
66
+ def successful?(response)
67
+ adapter.successful?(response)
68
+ end
69
+
70
+ # Public: Check for a validation error response (422)
71
+ #
72
+ # response - A response object specific to the adapter
73
+ def validation_error?(response)
74
+ adapter.validation_error?(response)
75
+ end
76
+
63
77
  def build_callback(request)
64
78
  Zipmark::Callback.new(request, :client => self)
65
79
  end
@@ -34,10 +34,10 @@ module Zipmark
34
34
 
35
35
  def apply_response(response)
36
36
  object = JSON.parse(response.body)
37
- if response.ok?
37
+ if client.successful?(response)
38
38
  @attributes = object[resource_type]
39
- elsif response.code == 422
40
- @errors = object
39
+ elsif client.validation_error?(response)
40
+ @errors = object["errors"]
41
41
  else
42
42
  raise Zipmark::Error.new(object)
43
43
  end
@@ -1,3 +1,3 @@
1
1
  module Zipmark
2
- VERSION = '0.0.1.beta.2'
2
+ VERSION = '0.0.1.beta.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.beta.2
4
+ version: 0.0.1.beta.3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-20 00:00:00.000000000 Z
12
+ date: 2012-11-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Simple Client Library to connect to the Zipmark API
15
15
  email: jake@zipmark.com