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 +42 -1
- data/lib/zipmark.rb +4 -0
- data/lib/zipmark/client.rb +4 -0
- data/lib/zipmark/collection.rb +1 -1
- data/lib/zipmark/entity.rb +15 -8
- data/lib/zipmark/error.rb +10 -1
- data/lib/zipmark/iterator.rb +1 -1
- data/lib/zipmark/link.rb +20 -0
- data/lib/zipmark/resource.rb +7 -3
- data/lib/zipmark/version.rb +1 -1
- metadata +3 -3
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
|
+
```
|
data/lib/zipmark.rb
CHANGED
@@ -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
|
data/lib/zipmark/client.rb
CHANGED
data/lib/zipmark/collection.rb
CHANGED
data/lib/zipmark/entity.rb
CHANGED
@@ -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
|
31
|
-
response = client.put(
|
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
|
data/lib/zipmark/error.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
module Zipmark
|
2
2
|
class Error < StandardError
|
3
|
-
attr_accessor :
|
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
|
data/lib/zipmark/iterator.rb
CHANGED
data/lib/zipmark/link.rb
CHANGED
@@ -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
|
data/lib/zipmark/resource.rb
CHANGED
@@ -11,9 +11,13 @@ module Zipmark
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def find(id)
|
14
|
-
|
15
|
-
object = JSON.parse(
|
16
|
-
|
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)
|
data/lib/zipmark/version.rb
CHANGED
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.
|
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:
|
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.
|
61
|
+
rubygems_version: 1.8.25
|
62
62
|
signing_key:
|
63
63
|
specification_version: 3
|
64
64
|
summary: Zipmark API Client Library
|