zipmark 0.0.1.beta.8 → 0.0.1.beta.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -33,7 +33,6 @@ client = Zipmark::Client.new(
33
33
  Vendor Identifier, Application Identifier, Application Secret should be replaced with the
34
34
  values provided by Zipmark.
35
35
 
36
-
37
36
  ### Production Mode
38
37
 
39
38
  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.
@@ -53,16 +52,50 @@ client = Zipmark::Client.new(
53
52
  client.bills.find("bill-id")
54
53
  ```
55
54
 
55
+ Attempting to find a bill that doesn't exist will raise a Zipmark::NotFound error.
56
+
56
57
  ### Discovering available resources
57
58
 
58
59
  Resources will contain an array of all available resources.
59
60
 
61
+ ```ruby
62
+ client.resources.keys
63
+ ```
64
+
60
65
  ### Creating a new Bill
61
66
 
62
67
  Create a bill object, set required attributes, send it to Zipmark
63
68
 
69
+ ```ruby
70
+ bill = client.bills.create(
71
+ :identifier => "1234",
72
+ :amount_cents => 100,
73
+ :bill_template_id => bill_template_id,
74
+ :memo => "My memo",
75
+ :content => '{"memo":"My Memo"}',
76
+ :customer_id => "Customer 1",
77
+ :date => "20130805")
78
+ ```
79
+
64
80
  As an alternative, it is possible to build an object first and then save it afterwards
65
81
 
82
+ ```ruby
83
+ bill = client.bills.build(
84
+ :identifier => "1234",
85
+ :amount_cents => 100,
86
+ :bill_template_id => bill_template_id,
87
+ :memo => "My memo",
88
+ :content => '{"memo":"My Memo"}',
89
+ :customer_id => "Customer 1",
90
+ :date => "20130805")
91
+ bill.save
92
+ ```
93
+
94
+ Regardless of which method is used, if a bill is valid, it was successfully saved to Zipmark:
95
+
96
+ ```ruby
97
+ puts bill.errors unless bill.valid?
98
+ ```
66
99
 
67
100
  ### Updating an existing Bill
68
101
 
@@ -103,3 +136,11 @@ Valid callbacks contain events, object types and objects. The below functions w
103
136
  Please see the [Zipmark API](https://dev.zipmark.com) or contact Zipmark Support via [email](mailto:developers@zipmark.com) or [chat](http://bit.ly/zipmarkAPIchat) for more information.
104
137
 
105
138
  ## Unit/Acceptance Tests
139
+
140
+ Tests are written in rspec. To run the full test suite, execute the following:
141
+
142
+ ```
143
+ bundle install
144
+
145
+ bundle exec rake spec
146
+ ```
@@ -4,6 +4,7 @@ require 'zipmark/collection'
4
4
  require 'zipmark/entity'
5
5
  require 'zipmark/error'
6
6
  require 'zipmark/iterator'
7
+ require 'zipmark/link'
7
8
  require 'zipmark/pagination'
8
9
  require 'zipmark/resource'
9
10
  require 'zipmark/util'
@@ -27,4 +28,7 @@ module Zipmark
27
28
 
28
29
  # Public: Error that is raised when a Resource is malformed or invalid
29
30
  class ResourceError < StandardError; end
31
+
32
+ # Public: Error that is raised when a Resource cannot be found
33
+ class NotFoundError < StandardError; end
30
34
  end
@@ -36,6 +36,10 @@ module Zipmark
36
36
  @identifier
37
37
  end
38
38
 
39
+ def resources
40
+ @resources
41
+ end
42
+
39
43
  # Public: Send a GET Request to the given API Path
40
44
  #
41
45
  # path - A String which can be a relative path to the API root, or a full URL
@@ -10,7 +10,7 @@ module Zipmark
10
10
  end
11
11
 
12
12
  def items
13
- iterator.current_items
13
+ iterator.items
14
14
  end
15
15
 
16
16
  def length
@@ -1,6 +1,6 @@
1
1
  module Zipmark
2
2
  class Entity
3
- attr_accessor :attributes, :client, :resource_type, :errors, :dirty_attributes
3
+ attr_accessor :attributes, :client, :resource_type, :errors, :dirty_attributes, :links
4
4
 
5
5
  def initialize(options={})
6
6
  @errors = {}
@@ -8,6 +8,17 @@ module Zipmark
8
8
  @dirty_attributes = {}
9
9
  @client = @attributes.delete("client")
10
10
  @resource_type = @attributes.delete("resource_type")
11
+ set_links
12
+ end
13
+
14
+ def set_links
15
+ @links = {}
16
+ object_links = @attributes.delete("links")
17
+ if object_links.kind_of?(Array)
18
+ object_links.each do |link|
19
+ @links[link["rel"]] = Link.new(link)
20
+ end
21
+ end
11
22
  end
12
23
 
13
24
  def inspect
@@ -27,8 +38,8 @@ module Zipmark
27
38
  end
28
39
 
29
40
  def save
30
- if url
31
- response = client.put(url, resource_type => dirty_attributes)
41
+ if links["self"]
42
+ response = client.put(links["self"].href, resource_type => dirty_attributes)
32
43
  else
33
44
  response = client.post("/#{resource_type}s", resource_type => attributes)
34
45
  end
@@ -40,6 +51,7 @@ module Zipmark
40
51
  object = JSON.parse(response.body)
41
52
  if client.successful?(response)
42
53
  @attributes = object[resource_type]
54
+ set_links
43
55
  elsif client.validation_error?(response)
44
56
  @errors = object["errors"]
45
57
  else
@@ -51,11 +63,6 @@ module Zipmark
51
63
  !!(id && errors.empty?)
52
64
  end
53
65
 
54
- def url
55
- link = links.detect {|link| link["rel"] == "self" } if links && !links.empty?
56
- link["href"] if link
57
- end
58
-
59
66
  def updated_at
60
67
  Time.parse(attributes["updated_at"]) if attributes["updated_at"]
61
68
  end
@@ -1,5 +1,14 @@
1
1
  module Zipmark
2
2
  class Error < StandardError
3
- attr_accessor :classification, :messages, :code
3
+ attr_accessor :status
4
+
5
+ def initialize(error)
6
+ self.status = error.delete(:status)
7
+ super(error)
8
+ end
9
+
10
+ def not_found?
11
+ status == 404
12
+ end
4
13
  end
5
14
  end
@@ -37,7 +37,7 @@ module Zipmark
37
37
  end
38
38
 
39
39
  def next_item
40
- item = @items.fetch(@items.index(current_item) + 1) rescue nil
40
+ item = @items.fetch(@items.index(current_item) + 1) rescue nil
41
41
  if item
42
42
  @current_item = item
43
43
  else
@@ -1,4 +1,24 @@
1
1
  module Zipmark
2
2
  class Link
3
+ attr_accessor :name, :title, :href
4
+
5
+ def initialize(options)
6
+ link = Util.stringify_keys(options)
7
+ @rel = link["rel"]
8
+ @title = link["title"]
9
+ @href = link["href"]
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
3
23
  end
4
24
  end
@@ -11,9 +11,13 @@ module Zipmark
11
11
  end
12
12
 
13
13
  def find(id)
14
- json = client.get("/" + rel + "/" + id).body
15
- object = JSON.parse(json)
16
- Zipmark::Entity.new(object[resource_name].merge(:client => client, :resource_type => resource_name))
14
+ response = client.get("/" + rel + "/" + id)
15
+ object = JSON.parse(response.body)
16
+ if client.successful?(response)
17
+ Zipmark::Entity.new(object[resource_name].merge(:client => client, :resource_type => resource_name))
18
+ else
19
+ raise Zipmark::Error.new(!!object ? object.merge(:status => response.status) : response)
20
+ end
17
21
  end
18
22
 
19
23
  def build(options)
@@ -1,3 +1,3 @@
1
1
  module Zipmark
2
- VERSION = '0.0.1.beta.8'
2
+ VERSION = '0.0.1.beta.10'
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.8
4
+ version: 0.0.1.beta.10
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-12-07 00:00:00.000000000 Z
12
+ date: 2013-08-08 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
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: 1.3.1
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 1.8.15
61
+ rubygems_version: 1.8.25
62
62
  signing_key:
63
63
  specification_version: 3
64
64
  summary: Zipmark API Client Library