omise 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6b2f56981a89d8705862e3a3649803458ed8ba8
4
- data.tar.gz: eeecbe3fced3152b59b4fc7956c89ea0800021df
3
+ metadata.gz: 8f67db51e46de8d75813070941bfce1ab7585841
4
+ data.tar.gz: 8529481a2cdc0b51f4e8d597a02a995e1e699d83
5
5
  SHA512:
6
- metadata.gz: 1a9b3226f8a0db71ef9f6b47569aee173d6e0aecb437d142552cee6a16af9348e5b4664ccf26901e0a080f1d63c2900cbfe003c723e9e02262c7b08a22ec12e9
7
- data.tar.gz: b4e0cffe3356323389e2421df5a97a38ab60542b25e75f31d47b11094ae137359c96b372e433d0cd8c89dcf70384a970f8a49aaf997c2dc1760514e015a9d19d
6
+ metadata.gz: 75f2c4e8aa0cef550ded71431dd5544f883e44d64de21f4c4689121f2b8c2bcb7a626a972d7075895dc0aa274343ffbaf5d1fd73c09813ccec143fc0bc109150
7
+ data.tar.gz: ed74619566dc4e0d3dc08e7db4371ed640212574aee48212c93f3dc87ec1fd5d8d2cc056a83c8e322d14c6feaa42d1aa76f53d7d6776e6bc331250839a5d7506
@@ -2,7 +2,15 @@
2
2
 
3
3
  An [unreleased] version is not available on rubygems and is subject to changes and must not be considered final. Elements of unreleased list may be edited or removed at any time.
4
4
 
5
- ## [unreleased]
5
+ ## [0.7.0] 2017-06-04
6
+
7
+ - [Added] Support for start_date in Scheduler
8
+ - [Added] Method to fetch schedules for a customer
9
+ - [Added] Method to fetch all refunds
10
+ - [Added] Support for predicate methods
11
+ - [Added] Support for retrieving exchange rates
12
+
13
+ ## [0.6.0] 2017-05-31
6
14
 
7
15
  - [Added] Schedule and Occurence
8
16
 
@@ -2,11 +2,13 @@ require "omise/account"
2
2
  require "omise/balance"
3
3
  require "omise/bank_account"
4
4
  require "omise/card"
5
+ require "omise/chain"
5
6
  require "omise/charge"
6
7
  require "omise/customer"
7
8
  require "omise/dispute"
8
9
  require "omise/document"
9
10
  require "omise/event"
11
+ require "omise/forex"
10
12
  require "omise/link"
11
13
  require "omise/occurrence"
12
14
  require "omise/recipient"
@@ -44,12 +44,32 @@ module Omise
44
44
  @attributes.key?(key.to_s)
45
45
  end
46
46
 
47
- def respond_to?(method_name)
48
- key?(method_name) || super
47
+ def predicate?(method_name)
48
+ method_name = method_name.to_s
49
+ question_mark = method_name.chars.last == "?"
50
+ key = method_name.chomp("?")
51
+
52
+ if question_mark && key?(key)
53
+ true
54
+ else
55
+ false
56
+ end
57
+ end
58
+
59
+ def respond_to_missing?(method_name, *args, &block)
60
+ if predicate?(method_name)
61
+ true
62
+ elsif key?(method_name)
63
+ true
64
+ else
65
+ super
66
+ end
49
67
  end
50
68
 
51
69
  def method_missing(method_name, *args, &block)
52
- if key?(method_name)
70
+ if predicate?(method_name)
71
+ !!self[method_name.to_s.chomp("?")]
72
+ elsif key?(method_name)
53
73
  self[method_name]
54
74
  else
55
75
  super
@@ -0,0 +1,24 @@
1
+ require "omise/object"
2
+ require "omise/list"
3
+
4
+ module Omise
5
+ class Chain < OmiseObject
6
+ self.endpoint = "/chains"
7
+
8
+ def self.retrieve(id, attributes = {})
9
+ new resource(location(id), attributes).get(attributes)
10
+ end
11
+
12
+ def self.list(attributes = {})
13
+ List.new resource(location, attributes).get(attributes)
14
+ end
15
+
16
+ def reload(attributes = {})
17
+ assign_attributes resource(attributes).get(attributes)
18
+ end
19
+
20
+ def revoke(attributes = {})
21
+ assign_attributes nested_resource("revoke", attributes).post(attributes)
22
+ end
23
+ end
24
+ end
@@ -35,6 +35,10 @@ module Omise
35
35
  assign_attributes resource(attributes).delete
36
36
  end
37
37
 
38
+ def schedules(attributes = {})
39
+ List.new nested_resource("schedules", attributes).get(attributes)
40
+ end
41
+
38
42
  def charge(attributes = {})
39
43
  if !defined?(Charge)
40
44
  require "omise/charge"
@@ -0,0 +1,15 @@
1
+ require "omise/object"
2
+
3
+ module Omise
4
+ class Forex < OmiseObject
5
+ self.endpoint = "/forex"
6
+
7
+ def self.from(currency, attributes = {})
8
+ new resource(location(currency.to_s.downcase), attributes).get(attributes)
9
+ end
10
+
11
+ def reload(attributes = {})
12
+ assign_attributes resource(attributes).get(attributes)
13
+ end
14
+ end
15
+ end
@@ -9,6 +9,10 @@ module Omise
9
9
  SearchScope.new(:refund)
10
10
  end
11
11
 
12
+ def self.list(attributes = {})
13
+ List.new resource(location, attributes).get(attributes)
14
+ end
15
+
12
16
  def reload(attributes = {})
13
17
  assign_attributes resource(attributes).get(attributes)
14
18
  end
@@ -17,6 +17,7 @@ module Omise
17
17
  @period = options[:period]
18
18
  @on = options[:on]
19
19
  @end_date = options[:end_date]
20
+ @start_date = options[:start_date]
20
21
  end
21
22
 
22
23
  def type
@@ -59,6 +60,11 @@ module Omise
59
60
  end
60
61
  alias_method :month, :months
61
62
 
63
+ def start_date(date)
64
+ date = Date.parse(date.to_s)
65
+ renew(start_date: date.iso8601)
66
+ end
67
+
62
68
  def end_date(date)
63
69
  date = Date.parse(date.to_s)
64
70
  renew(end_date: date.iso8601)
@@ -109,11 +115,12 @@ module Omise
109
115
 
110
116
  def to_attributes
111
117
  {}.tap do |a|
112
- a[@type] = @attributes
113
- a[:every] = @every if @every
114
- a[:period] = @period if @period
115
- a[:on] = @on if @on
116
- a[:end_date] = @end_date if @end_date
118
+ a[@type] = @attributes
119
+ a[:every] = @every if @every
120
+ a[:period] = @period if @period
121
+ a[:on] = @on if @on
122
+ a[:end_date] = @end_date if @end_date
123
+ a[:start_date] = @start_date if @start_date
117
124
  end
118
125
  end
119
126
 
@@ -139,10 +146,11 @@ module Omise
139
146
 
140
147
  def renew(attributes)
141
148
  self.class.new(@type, @attributes, {
142
- every: @every,
143
- period: @period,
144
- on: @on,
145
- end_date: @end_date,
149
+ every: @every,
150
+ period: @period,
151
+ on: @on,
152
+ end_date: @end_date,
153
+ start_date: @start_date,
146
154
  }.merge(attributes))
147
155
  end
148
156
  end
@@ -1,3 +1,3 @@
1
1
  module Omise
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -0,0 +1,15 @@
1
+ {
2
+ "object": "list",
3
+ "from": "1970-01-01T00:00:00+00:00",
4
+ "to": "2015-01-15T05:04:30+00:00",
5
+ "offset": 0,
6
+ "limit": 20,
7
+ "total": 2,
8
+ "data": [
9
+ {
10
+ "object": "chain",
11
+ "id": "acch_test_57io26ws5af7plco6k1",
12
+ "location": "/chains/acch_test_57io26ws5af7plco6k1"
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "object": "chain",
3
+ "id": "acch_test_57io26ws5af7plco6k1",
4
+ "location": "/chains/acch_test_57io26ws5af7plco6k1",
5
+ "revoked": false
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "object": "chain",
3
+ "id": "acch_test_57io26ws5af7plco6k1",
4
+ "location": "/chains/acch_test_57io26ws5af7plco6k1",
5
+ "revoked": true
6
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "object": "list",
3
+ "data": [
4
+ {
5
+ "object": "schedule",
6
+ "location": "/schedules/schd_test_4yq7duw15p9hdrjp8oq",
7
+ "id": "schd_test_4yq7duw15p9hdrjp8oq"
8
+ }
9
+ ]
10
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "object": "forex",
3
+ "from": "usd",
4
+ "to": "thb",
5
+ "rate": 32.85436545,
6
+ "location": "/forex/usd"
7
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "object": "list",
3
+ "from": "1970-01-01T00:00:00+00:00",
4
+ "to": "2015-01-16T07:24:51+00:00",
5
+ "offset": 0,
6
+ "limit": 20,
7
+ "total": 1,
8
+ "data": [
9
+ {
10
+ "object": "refund",
11
+ "id": "rfnd_test_4yqmv79ahghsiz23y3c",
12
+ "location": "/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds/rfnd_test_4yqmv79ahghsiz23y3c",
13
+ "amount": 10000,
14
+ "currency": "thb",
15
+ "charge": "chrg_test_4yq7duw15p9hdrjp8oq",
16
+ "transaction": "trxn_test_4yqmv79fzpy0gmz5mmq",
17
+ "created": "2015-01-16T07:23:45Z"
18
+ }
19
+ ],
20
+ "location": "/charges/chrg_test_4yq7duw15p9hdrjp8oq/refunds"
21
+ }
@@ -48,12 +48,24 @@ class TestAttributes < Omise::Test
48
48
 
49
49
  def test_that_we_can_tell_if_a_teapot_has_not_been_destroyed
50
50
  refute @teapot.destroyed?
51
+ refute @teapot.deleted?
51
52
  end
52
53
 
53
54
  def test_that_we_can_tell_if_a_teapot_has_been_destroyed
54
55
  @teapot.assign_attributes(@attributes.merge("deleted" => true))
55
56
 
56
57
  assert @teapot.destroyed?
58
+ assert @teapot.deleted?
59
+ end
60
+
61
+ def test_we_can_predicate_any_key
62
+ assert @teapot.child?
63
+ end
64
+
65
+ def test_we_cannot_predicate_a_key_not_present
66
+ assert_raises NoMethodError do
67
+ @teapot.color?
68
+ end
57
69
  end
58
70
 
59
71
  def test_that_we_get_the_location_of_the_teapot
@@ -76,4 +88,9 @@ class TestAttributes < Omise::Test
76
88
  assert @teapot.respond_to?("name")
77
89
  refute @teapot.respond_to?("color")
78
90
  end
91
+
92
+ def test_that_a_teap_respond_correctly_to_dynamic_predicates
93
+ assert @teapot.respond_to?("deleted?")
94
+ refute @teapot.respond_to?("revoked?")
95
+ end
79
96
  end
@@ -0,0 +1,40 @@
1
+ require "support"
2
+
3
+ class TestChain < Omise::Test
4
+ setup do
5
+ @chain = Omise::Chain.retrieve("acch_test_57io26ws5af7plco6k1")
6
+ end
7
+
8
+ def test_that_we_can_list_all_chains
9
+ chains = Omise::Chain.list
10
+
11
+ assert chains
12
+ assert_instance_of Omise::List, chains
13
+ assert_instance_of Omise::Chain, chains.first
14
+ end
15
+
16
+ def test_that_we_can_retrieve_a_chain
17
+ chain = Omise::Chain.retrieve("acch_test_57io26ws5af7plco6k1")
18
+
19
+ assert chain
20
+ assert_instance_of Omise::Chain, chain
21
+ end
22
+
23
+ def test_that_we_can_reload_a_chain
24
+ @chain.attributes.taint
25
+ @chain.reload
26
+
27
+ refute @chain.attributes.tainted?
28
+ end
29
+
30
+ def test_that_we_can_revoke_a_chain
31
+ @chain.attributes.taint
32
+
33
+ refute @chain.revoked
34
+
35
+ @chain.revoke
36
+
37
+ assert @chain.revoked?
38
+ refute @chain.attributes.tainted?
39
+ end
40
+ end
@@ -72,4 +72,11 @@ class TestCustomer < Omise::Test
72
72
  assert_instance_of Omise::SearchScope, Omise::Customer.search
73
73
  assert_equal "customer", Omise::Customer.search.scope
74
74
  end
75
+
76
+ def test_that_we_can_fetch_a_schedule_list_for_a_given_customer
77
+ schedules = @customer.schedules
78
+
79
+ assert schedules
80
+ assert_instance_of Omise::List, schedules
81
+ end
75
82
  end
@@ -0,0 +1,26 @@
1
+ require "support"
2
+
3
+ class TestForex < Omise::Test
4
+ setup do
5
+ @forex = Omise::Forex.from("USD")
6
+ end
7
+
8
+ def test_that_we_can_retrieve_a_forex
9
+ forex = Omise::Forex.from("usd")
10
+
11
+ assert_instance_of Omise::Forex, forex
12
+ end
13
+
14
+ def test_that_we_can_retrieve_a_forex_by_passing_symbol
15
+ forex = Omise::Forex.from(:usd)
16
+
17
+ assert_instance_of Omise::Forex, forex
18
+ end
19
+
20
+ def test_that_we_can_reload_a_forex
21
+ @forex.attributes.taint
22
+ @forex.reload
23
+
24
+ refute @forex.attributes.tainted?
25
+ end
26
+ end
@@ -11,6 +11,14 @@ class TestRefund < Omise::Test
11
11
  assert_equal "rfnd_test_4yqmv79ahghsiz23y3c", @refund.id
12
12
  end
13
13
 
14
+ def test_that_we_can_list_all_refunds
15
+ refunds = Omise::Refund.list
16
+
17
+ assert refunds
18
+ assert_instance_of Omise::List, refunds
19
+ assert_instance_of Omise::Refund, refunds.first
20
+ end
21
+
14
22
  def test_that_we_can_create_a_refund
15
23
  refund = @refunds.create(amount: 10000)
16
24
 
@@ -113,6 +113,22 @@ class TestScheduler < Omise::Test
113
113
  assert_equal "2018-01-01", scheduler.to_attributes[:end_date]
114
114
  end
115
115
 
116
+ def test_we_can_set_start_date
117
+ scheduler = @scheduler.start_date("2018-01-01")
118
+
119
+ assert_scheduler_attributes(@scheduler)
120
+ refute_equal scheduler.object_id, @scheduler.object_id
121
+ assert_equal "2018-01-01", scheduler.to_attributes[:start_date]
122
+ end
123
+
124
+ def test_we_can_set_start_date_in_other_formats
125
+ scheduler = @scheduler.start_date("1st January 2018")
126
+
127
+ assert_scheduler_attributes(@scheduler)
128
+ refute_equal scheduler.object_id, @scheduler.object_id
129
+ assert_equal "2018-01-01", scheduler.to_attributes[:start_date]
130
+ end
131
+
116
132
  def that_we_can_parse_it_all_in_one
117
133
  scheduler = @scheduler.parse("every 1 month on the 28th until May 1st, 2018")
118
134
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Clart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-31 00:00:00.000000000 Z
11
+ date: 2017-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -119,6 +119,7 @@ files:
119
119
  - lib/omise/bank_account.rb
120
120
  - lib/omise/card.rb
121
121
  - lib/omise/card_list.rb
122
+ - lib/omise/chain.rb
122
123
  - lib/omise/charge.rb
123
124
  - lib/omise/charge_list.rb
124
125
  - lib/omise/config.rb
@@ -128,6 +129,7 @@ files:
128
129
  - lib/omise/document_list.rb
129
130
  - lib/omise/error.rb
130
131
  - lib/omise/event.rb
132
+ - lib/omise/forex.rb
131
133
  - lib/omise/http_logger.rb
132
134
  - lib/omise/link.rb
133
135
  - lib/omise/list.rb
@@ -153,6 +155,9 @@ files:
153
155
  - omise.gemspec
154
156
  - test/fixtures/api.omise.co/account-get.json
155
157
  - test/fixtures/api.omise.co/balance-get.json
158
+ - test/fixtures/api.omise.co/chains-get.json
159
+ - test/fixtures/api.omise.co/chains/acch_test_57io26ws5af7plco6k1-get.json
160
+ - test/fixtures/api.omise.co/chains/acch_test_57io26ws5af7plco6k1/revoke-post.json
156
161
  - test/fixtures/api.omise.co/charges-get-limit-20-offset-0.json
157
162
  - test/fixtures/api.omise.co/charges-get-limit-20-offset-20.json
158
163
  - test/fixtures/api.omise.co/charges-get.json
@@ -178,6 +183,7 @@ files:
178
183
  - test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-delete.json
179
184
  - test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-get.json
180
185
  - test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-patch.json
186
+ - test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/schedules-get.json
181
187
  - test/fixtures/api.omise.co/disputes-get.json
182
188
  - test/fixtures/api.omise.co/disputes/closed-get.json
183
189
  - test/fixtures/api.omise.co/disputes/dspt_test_5089off452g5m5te7xs-get.json
@@ -190,6 +196,7 @@ files:
190
196
  - test/fixtures/api.omise.co/disputes/pending-get.json
191
197
  - test/fixtures/api.omise.co/events-get.json
192
198
  - test/fixtures/api.omise.co/events/evnt_test_52cin5n9bb6lytxduh9-get.json
199
+ - test/fixtures/api.omise.co/forex/usd-get.json
193
200
  - test/fixtures/api.omise.co/links-get.json
194
201
  - test/fixtures/api.omise.co/links-post.json
195
202
  - test/fixtures/api.omise.co/links/link_test_55pcclmznvrv9lc7r9s-get.json
@@ -199,6 +206,7 @@ files:
199
206
  - test/fixtures/api.omise.co/recipients/recp_test_50894vc13y8z4v51iuc-delete.json
200
207
  - test/fixtures/api.omise.co/recipients/recp_test_50894vc13y8z4v51iuc-get.json
201
208
  - test/fixtures/api.omise.co/recipients/recp_test_50894vc13y8z4v51iuc-patch.json
209
+ - test/fixtures/api.omise.co/refunds-get.json
202
210
  - test/fixtures/api.omise.co/schedules-get.json
203
211
  - test/fixtures/api.omise.co/schedules-post.json
204
212
  - test/fixtures/api.omise.co/schedules/schd_test_4yq7duw15p9hdrjp8oq-delete.json
@@ -219,12 +227,14 @@ files:
219
227
  - test/omise/test_attributes.rb
220
228
  - test/omise/test_balance.rb
221
229
  - test/omise/test_card.rb
230
+ - test/omise/test_chain.rb
222
231
  - test/omise/test_charge.rb
223
232
  - test/omise/test_config.rb
224
233
  - test/omise/test_customer.rb
225
234
  - test/omise/test_dispute.rb
226
235
  - test/omise/test_document.rb
227
236
  - test/omise/test_event.rb
237
+ - test/omise/test_forex.rb
228
238
  - test/omise/test_http_logger.rb
229
239
  - test/omise/test_link.rb
230
240
  - test/omise/test_list.rb
@@ -268,6 +278,9 @@ summary: Omise Ruby client
268
278
  test_files:
269
279
  - test/fixtures/api.omise.co/account-get.json
270
280
  - test/fixtures/api.omise.co/balance-get.json
281
+ - test/fixtures/api.omise.co/chains-get.json
282
+ - test/fixtures/api.omise.co/chains/acch_test_57io26ws5af7plco6k1-get.json
283
+ - test/fixtures/api.omise.co/chains/acch_test_57io26ws5af7plco6k1/revoke-post.json
271
284
  - test/fixtures/api.omise.co/charges-get-limit-20-offset-0.json
272
285
  - test/fixtures/api.omise.co/charges-get-limit-20-offset-20.json
273
286
  - test/fixtures/api.omise.co/charges-get.json
@@ -293,6 +306,7 @@ test_files:
293
306
  - test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-delete.json
294
307
  - test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-get.json
295
308
  - test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/cards/card_test_4yq6tuucl9h4erukfl0-patch.json
309
+ - test/fixtures/api.omise.co/customers/cust_test_4yq6txdpfadhbaqnwp3/schedules-get.json
296
310
  - test/fixtures/api.omise.co/disputes-get.json
297
311
  - test/fixtures/api.omise.co/disputes/closed-get.json
298
312
  - test/fixtures/api.omise.co/disputes/dspt_test_5089off452g5m5te7xs-get.json
@@ -305,6 +319,7 @@ test_files:
305
319
  - test/fixtures/api.omise.co/disputes/pending-get.json
306
320
  - test/fixtures/api.omise.co/events-get.json
307
321
  - test/fixtures/api.omise.co/events/evnt_test_52cin5n9bb6lytxduh9-get.json
322
+ - test/fixtures/api.omise.co/forex/usd-get.json
308
323
  - test/fixtures/api.omise.co/links-get.json
309
324
  - test/fixtures/api.omise.co/links-post.json
310
325
  - test/fixtures/api.omise.co/links/link_test_55pcclmznvrv9lc7r9s-get.json
@@ -314,6 +329,7 @@ test_files:
314
329
  - test/fixtures/api.omise.co/recipients/recp_test_50894vc13y8z4v51iuc-delete.json
315
330
  - test/fixtures/api.omise.co/recipients/recp_test_50894vc13y8z4v51iuc-get.json
316
331
  - test/fixtures/api.omise.co/recipients/recp_test_50894vc13y8z4v51iuc-patch.json
332
+ - test/fixtures/api.omise.co/refunds-get.json
317
333
  - test/fixtures/api.omise.co/schedules-get.json
318
334
  - test/fixtures/api.omise.co/schedules-post.json
319
335
  - test/fixtures/api.omise.co/schedules/schd_test_4yq7duw15p9hdrjp8oq-delete.json
@@ -334,12 +350,14 @@ test_files:
334
350
  - test/omise/test_attributes.rb
335
351
  - test/omise/test_balance.rb
336
352
  - test/omise/test_card.rb
353
+ - test/omise/test_chain.rb
337
354
  - test/omise/test_charge.rb
338
355
  - test/omise/test_config.rb
339
356
  - test/omise/test_customer.rb
340
357
  - test/omise/test_dispute.rb
341
358
  - test/omise/test_document.rb
342
359
  - test/omise/test_event.rb
360
+ - test/omise/test_forex.rb
343
361
  - test/omise/test_http_logger.rb
344
362
  - test/omise/test_link.rb
345
363
  - test/omise/test_list.rb