paid 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/paid.rb +2 -0
- data/lib/paid/api_operations/update.rb +14 -14
- data/lib/paid/paid_object.rb +1 -1
- data/lib/paid/plan.rb +6 -0
- data/lib/paid/subscription.rb +19 -0
- data/lib/paid/util.rb +3 -1
- data/lib/paid/version.rb +1 -1
- data/test/paid/alias_test.rb +10 -17
- data/test/paid/api_resource_test.rb +116 -119
- data/test/paid/customer_test.rb +1 -1
- data/test/paid/plan_test.rb +17 -0
- data/test/paid/properties_test.rb +103 -0
- data/test/paid/subscription_test.rb +31 -0
- data/test/paid/transaction_test.rb +18 -20
- data/test/test_data.rb +45 -4
- metadata +10 -4
- data/test/paid/metadata_test.rb +0 -104
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c131f42824035c881ba3eaf3896d2a8e79aa9a26
|
4
|
+
data.tar.gz: c2b902c2b3d7e0fba75c67b71ec3cff06db9fc98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97115b5ea5004e528b213f9fc9800d5adfebe63d6ff7c0ed95f98f06a04d4acc0523067a285707521a6ce19ef365ec38768aed459cfa6da6e37afe61a72dd339
|
7
|
+
data.tar.gz: b1b15a66a2e5c093635e35d790bc9c801ad03143f595e1d86c512a26f7e88885a6adbeb69731fd1ca5ee5fa630c90f013549ec1d2b3e8398a1cf1f1bed29258c
|
data/Gemfile.lock
CHANGED
data/lib/paid.rb
CHANGED
@@ -4,33 +4,33 @@ module Paid
|
|
4
4
|
def save(opts={})
|
5
5
|
values = serialize_params(self).merge(opts)
|
6
6
|
|
7
|
-
if @values[:
|
8
|
-
values[:
|
7
|
+
if @values[:properties]
|
8
|
+
values[:properties] = serialize_properties
|
9
9
|
end
|
10
10
|
|
11
11
|
if values.length > 0
|
12
12
|
values.delete(:id)
|
13
13
|
|
14
|
-
response, api_key = Paid.request(:
|
14
|
+
response, api_key = Paid.request(:post, api_url, @api_key, values)
|
15
15
|
refresh_from(response, api_key)
|
16
16
|
end
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
if @unsaved_values.include?(:
|
22
|
-
# the
|
23
|
-
# i.e. as object.
|
24
|
-
|
25
|
-
new_keys =
|
20
|
+
def serialize_properties
|
21
|
+
if @unsaved_values.include?(:properties)
|
22
|
+
# the properties object has been reassigned
|
23
|
+
# i.e. as object.properties = {key => val}
|
24
|
+
properties_update = @values[:properties] # new hash
|
25
|
+
new_keys = properties_update.keys.map(&:to_sym)
|
26
26
|
# remove keys at the server, but not known locally
|
27
|
-
keys_to_unset = @
|
28
|
-
keys_to_unset.each {|key|
|
27
|
+
keys_to_unset = @previous_properties.keys - new_keys
|
28
|
+
keys_to_unset.each {|key| properties_update[key] = ''}
|
29
29
|
|
30
|
-
|
30
|
+
properties_update
|
31
31
|
else
|
32
|
-
#
|
33
|
-
serialize_params(@values[:
|
32
|
+
# properties is a PaidObject, and can be serialized normally
|
33
|
+
serialize_params(@values[:properties])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
data/lib/paid/paid_object.rb
CHANGED
@@ -45,7 +45,7 @@ module Paid
|
|
45
45
|
def refresh_from(values, api_key, partial=false)
|
46
46
|
@api_key = api_key
|
47
47
|
|
48
|
-
@
|
48
|
+
@previous_properties = values[:properties]
|
49
49
|
removed = partial ? Set.new : Set.new(@values.keys - values.keys)
|
50
50
|
added = Set.new(values.keys - @values.keys)
|
51
51
|
|
data/lib/paid/plan.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Paid
|
2
|
+
class Subscription < APIResource
|
3
|
+
include Paid::APIOperations::List
|
4
|
+
include Paid::APIOperations::Create
|
5
|
+
|
6
|
+
def cancel(params={}, opts={})
|
7
|
+
api_key, headers = Util.parse_opts(opts)
|
8
|
+
response, api_key = Paid.request(
|
9
|
+
:post, cancel_url, api_key || @api_key, params, headers)
|
10
|
+
refresh_from(response, api_key)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def cancel_url
|
16
|
+
api_url + '/cancel'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/paid/util.rb
CHANGED
data/lib/paid/version.rb
CHANGED
data/test/paid/alias_test.rb
CHANGED
@@ -1,29 +1,22 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
|
3
3
|
module Paid
|
4
|
+
# AliasTest
|
4
5
|
class AliasTest < Test::Unit::TestCase
|
5
|
-
should
|
6
|
+
should 'aliases should not be deletable' do
|
6
7
|
assert_raises NoMethodError do
|
7
|
-
|
8
|
-
|
8
|
+
# Expect twice because Paid::Alias.retrieve returns a customer object
|
9
|
+
@mock.expects(:get).twice.returns(test_response(test_customer))
|
10
|
+
c = Paid::Alias.retrieve('test_alias')
|
9
11
|
c.delete
|
10
12
|
end
|
11
13
|
end
|
12
14
|
|
13
|
-
should
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
}
|
19
|
-
end.once.returns(test_response(test_alias))
|
20
|
-
|
21
|
-
a = Paid::Alias.create({
|
22
|
-
:name => 'test-alias',
|
23
|
-
:customer => 'c_test_customer'
|
24
|
-
})
|
25
|
-
|
26
|
-
assert a.name == 'test-alias'
|
15
|
+
should 'retrieve should retrieve alias' do
|
16
|
+
# Expect twice because Paid::Alias.retrieve returns a customer object
|
17
|
+
@mock.expects(:get).twice.returns(test_response(test_alias))
|
18
|
+
i = Paid::Alias.retrieve('in_test_alias')
|
19
|
+
assert_equal 'al_test_alias', i.id
|
27
20
|
end
|
28
21
|
end
|
29
22
|
end
|
@@ -3,64 +3,62 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
3
3
|
|
4
4
|
module Paid
|
5
5
|
class ApiResourceTest < Test::Unit::TestCase
|
6
|
-
should
|
6
|
+
should 'creating a new APIResource should not fetch over the network' do
|
7
7
|
@mock.expects(:get).never
|
8
|
-
Paid::Customer.new(
|
8
|
+
Paid::Customer.new('someid')
|
9
9
|
end
|
10
10
|
|
11
|
-
should
|
11
|
+
should 'creating a new APIResource from a hash should not fetch over the network' do
|
12
12
|
@mock.expects(:get).never
|
13
|
-
Paid::Customer.construct_from(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
:account_id => 'acct_1234'
|
19
|
-
})
|
13
|
+
Paid::Customer.construct_from(id: 'somecustomer',
|
14
|
+
object: 'customer',
|
15
|
+
email: 'someone@example.com',
|
16
|
+
name: 'Some Business',
|
17
|
+
account_id: 'acct_1234')
|
20
18
|
end
|
21
19
|
|
22
|
-
should
|
20
|
+
should 'setting an attribute should not cause a network request' do
|
23
21
|
@mock.expects(:get).never
|
24
22
|
@mock.expects(:post).never
|
25
|
-
c = Paid::Customer.new(
|
23
|
+
c = Paid::Customer.new('test_customer')
|
26
24
|
c.name = 'Another Name'
|
27
25
|
end
|
28
26
|
|
29
|
-
should
|
27
|
+
should 'accessing id should not issue a fetch' do
|
30
28
|
@mock.expects(:get).never
|
31
|
-
c = Paid::Customer.new(
|
29
|
+
c = Paid::Customer.new('test_customer')
|
32
30
|
c.id
|
33
31
|
end
|
34
32
|
|
35
|
-
should
|
33
|
+
should 'not specifying api credentials should raise an exception' do
|
36
34
|
Paid.api_key = nil
|
37
35
|
assert_raises Paid::AuthenticationError do
|
38
|
-
Paid::Customer.new(
|
36
|
+
Paid::Customer.new('test_customer').refresh
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
42
|
-
should
|
43
|
-
Paid.api_key =
|
40
|
+
should 'specifying api credentials containing whitespace should raise an exception' do
|
41
|
+
Paid.api_key = 'key '
|
44
42
|
assert_raises Paid::AuthenticationError do
|
45
|
-
Paid::Customer.new(
|
43
|
+
Paid::Customer.new('test_customer').refresh
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
49
|
-
should
|
50
|
-
Paid.api_key =
|
47
|
+
should 'specifying invalid api credentials should raise an exception' do
|
48
|
+
Paid.api_key = 'invalid'
|
51
49
|
response = test_response(test_invalid_api_key_error, 401)
|
52
50
|
assert_raises Paid::AuthenticationError do
|
53
51
|
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
|
54
|
-
Paid::Customer.retrieve(
|
52
|
+
Paid::Customer.retrieve('failing_customer')
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
58
|
-
should
|
59
|
-
Paid.api_key =
|
56
|
+
should 'AuthenticationErrors should have an http status, http body, and JSON body' do
|
57
|
+
Paid.api_key = 'invalid'
|
60
58
|
response = test_response(test_invalid_api_key_error, 401)
|
61
59
|
begin
|
62
60
|
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 401))
|
63
|
-
Paid::Customer.retrieve(
|
61
|
+
Paid::Customer.retrieve('failing_customer')
|
64
62
|
rescue Paid::AuthenticationError => e
|
65
63
|
assert_equal(401, e.http_status)
|
66
64
|
assert_equal(true, !!e.http_body)
|
@@ -69,75 +67,75 @@ module Paid
|
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
72
|
-
should
|
73
|
-
paid_account =
|
70
|
+
should 'send paid account as header when set' do
|
71
|
+
paid_account = 'acct_0000'
|
74
72
|
Paid.expects(:execute_request).with do |opts|
|
75
73
|
opts[:headers][:paid_account] == paid_account
|
76
74
|
end.returns(test_response(test_transaction))
|
77
75
|
|
78
|
-
Paid::Transaction.create({:
|
79
|
-
|
76
|
+
Paid::Transaction.create({ amount: 100 },
|
77
|
+
paid_account: paid_account, api_key: 'sk_test_local')
|
80
78
|
end
|
81
79
|
|
82
|
-
should
|
80
|
+
should 'not send paid account as header when not set' do
|
83
81
|
Paid.expects(:execute_request).with do |opts|
|
84
82
|
opts[:headers][:paid_account].nil?
|
85
83
|
end.returns(test_response(test_transaction))
|
86
84
|
|
87
85
|
Paid::Transaction.create(
|
88
86
|
{
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
87
|
+
amount: 200,
|
88
|
+
description: 'This is a description.',
|
89
|
+
customer: 'somecustomer'
|
92
90
|
|
93
91
|
},
|
94
92
|
'sk_test_local'
|
95
93
|
)
|
96
94
|
end
|
97
95
|
|
98
|
-
context
|
99
|
-
context
|
100
|
-
should
|
96
|
+
context 'when specifying per-object credentials' do
|
97
|
+
context 'with no global API key set' do
|
98
|
+
should 'use the per-object credential when creating' do
|
101
99
|
Paid.expects(:execute_request).with do |opts|
|
102
100
|
opts[:headers][:authorization] == 'Bearer sk_test_local'
|
103
101
|
end.returns(test_response(test_transaction))
|
104
102
|
|
105
103
|
Paid::Transaction.create(
|
106
104
|
{
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
105
|
+
amount: 200,
|
106
|
+
description: 'This is a description.',
|
107
|
+
customer: 'somecustomer'
|
110
108
|
},
|
111
109
|
'sk_test_local'
|
112
110
|
)
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
116
|
-
context
|
114
|
+
context 'with a global API key set' do
|
117
115
|
setup do
|
118
|
-
Paid.api_key =
|
116
|
+
Paid.api_key = 'global'
|
119
117
|
end
|
120
118
|
|
121
119
|
teardown do
|
122
120
|
Paid.api_key = nil
|
123
121
|
end
|
124
122
|
|
125
|
-
should
|
123
|
+
should 'use the per-object credential when creating' do
|
126
124
|
Paid.expects(:execute_request).with do |opts|
|
127
125
|
opts[:headers][:authorization] == 'Bearer local'
|
128
126
|
end.returns(test_response(test_transaction))
|
129
127
|
|
130
128
|
Paid::Transaction.create(
|
131
129
|
{
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
130
|
+
amount: 200,
|
131
|
+
description: 'This is a description.',
|
132
|
+
customer: 'somecustomer'
|
135
133
|
},
|
136
134
|
'local'
|
137
135
|
)
|
138
136
|
end
|
139
137
|
|
140
|
-
should
|
138
|
+
should 'use the per-object credential when retrieving and making other calls' do
|
141
139
|
Paid.expects(:execute_request).with do |opts|
|
142
140
|
opts[:url] == "#{Paid.api_base}/v0/transactions/tr_test_transaction" &&
|
143
141
|
opts[:headers][:authorization] == 'Bearer local'
|
@@ -148,154 +146,154 @@ module Paid
|
|
148
146
|
end
|
149
147
|
end
|
150
148
|
|
151
|
-
context
|
152
|
-
should
|
149
|
+
context 'with valid credentials' do
|
150
|
+
should 'send along the idempotency-key header' do
|
153
151
|
Paid.expects(:execute_request).with do |opts|
|
154
152
|
opts[:headers][:idempotency_key] == 'bar'
|
155
153
|
end.returns(test_response(test_transaction))
|
156
154
|
|
157
155
|
Paid::Transaction.create(
|
158
156
|
{
|
159
|
-
:
|
160
|
-
:
|
161
|
-
:
|
162
|
-
},
|
163
|
-
|
164
|
-
|
165
|
-
:api_key => 'local',
|
166
|
-
}
|
157
|
+
amount: 200,
|
158
|
+
description: 'This is a description.',
|
159
|
+
customer: 'somecustomer'
|
160
|
+
},
|
161
|
+
idempotency_key: 'bar',
|
162
|
+
api_key: 'local'
|
167
163
|
)
|
168
164
|
end
|
169
165
|
|
170
|
-
should
|
166
|
+
should 'urlencode values in GET params' do
|
171
167
|
response = test_response(test_transaction_array)
|
172
168
|
@mock.expects(:get).with("#{Paid.api_base}/v0/transactions?customer=test%20customer", nil, nil).returns(response)
|
173
|
-
transactions = Paid::Transaction.all(:
|
174
|
-
assert transactions.
|
169
|
+
transactions = Paid::Transaction.all(customer: 'test customer').data
|
170
|
+
assert transactions.is_a? Array
|
175
171
|
end
|
176
172
|
|
177
|
-
should
|
173
|
+
should 'a 400 should give an InvalidRequestError with http status, body, and JSON body' do
|
178
174
|
response = test_response(test_missing_id_error, 400)
|
179
175
|
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
180
176
|
begin
|
181
|
-
Paid::Customer.retrieve(
|
177
|
+
Paid::Customer.retrieve('foo')
|
182
178
|
rescue Paid::InvalidRequestError => e
|
183
179
|
assert_equal(400, e.http_status)
|
184
180
|
assert_equal(true, !!e.http_body)
|
185
|
-
assert_equal(true, e.json_body.
|
181
|
+
assert_equal(true, e.json_body.is_a?(Hash))
|
186
182
|
end
|
187
183
|
end
|
188
184
|
|
189
|
-
should
|
185
|
+
should 'a 401 should give an AuthenticationError with http status, body, and JSON body' do
|
190
186
|
response = test_response(test_missing_id_error, 401)
|
191
187
|
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
192
188
|
begin
|
193
|
-
Paid::Customer.retrieve(
|
189
|
+
Paid::Customer.retrieve('foo')
|
194
190
|
rescue Paid::AuthenticationError => e
|
195
191
|
assert_equal(401, e.http_status)
|
196
192
|
assert_equal(true, !!e.http_body)
|
197
|
-
assert_equal(true, e.json_body.
|
193
|
+
assert_equal(true, e.json_body.is_a?(Hash))
|
198
194
|
end
|
199
195
|
end
|
200
196
|
|
201
|
-
should
|
197
|
+
should 'a 404 should give an InvalidRequestError with http status, body, and JSON body' do
|
202
198
|
response = test_response(test_missing_id_error, 404)
|
203
199
|
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
204
200
|
begin
|
205
|
-
Paid::Customer.retrieve(
|
201
|
+
Paid::Customer.retrieve('foo')
|
206
202
|
rescue Paid::InvalidRequestError => e
|
207
203
|
assert_equal(404, e.http_status)
|
208
204
|
assert_equal(true, !!e.http_body)
|
209
|
-
assert_equal(true, e.json_body.
|
205
|
+
assert_equal(true, e.json_body.is_a?(Hash))
|
210
206
|
end
|
211
207
|
end
|
212
208
|
|
213
|
-
should
|
214
|
-
@mock.expects(:get).with do |url,
|
209
|
+
should 'setting a nil value for a param should exclude that param from the request' do
|
210
|
+
@mock.expects(:get).with do |url, _api_key, _params|
|
215
211
|
uri = URI(url)
|
216
212
|
query = CGI.parse(uri.query)
|
217
213
|
(url =~ %r{^#{Paid.api_base}/v0/transactions?} &&
|
218
|
-
query.keys.sort ==
|
219
|
-
end.returns(test_response(
|
220
|
-
Paid::Transaction.all(:
|
214
|
+
query.keys.sort == %w(offset sad))
|
215
|
+
end.returns(test_response(count: 1, data: [test_transaction]))
|
216
|
+
Paid::Transaction.all(count: nil, offset: 5, sad: false)
|
221
217
|
|
222
218
|
@mock.expects(:post).with do |url, api_key, params|
|
223
219
|
url == "#{Paid.api_base}/v0/transactions" &&
|
224
220
|
api_key.nil? &&
|
225
221
|
CGI.parse(params) == { 'amount' => ['100'] }
|
226
|
-
end.returns(test_response(
|
227
|
-
Paid::Transaction.create(:
|
222
|
+
end.returns(test_response(count: 1, data: [test_transaction]))
|
223
|
+
Paid::Transaction.create(amount: 100)
|
228
224
|
end
|
229
225
|
|
230
|
-
should
|
226
|
+
should 'requesting with a unicode ID should result in a request' do
|
231
227
|
response = test_response(test_missing_id_error, 404)
|
232
228
|
@mock.expects(:get).once.with("#{Paid.api_base}/v0/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404))
|
233
|
-
c = Paid::Customer.new(
|
229
|
+
c = Paid::Customer.new('☃')
|
234
230
|
assert_raises(Paid::InvalidRequestError) { c.refresh }
|
235
231
|
end
|
236
232
|
|
237
|
-
should
|
233
|
+
should 'requesting with no ID should result in an InvalidRequestError with no request' do
|
238
234
|
c = Paid::Customer.new
|
239
235
|
assert_raises(Paid::InvalidRequestError) { c.refresh }
|
240
236
|
end
|
241
237
|
|
242
|
-
should
|
243
|
-
params = { :
|
238
|
+
should 'making a GET request with parameters should have a query string and no body' do
|
239
|
+
params = { limit: 1 }
|
244
240
|
@mock.expects(:get).once.with("#{Paid.api_base}/v0/transactions?limit=1", nil, nil).returns(test_response([test_transaction]))
|
245
241
|
Paid::Transaction.all(params)
|
246
242
|
end
|
247
243
|
|
248
|
-
should
|
249
|
-
params = { :
|
250
|
-
@mock.expects(:post).once.with do |
|
251
|
-
get.nil? && CGI.parse(post) == {'amount' => ['100'], 'alias' => ['test_alias']}
|
244
|
+
should 'making a POST request with parameters should have a body and no query string' do
|
245
|
+
params = { amount: 100, alias: 'test_alias' }
|
246
|
+
@mock.expects(:post).once.with do |_url, get, post|
|
247
|
+
get.nil? && CGI.parse(post) == { 'amount' => ['100'], 'alias' => ['test_alias'] }
|
252
248
|
end.returns(test_response(test_transaction))
|
253
249
|
Paid::Transaction.create(params)
|
254
250
|
end
|
255
251
|
|
256
|
-
should
|
252
|
+
should 'loading an object should issue a GET request' do
|
257
253
|
@mock.expects(:get).once.returns(test_response(test_customer))
|
258
|
-
c = Paid::Customer.new(
|
254
|
+
c = Paid::Customer.new('test_customer')
|
259
255
|
c.refresh
|
260
256
|
end
|
261
257
|
|
262
|
-
should
|
258
|
+
should 'using array accessors should be the same as the method interface' do
|
263
259
|
@mock.expects(:get).once.returns(test_response(test_customer))
|
264
|
-
c = Paid::Customer.new(
|
260
|
+
c = Paid::Customer.new('test_customer')
|
265
261
|
c.refresh
|
266
262
|
assert_equal c.created, c[:created]
|
267
263
|
assert_equal c.created, c['created']
|
268
|
-
c['created'] =
|
269
|
-
assert_equal c.created,
|
264
|
+
c['created'] = 12_345
|
265
|
+
assert_equal c.created, 12_345
|
270
266
|
end
|
271
267
|
|
272
|
-
should
|
268
|
+
should 'accessing a property other than id or parent on an unfetched object should fetch it' do
|
273
269
|
@mock.expects(:get).once.returns(test_response(test_customer))
|
274
|
-
c = Paid::Customer.new(
|
270
|
+
c = Paid::Customer.new('test_customer')
|
275
271
|
c.transactions
|
276
272
|
end
|
277
273
|
|
278
|
-
should
|
274
|
+
should 'updating an object should issue a POST request with only the changed properties' do
|
279
275
|
@mock.expects(:post).with do |url, api_key, params|
|
280
|
-
url == "#{Paid.api_base}/v0/customers/
|
276
|
+
url == "#{Paid.api_base}/v0/customers/cus_test_customer" &&
|
277
|
+
api_key.nil? &&
|
278
|
+
CGI.parse(params) == { 'description' => ['another_mn'] }
|
281
279
|
end.once.returns(test_response(test_customer))
|
282
280
|
c = Paid::Customer.construct_from(test_customer)
|
283
|
-
c.description =
|
281
|
+
c.description = 'another_mn'
|
284
282
|
c.save
|
285
283
|
end
|
286
284
|
|
287
|
-
should
|
285
|
+
should 'updating should merge in returned properties' do
|
288
286
|
@mock.expects(:post).once.returns(test_response(test_customer))
|
289
|
-
c = Paid::Customer.new(
|
290
|
-
c.description =
|
287
|
+
c = Paid::Customer.new('cus_test_customer')
|
288
|
+
c.description = 'another_mn'
|
291
289
|
c.save
|
292
290
|
# assert_equal false, c.livemode
|
293
291
|
end
|
294
292
|
|
295
|
-
should
|
293
|
+
should 'deleting should send no props and result in an object that has no props other deleted' do
|
296
294
|
@mock.expects(:get).never
|
297
295
|
@mock.expects(:post).never
|
298
|
-
@mock.expects(:delete).with("#{Paid.api_base}/v0/customers/
|
296
|
+
@mock.expects(:delete).with("#{Paid.api_base}/v0/customers/cus_test_customer", nil, nil).once.returns(test_response('id' => 'test_customer', 'deleted' => true))
|
299
297
|
|
300
298
|
c = Paid::Customer.construct_from(test_customer)
|
301
299
|
c.delete
|
@@ -306,51 +304,50 @@ module Paid
|
|
306
304
|
end
|
307
305
|
end
|
308
306
|
|
309
|
-
should
|
307
|
+
should 'loading an object with properties that have specific types should instantiate those classes' do
|
310
308
|
@mock.expects(:get).once.returns(test_response(test_transaction))
|
311
|
-
t = Paid::Transaction.retrieve(
|
312
|
-
assert t.
|
309
|
+
t = Paid::Transaction.retrieve('test_transaction')
|
310
|
+
assert t.is_a?(Paid::PaidObject) && t.object == 'transaction'
|
313
311
|
end
|
314
312
|
|
315
|
-
should
|
313
|
+
should 'loading all of an APIResource should return an array of recursively instantiated objects' do
|
316
314
|
@mock.expects(:get).once.returns(test_response(test_transaction_array))
|
317
315
|
t = Paid::Transaction.all.data
|
318
|
-
assert t.
|
319
|
-
assert t[0].
|
320
|
-
assert t[0].
|
316
|
+
assert t.is_a? Array
|
317
|
+
assert t[0].is_a? Paid::Transaction
|
318
|
+
assert t[0].is_a?(Paid::PaidObject) && t[0].object == 'transaction'
|
321
319
|
end
|
322
320
|
|
323
|
-
context
|
324
|
-
|
325
|
-
should "404s should raise an InvalidRequestError" do
|
321
|
+
context 'error checking' do
|
322
|
+
should '404s should raise an InvalidRequestError' do
|
326
323
|
response = test_response(test_missing_id_error, 404)
|
327
324
|
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
|
328
325
|
|
329
326
|
rescued = false
|
330
327
|
begin
|
331
|
-
Paid::Customer.new(
|
332
|
-
assert false #shouldn't get here either
|
328
|
+
Paid::Customer.new('test_customer').refresh
|
329
|
+
assert false # shouldn't get here either
|
333
330
|
rescue Paid::InvalidRequestError => e # we don't use assert_raises because we want to examine e
|
334
331
|
rescued = true
|
335
|
-
assert e.
|
336
|
-
assert_equal
|
337
|
-
assert_equal
|
332
|
+
assert e.is_a? Paid::InvalidRequestError
|
333
|
+
assert_equal 'id', e.param
|
334
|
+
assert_equal 'Missing id', e.message
|
338
335
|
end
|
339
336
|
|
340
337
|
assert_equal true, rescued
|
341
338
|
end
|
342
339
|
|
343
|
-
should
|
340
|
+
should '5XXs should raise an APIError' do
|
344
341
|
response = test_response(test_api_error, 500)
|
345
342
|
@mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 500))
|
346
343
|
|
347
344
|
rescued = false
|
348
345
|
begin
|
349
|
-
Paid::Customer.new(
|
350
|
-
assert false #shouldn't get here either
|
346
|
+
Paid::Customer.new('test_customer').refresh
|
347
|
+
assert false # shouldn't get here either
|
351
348
|
rescue Paid::APIError => e # we don't use assert_raises because we want to examine e
|
352
349
|
rescued = true
|
353
|
-
assert e.
|
350
|
+
assert e.is_a? Paid::APIError
|
354
351
|
end
|
355
352
|
|
356
353
|
assert_equal true, rescued
|
data/test/paid/customer_test.rb
CHANGED
@@ -29,7 +29,7 @@ module Paid
|
|
29
29
|
should "create should return a new customer" do
|
30
30
|
@mock.expects(:post).once.returns(test_response(test_customer))
|
31
31
|
c = Paid::Customer.create
|
32
|
-
assert_equal "
|
32
|
+
assert_equal "cus_test_customer", c.id
|
33
33
|
end
|
34
34
|
|
35
35
|
should "be able to generate invoice" do
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Paid
|
4
|
+
class PlanTest < Test::Unit::TestCase
|
5
|
+
should "retrieve should retrieve plans" do
|
6
|
+
@mock.expects(:get).once.returns(test_response(test_plan))
|
7
|
+
i = Paid::Plan.retrieve('in_test_plan')
|
8
|
+
assert_equal 'pl_test_plan', i.id
|
9
|
+
end
|
10
|
+
|
11
|
+
should "create should create a new plan" do
|
12
|
+
@mock.expects(:post).once.returns(test_response(test_plan))
|
13
|
+
i = Paid::Plan.create
|
14
|
+
assert_equal "pl_test_plan", i.id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Paid
|
4
|
+
class PropertiesTest < Test::Unit::TestCase
|
5
|
+
setup do
|
6
|
+
@properties_supported = {
|
7
|
+
transaction: {
|
8
|
+
new: Paid::Transaction.method(:new),
|
9
|
+
test: method(:test_transaction),
|
10
|
+
url: "/v0/transactions/#{test_transaction[:id]}"
|
11
|
+
},
|
12
|
+
customer: {
|
13
|
+
new: Paid::Customer.method(:new),
|
14
|
+
test: method(:test_customer),
|
15
|
+
url: "/v0/customers/#{test_customer[:id]}"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
@base_url = 'https://api.paidapi.com'
|
20
|
+
end
|
21
|
+
|
22
|
+
should 'not touch properties' do
|
23
|
+
update_actions = ->(obj) { obj.description = 'test' }
|
24
|
+
check_properties({ properties: { 'initial' => 'true' } },
|
25
|
+
'description=test',
|
26
|
+
update_actions)
|
27
|
+
end
|
28
|
+
|
29
|
+
should 'update properties as a whole' do
|
30
|
+
update_actions = ->(obj) { obj.properties = { 'uuid' => '6735' } }
|
31
|
+
check_properties({ properties: {} },
|
32
|
+
'properties[uuid]=6735',
|
33
|
+
update_actions)
|
34
|
+
|
35
|
+
if is_greater_than_ruby_1_9?
|
36
|
+
check_properties({ properties: { initial: 'true' } },
|
37
|
+
'properties[uuid]=6735&properties[initial]=',
|
38
|
+
update_actions)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'update properties keys individually' do
|
43
|
+
update_actions = ->(obj) { obj.properties['txn_id'] = '134a13' }
|
44
|
+
check_properties({ properties: { 'initial' => 'true' } },
|
45
|
+
'properties[txn_id]=134a13',
|
46
|
+
update_actions)
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'clear properties as a whole' do
|
50
|
+
update_actions = ->(obj) { obj.properties = nil }
|
51
|
+
check_properties({ properties: { 'initial' => 'true' } },
|
52
|
+
'properties=',
|
53
|
+
update_actions)
|
54
|
+
end
|
55
|
+
|
56
|
+
should 'clear properties keys individually' do
|
57
|
+
update_actions = ->(obj) { obj.properties['initial'] = nil }
|
58
|
+
check_properties({ properties: { 'initial' => 'true' } },
|
59
|
+
'properties[initial]=',
|
60
|
+
update_actions)
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'handle combinations of whole and partial properties updates' do
|
64
|
+
if is_greater_than_ruby_1_9?
|
65
|
+
update_actions = lambda do |obj|
|
66
|
+
obj.properties = { 'type' => 'summer' }
|
67
|
+
obj.properties['uuid'] = '6735'
|
68
|
+
end
|
69
|
+
params = { properties: { 'type' => 'summer', 'uuid' => '6735' } }
|
70
|
+
curl_args = Paid.uri_encode(params)
|
71
|
+
check_properties({ properties: { 'type' => 'christmas' } },
|
72
|
+
curl_args,
|
73
|
+
update_actions)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def check_properties(initial_params, curl_args, properties_update)
|
78
|
+
@properties_supported.each do |_name, methods|
|
79
|
+
neu = methods[:new]
|
80
|
+
test = methods[:test]
|
81
|
+
url = @base_url + methods[:url]
|
82
|
+
|
83
|
+
initial_test_obj = test.call(initial_params)
|
84
|
+
@mock.expects(:get).once.returns(test_response(initial_test_obj))
|
85
|
+
|
86
|
+
final_test_obj = test.call
|
87
|
+
@mock.expects(:post).once
|
88
|
+
.returns(test_response(final_test_obj))
|
89
|
+
.with(url, nil, curl_args)
|
90
|
+
|
91
|
+
obj = neu.call('test')
|
92
|
+
obj.refresh
|
93
|
+
properties_update.call(obj)
|
94
|
+
obj.save
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def is_greater_than_ruby_1_9?
|
99
|
+
version = RUBY_VERSION.dup # clone preserves frozen state
|
100
|
+
Gem::Version.new(version) >= Gem::Version.new('1.9')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
module Paid
|
4
|
+
# SubscriptionTest
|
5
|
+
class SubscriptionTest < Test::Unit::TestCase
|
6
|
+
should 'retrieve should retrieve subscriptions' do
|
7
|
+
@mock.expects(:get).once.returns(test_response(test_subscription))
|
8
|
+
i = Paid::Subscription.retrieve('in_test_subscription')
|
9
|
+
assert_equal 'sub_test_subscription', i.id
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'create should create a new subscription' do
|
13
|
+
@mock.expects(:post).once.returns(test_response(test_subscription))
|
14
|
+
i = Paid::Subscription.create
|
15
|
+
assert_equal 'sub_test_subscription', i.id
|
16
|
+
end
|
17
|
+
|
18
|
+
should 'subscriptions should be cancellable' do
|
19
|
+
@mock.expects(:get).never
|
20
|
+
@mock.expects(:post).once.returns(
|
21
|
+
test_response(
|
22
|
+
id: 'sub_test_subscription',
|
23
|
+
cancelled_at: 123_456_789
|
24
|
+
)
|
25
|
+
)
|
26
|
+
s = Paid::Subscription.new('test_subscription')
|
27
|
+
s.cancel
|
28
|
+
assert !s.cancelled_at.nil?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -2,54 +2,52 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Paid
|
4
4
|
class TransactionTest < Test::Unit::TestCase
|
5
|
-
should
|
5
|
+
should 'transactions should be listable' do
|
6
6
|
@mock.expects(:get).once.returns(test_response(test_transaction_array))
|
7
7
|
c = Paid::Transaction.all
|
8
|
-
assert c.data.
|
8
|
+
assert c.data.is_a? Array
|
9
9
|
c.each do |transaction|
|
10
|
-
assert transaction.
|
10
|
+
assert transaction.is_a?(Paid::Transaction)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
should
|
14
|
+
should 'transactions should not be deletable' do
|
15
15
|
assert_raises NoMethodError do
|
16
16
|
@mock.expects(:get).once.returns(test_response(test_transaction))
|
17
|
-
c = Paid::Transaction.retrieve(
|
17
|
+
c = Paid::Transaction.retrieve('test_transaction')
|
18
18
|
c.delete
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
should
|
22
|
+
should 'transactions should be updateable' do
|
23
23
|
@mock.expects(:get).once.returns(test_response(test_transaction))
|
24
24
|
@mock.expects(:post).once.returns(test_response(test_transaction))
|
25
|
-
c = Paid::Transaction.new(
|
25
|
+
c = Paid::Transaction.new('test_transaction')
|
26
26
|
c.refresh
|
27
|
-
c.mnemonic =
|
27
|
+
c.mnemonic = 'New transaction description'
|
28
28
|
c.save
|
29
29
|
end
|
30
30
|
|
31
|
-
should
|
31
|
+
should 'execute should return a new, fully executed transaction when passed correct parameters' do
|
32
32
|
@mock.expects(:post).with do |url, api_key, params|
|
33
33
|
url == "#{Paid.api_base}/v0/transactions" && api_key.nil? && CGI.parse(params) == {
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
'amount' => ['100'],
|
35
|
+
'description' => ['a description'],
|
36
|
+
'customer' => ['cus_test_customer']
|
37
37
|
}
|
38
38
|
end.once.returns(test_response(test_transaction))
|
39
39
|
|
40
|
-
c = Paid::Transaction.create(
|
41
|
-
|
42
|
-
|
43
|
-
:customer => 'c_test_customer'
|
44
|
-
})
|
40
|
+
c = Paid::Transaction.create(amount: 100,
|
41
|
+
description: 'a description',
|
42
|
+
customer: 'cus_test_customer')
|
45
43
|
|
46
44
|
assert !c.paid
|
47
45
|
end
|
48
46
|
|
49
|
-
should
|
47
|
+
should 'transactions should be able to be marked as paid' do
|
50
48
|
@mock.expects(:get).never
|
51
|
-
@mock.expects(:post).once.returns(test_response(
|
52
|
-
t = Paid::Invoice.new(
|
49
|
+
@mock.expects(:post).once.returns(test_response(id: 'tr_test_transaction', paid: true))
|
50
|
+
t = Paid::Invoice.new('test_transaction')
|
53
51
|
t.mark_as_paid
|
54
52
|
assert t.paid
|
55
53
|
end
|
data/test/test_data.rb
CHANGED
@@ -17,7 +17,7 @@ module Paid
|
|
17
17
|
:object => "alias",
|
18
18
|
:id => id,
|
19
19
|
:name => 'test-alias',
|
20
|
-
:customer => '
|
20
|
+
:customer => 'cus_test_customer'
|
21
21
|
}.merge(params)
|
22
22
|
end
|
23
23
|
|
@@ -30,7 +30,7 @@ module Paid
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_customer(params={})
|
33
|
-
id = params[:id] || '
|
33
|
+
id = params[:id] || 'cus_test_customer'
|
34
34
|
{
|
35
35
|
:transactions => [],
|
36
36
|
:object => "customer",
|
@@ -56,7 +56,7 @@ module Paid
|
|
56
56
|
:object => "transaction",
|
57
57
|
:description => 'a description',
|
58
58
|
:created => 1304114826,
|
59
|
-
:customer => '
|
59
|
+
:customer => 'cus_test_customer'
|
60
60
|
}.merge(params)
|
61
61
|
end
|
62
62
|
|
@@ -89,7 +89,7 @@ module Paid
|
|
89
89
|
next_chase_on: nil,
|
90
90
|
terms: 30,
|
91
91
|
due_date: nil,
|
92
|
-
customer: "
|
92
|
+
customer: "cus_test_customer",
|
93
93
|
issued_at: nil
|
94
94
|
}
|
95
95
|
end
|
@@ -120,5 +120,46 @@ module Paid
|
|
120
120
|
}
|
121
121
|
}
|
122
122
|
end
|
123
|
+
|
124
|
+
def test_plan(params={})
|
125
|
+
{
|
126
|
+
:amount => 100,
|
127
|
+
:id => 'pl_test_plan',
|
128
|
+
:object => 'plan',
|
129
|
+
:name => 'test-name',
|
130
|
+
:description => 'a description',
|
131
|
+
:interval => 'month',
|
132
|
+
:interval_count => 3
|
133
|
+
}.merge(params)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_plans_array(params={})
|
137
|
+
{
|
138
|
+
:data => [test_plan, test_plan, test_plan],
|
139
|
+
:object => 'list',
|
140
|
+
:url => '/v0/plans'
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_subscription(params={})
|
145
|
+
{
|
146
|
+
:amount => 100,
|
147
|
+
:id => 'sub_test_subscription',
|
148
|
+
:customer => 'cus_test_customer',
|
149
|
+
:cancelled_at => nil,
|
150
|
+
:ended_at => nil,
|
151
|
+
:started_at => 123_456_789,
|
152
|
+
:start_on => nil,
|
153
|
+
:plan => 'pl_test_plan'
|
154
|
+
}.merge(params)
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_subscriptions_array(params={})
|
158
|
+
{
|
159
|
+
:data => [test_subscription, test_subscription, test_subscription],
|
160
|
+
:object => 'list',
|
161
|
+
:url => '/v0/subscriptions'
|
162
|
+
}
|
163
|
+
end
|
123
164
|
end
|
124
165
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Jackson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -148,7 +148,9 @@ files:
|
|
148
148
|
- lib/paid/invoice.rb
|
149
149
|
- lib/paid/list_object.rb
|
150
150
|
- lib/paid/paid_object.rb
|
151
|
+
- lib/paid/plan.rb
|
151
152
|
- lib/paid/singleton_api_resource.rb
|
153
|
+
- lib/paid/subscription.rb
|
152
154
|
- lib/paid/transaction.rb
|
153
155
|
- lib/paid/util.rb
|
154
156
|
- lib/paid/version.rb
|
@@ -161,8 +163,10 @@ files:
|
|
161
163
|
- test/paid/customer_test.rb
|
162
164
|
- test/paid/invoice_test.rb
|
163
165
|
- test/paid/list_object_test.rb
|
164
|
-
- test/paid/metadata_test.rb
|
165
166
|
- test/paid/paid_object_test.rb
|
167
|
+
- test/paid/plan_test.rb
|
168
|
+
- test/paid/properties_test.rb
|
169
|
+
- test/paid/subscription_test.rb
|
166
170
|
- test/paid/transaction_test.rb
|
167
171
|
- test/paid/util_test.rb
|
168
172
|
- test/test_data.rb
|
@@ -199,8 +203,10 @@ test_files:
|
|
199
203
|
- test/paid/customer_test.rb
|
200
204
|
- test/paid/invoice_test.rb
|
201
205
|
- test/paid/list_object_test.rb
|
202
|
-
- test/paid/metadata_test.rb
|
203
206
|
- test/paid/paid_object_test.rb
|
207
|
+
- test/paid/plan_test.rb
|
208
|
+
- test/paid/properties_test.rb
|
209
|
+
- test/paid/subscription_test.rb
|
204
210
|
- test/paid/transaction_test.rb
|
205
211
|
- test/paid/util_test.rb
|
206
212
|
- test/test_data.rb
|
data/test/paid/metadata_test.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
|
3
|
-
module Paid
|
4
|
-
class MetadataTest < Test::Unit::TestCase
|
5
|
-
setup do
|
6
|
-
@metadata_supported = {
|
7
|
-
:transaction => {
|
8
|
-
:new => Paid::Transaction.method(:new),
|
9
|
-
:test => method(:test_transaction),
|
10
|
-
:url => "/v0/transactions/#{test_transaction()[:id]}"
|
11
|
-
},
|
12
|
-
:customer => {
|
13
|
-
:new => Paid::Customer.method(:new),
|
14
|
-
:test => method(:test_customer),
|
15
|
-
:url => "/v0/customers/#{test_customer()[:id]}"
|
16
|
-
}
|
17
|
-
}
|
18
|
-
|
19
|
-
@base_url = 'https://api.paidapi.com'
|
20
|
-
end
|
21
|
-
|
22
|
-
should "not touch metadata" do
|
23
|
-
update_actions = lambda {|obj| obj.description = 'test'}
|
24
|
-
check_metadata({:metadata => {'initial' => 'true'}},
|
25
|
-
'description=test',
|
26
|
-
update_actions)
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
should "update metadata as a whole" do
|
31
|
-
update_actions = lambda {|obj| obj.metadata = {'uuid' => '6735'}}
|
32
|
-
check_metadata({:metadata => {}},
|
33
|
-
'metadata[uuid]=6735',
|
34
|
-
update_actions)
|
35
|
-
|
36
|
-
if is_greater_than_ruby_1_9?
|
37
|
-
check_metadata({:metadata => {:initial => 'true'}},
|
38
|
-
'metadata[uuid]=6735&metadata[initial]=',
|
39
|
-
update_actions)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
should "update metadata keys individually" do
|
44
|
-
update_actions = lambda {|obj| obj.metadata['txn_id'] = '134a13'}
|
45
|
-
check_metadata({:metadata => {'initial' => 'true'}},
|
46
|
-
'metadata[txn_id]=134a13',
|
47
|
-
update_actions)
|
48
|
-
end
|
49
|
-
|
50
|
-
should "clear metadata as a whole" do
|
51
|
-
update_actions = lambda {|obj| obj.metadata = nil}
|
52
|
-
check_metadata({:metadata => {'initial' => 'true'}},
|
53
|
-
'metadata=',
|
54
|
-
update_actions)
|
55
|
-
end
|
56
|
-
|
57
|
-
should "clear metadata keys individually" do
|
58
|
-
update_actions = lambda {|obj| obj.metadata['initial'] = nil}
|
59
|
-
check_metadata({:metadata => {'initial' => 'true'}},
|
60
|
-
'metadata[initial]=',
|
61
|
-
update_actions)
|
62
|
-
end
|
63
|
-
|
64
|
-
should "handle combinations of whole and partial metadata updates" do
|
65
|
-
if is_greater_than_ruby_1_9?
|
66
|
-
update_actions = lambda do |obj|
|
67
|
-
obj.metadata = {'type' => 'summer'}
|
68
|
-
obj.metadata['uuid'] = '6735'
|
69
|
-
end
|
70
|
-
params = {:metadata => {'type' => 'summer', 'uuid' => '6735'}}
|
71
|
-
curl_args = Paid.uri_encode(params)
|
72
|
-
check_metadata({:metadata => {'type' => 'christmas'}},
|
73
|
-
curl_args,
|
74
|
-
update_actions)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def check_metadata (initial_params, curl_args, metadata_update)
|
79
|
-
@metadata_supported.each do |name, methods|
|
80
|
-
neu = methods[:new]
|
81
|
-
test = methods[:test]
|
82
|
-
url = @base_url + methods[:url]
|
83
|
-
|
84
|
-
initial_test_obj = test.call(initial_params)
|
85
|
-
@mock.expects(:get).once.returns(test_response(initial_test_obj))
|
86
|
-
|
87
|
-
final_test_obj = test.call()
|
88
|
-
@mock.expects(:post).once.
|
89
|
-
returns(test_response(final_test_obj)).
|
90
|
-
with(url, nil, curl_args)
|
91
|
-
|
92
|
-
obj = neu.call("test")
|
93
|
-
obj.refresh()
|
94
|
-
metadata_update.call(obj)
|
95
|
-
obj.save
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def is_greater_than_ruby_1_9?
|
100
|
-
version = RUBY_VERSION.dup # clone preserves frozen state
|
101
|
-
Gem::Version.new(version) >= Gem::Version.new('1.9')
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|