stripe 1.28.1 → 1.29.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/History.txt +2 -2
- data/VERSION +1 -1
- data/lib/stripe/account.rb +2 -2
- data/lib/stripe/api_operations/create.rb +3 -9
- data/lib/stripe/api_operations/list.rb +17 -9
- data/lib/stripe/application_fee.rb +1 -1
- data/lib/stripe/application_fee_refund.rb +1 -1
- data/lib/stripe/balance_transaction.rb +1 -1
- data/lib/stripe/bank_account.rb +1 -1
- data/lib/stripe/bitcoin_receiver.rb +2 -2
- data/lib/stripe/bitcoin_transaction.rb +1 -1
- data/lib/stripe/card.rb +1 -1
- data/lib/stripe/charge.rb +2 -2
- data/lib/stripe/coupon.rb +2 -2
- data/lib/stripe/customer.rb +2 -2
- data/lib/stripe/dispute.rb +2 -2
- data/lib/stripe/event.rb +1 -1
- data/lib/stripe/file_upload.rb +2 -2
- data/lib/stripe/invoice.rb +2 -2
- data/lib/stripe/invoice_item.rb +2 -2
- data/lib/stripe/list_object.rb +64 -3
- data/lib/stripe/order.rb +2 -2
- data/lib/stripe/plan.rb +2 -2
- data/lib/stripe/product.rb +2 -2
- data/lib/stripe/recipient.rb +2 -2
- data/lib/stripe/refund.rb +2 -2
- data/lib/stripe/reversal.rb +1 -1
- data/lib/stripe/sku.rb +2 -2
- data/lib/stripe/stripe_object.rb +7 -0
- data/lib/stripe/token.rb +1 -1
- data/lib/stripe/transfer.rb +2 -2
- data/lib/stripe/version.rb +1 -1
- data/test/stripe/api_resource_test.rb +10 -9
- data/test/stripe/application_fee_test.rb +1 -1
- data/test/stripe/bitcoin_receiver_test.rb +2 -2
- data/test/stripe/bitcoin_transaction_test.rb +1 -1
- data/test/stripe/charge_test.rb +1 -1
- data/test/stripe/customer_card_test.rb +1 -1
- data/test/stripe/customer_test.rb +1 -1
- data/test/stripe/dispute_test.rb +1 -1
- data/test/stripe/file_upload_test.rb +1 -1
- data/test/stripe/list_object_test.rb +123 -13
- data/test/stripe/order_test.rb +1 -1
- data/test/stripe/product_test.rb +1 -1
- data/test/stripe/recipient_card_test.rb +1 -1
- data/test/stripe/refund_test.rb +1 -1
- data/test/stripe/sku_test.rb +1 -1
- data/test/stripe/stripe_object_test.rb +10 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cad15842f509a5f748f5e644a3932ea8b45ae480
|
4
|
+
data.tar.gz: defecc310910f380f32d973ec2c1032b08e85a51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0776d66e4e13d87f2b5478e24cd00e4e00c4990bf7cf2f0e652e6f052cb17c7e90c0e4514f8ab7daa485b33751acf79fa11d6a1d5908d5536f2a63d7fdf2fc3a
|
7
|
+
data.tar.gz: 0e1e2e41df59fb7ec775240b279a4bde6087883d37024b6f01794ccdc0ab91aaa100b39c35b06e5f8242f246f9e8d3ff8dd9795ed12ceab9a69404b2dbaca2ea
|
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.29.0
|
data/lib/stripe/account.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Account < APIResource
|
3
|
-
|
3
|
+
extend Stripe::APIOperations::Create
|
4
4
|
include Stripe::APIOperations::Delete
|
5
|
-
|
5
|
+
extend Stripe::APIOperations::List
|
6
6
|
include Stripe::APIOperations::Update
|
7
7
|
|
8
8
|
def url
|
@@ -1,15 +1,9 @@
|
|
1
1
|
module Stripe
|
2
2
|
module APIOperations
|
3
3
|
module Create
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Util.convert_to_stripe_object(response, opts)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.included(base)
|
12
|
-
base.extend(ClassMethods)
|
4
|
+
def create(params={}, opts={})
|
5
|
+
response, opts = request(:post, url, params, opts)
|
6
|
+
Util.convert_to_stripe_object(response, opts)
|
13
7
|
end
|
14
8
|
end
|
15
9
|
end
|
@@ -1,17 +1,25 @@
|
|
1
1
|
module Stripe
|
2
2
|
module APIOperations
|
3
3
|
module List
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
4
|
+
def list(filters={}, opts={})
|
5
|
+
opts = Util.normalize_opts(opts)
|
6
|
+
opts = @opts.merge(opts) if @opts
|
7
|
+
|
8
|
+
response, opts = request(:get, url, filters, opts)
|
9
|
+
obj = ListObject.construct_from(response, opts)
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
# set a limit so that we can fetch the same number when accessing the
|
12
|
+
# next and previous pages
|
13
|
+
obj.limit = filters[:limit]
|
14
|
+
|
15
|
+
obj
|
14
16
|
end
|
17
|
+
|
18
|
+
# The original version of #list was given the somewhat unfortunate name of
|
19
|
+
# #all, and this alias allows us to maintain backward compatibility (the
|
20
|
+
# choice was somewhat misleading in the way that it only returned a single
|
21
|
+
# page rather than all objects).
|
22
|
+
alias :all :list
|
15
23
|
end
|
16
24
|
end
|
17
25
|
end
|
data/lib/stripe/bank_account.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Stripe
|
2
2
|
class BitcoinReceiver < APIResource
|
3
|
-
|
3
|
+
extend Stripe::APIOperations::Create
|
4
4
|
include Stripe::APIOperations::Update
|
5
5
|
include Stripe::APIOperations::Delete
|
6
|
-
|
6
|
+
extend Stripe::APIOperations::List
|
7
7
|
|
8
8
|
def self.url
|
9
9
|
"/v1/bitcoin/receivers"
|
data/lib/stripe/card.rb
CHANGED
data/lib/stripe/charge.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Charge < APIResource
|
3
|
-
|
4
|
-
|
3
|
+
extend Stripe::APIOperations::List
|
4
|
+
extend Stripe::APIOperations::Create
|
5
5
|
include Stripe::APIOperations::Update
|
6
6
|
|
7
7
|
def refund(params={}, opts={})
|
data/lib/stripe/coupon.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Coupon < APIResource
|
3
|
-
|
3
|
+
extend Stripe::APIOperations::Create
|
4
4
|
include Stripe::APIOperations::Update
|
5
5
|
include Stripe::APIOperations::Delete
|
6
|
-
|
6
|
+
extend Stripe::APIOperations::List
|
7
7
|
end
|
8
8
|
end
|
data/lib/stripe/customer.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Customer < APIResource
|
3
|
-
|
3
|
+
extend Stripe::APIOperations::Create
|
4
4
|
include Stripe::APIOperations::Delete
|
5
5
|
include Stripe::APIOperations::Update
|
6
|
-
|
6
|
+
extend Stripe::APIOperations::List
|
7
7
|
|
8
8
|
def add_invoice_item(params, opts={})
|
9
9
|
opts = @opts.merge(Util.normalize_opts(opts))
|
data/lib/stripe/dispute.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Dispute < APIResource
|
3
|
-
|
4
|
-
|
3
|
+
extend Stripe::APIOperations::List
|
4
|
+
extend Stripe::APIOperations::Create
|
5
5
|
include Stripe::APIOperations::Update
|
6
6
|
|
7
7
|
def close(params={}, opts={})
|
data/lib/stripe/event.rb
CHANGED
data/lib/stripe/file_upload.rb
CHANGED
data/lib/stripe/invoice.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Invoice < APIResource
|
3
|
-
|
3
|
+
extend Stripe::APIOperations::List
|
4
4
|
include Stripe::APIOperations::Update
|
5
|
-
|
5
|
+
extend Stripe::APIOperations::Create
|
6
6
|
|
7
7
|
def self.upcoming(params, opts={})
|
8
8
|
response, opts = request(:get, upcoming_url, params, opts)
|
data/lib/stripe/invoice_item.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Stripe
|
2
2
|
class InvoiceItem < APIResource
|
3
|
-
|
4
|
-
|
3
|
+
extend Stripe::APIOperations::List
|
4
|
+
extend Stripe::APIOperations::Create
|
5
5
|
include Stripe::APIOperations::Delete
|
6
6
|
include Stripe::APIOperations::Update
|
7
7
|
end
|
data/lib/stripe/list_object.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
module Stripe
|
2
2
|
class ListObject < StripeObject
|
3
3
|
include Enumerable
|
4
|
+
include Stripe::APIOperations::List
|
4
5
|
include Stripe::APIOperations::Request
|
5
6
|
|
7
|
+
# This accessor allows a `ListObject` to inherit a limit that was given to
|
8
|
+
# a predecessor. This allows consistent limits as a user pages through
|
9
|
+
# resources.
|
10
|
+
attr_accessor :limit
|
11
|
+
|
12
|
+
# An empty list object. This is returned from +next+ when we know that
|
13
|
+
# there isn't a next page in order to replicate the behavior of the API
|
14
|
+
# when it attempts to return a page beyond the last.
|
15
|
+
def self.empty_list(opts={})
|
16
|
+
ListObject.construct_from({ :data => [] }, opts)
|
17
|
+
end
|
18
|
+
|
6
19
|
def [](k)
|
7
20
|
case k
|
8
21
|
when String, Symbol
|
@@ -12,10 +25,32 @@ module Stripe
|
|
12
25
|
end
|
13
26
|
end
|
14
27
|
|
28
|
+
# Iterates through each resource in the page represented by the current
|
29
|
+
# `ListObject`.
|
30
|
+
#
|
31
|
+
# Note that this method makes no effort to fetch a new page when it gets to
|
32
|
+
# the end of the current page's resources. See also +auto_paging_each+.
|
15
33
|
def each(&blk)
|
16
34
|
self.data.each(&blk)
|
17
35
|
end
|
18
36
|
|
37
|
+
# Iterates through each resource in all pages, making additional fetches to
|
38
|
+
# the API as necessary.
|
39
|
+
#
|
40
|
+
# Note that this method will make as many API calls as necessary to fetch
|
41
|
+
# all resources. For more granular control, please see +each+ and
|
42
|
+
# +next_page+.
|
43
|
+
def auto_paging_each(&blk)
|
44
|
+
return enum_for(:auto_paging_each) unless block_given?
|
45
|
+
|
46
|
+
page = self
|
47
|
+
loop do
|
48
|
+
page.each(&blk)
|
49
|
+
page = page.next_page
|
50
|
+
break if page.empty?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
19
54
|
# Returns true if the page object contains no elements.
|
20
55
|
def empty?
|
21
56
|
self.data.empty?
|
@@ -32,9 +67,35 @@ module Stripe
|
|
32
67
|
Util.convert_to_stripe_object(response, opts)
|
33
68
|
end
|
34
69
|
|
35
|
-
|
36
|
-
|
37
|
-
|
70
|
+
# Fetches the next page in the resource list (if there is one).
|
71
|
+
#
|
72
|
+
# This method will try to respect the limit of the current page. If none
|
73
|
+
# was given, the default limit will be fetched again.
|
74
|
+
def next_page(params={}, opts={})
|
75
|
+
return self.class.empty_list(opts) if !has_more
|
76
|
+
last_id = data.last.id
|
77
|
+
|
78
|
+
params = {
|
79
|
+
:limit => limit, # may be nil
|
80
|
+
:starting_after => last_id,
|
81
|
+
}.merge(params)
|
82
|
+
|
83
|
+
list(params, opts)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Fetches the previous page in the resource list (if there is one).
|
87
|
+
#
|
88
|
+
# This method will try to respect the limit of the current page. If none
|
89
|
+
# was given, the default limit will be fetched again.
|
90
|
+
def previous_page(params={}, opts={})
|
91
|
+
first_id = data.first.id
|
92
|
+
|
93
|
+
params = {
|
94
|
+
:ending_before => first_id,
|
95
|
+
:limit => limit, # may be nil
|
96
|
+
}.merge(params)
|
97
|
+
|
98
|
+
list(params, opts)
|
38
99
|
end
|
39
100
|
end
|
40
101
|
end
|
data/lib/stripe/order.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Order < APIResource
|
3
|
-
|
4
|
-
|
3
|
+
extend Stripe::APIOperations::List
|
4
|
+
extend Stripe::APIOperations::Create
|
5
5
|
include Stripe::APIOperations::Update
|
6
6
|
|
7
7
|
def pay(params, opts={})
|
data/lib/stripe/plan.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Plan < APIResource
|
3
|
-
|
3
|
+
extend Stripe::APIOperations::Create
|
4
4
|
include Stripe::APIOperations::Delete
|
5
|
-
|
5
|
+
extend Stripe::APIOperations::List
|
6
6
|
include Stripe::APIOperations::Update
|
7
7
|
end
|
8
8
|
end
|
data/lib/stripe/product.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Product < APIResource
|
3
|
-
|
4
|
-
|
3
|
+
extend Stripe::APIOperations::List
|
4
|
+
extend Stripe::APIOperations::Create
|
5
5
|
include Stripe::APIOperations::Update
|
6
6
|
|
7
7
|
# Keep APIResource#url as `api_url` to avoid letting the external URL
|
data/lib/stripe/recipient.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Stripe
|
2
2
|
class Recipient < APIResource
|
3
|
-
|
3
|
+
extend Stripe::APIOperations::Create
|
4
4
|
include Stripe::APIOperations::Delete
|
5
5
|
include Stripe::APIOperations::Update
|
6
|
-
|
6
|
+
extend Stripe::APIOperations::List
|
7
7
|
|
8
8
|
def transfers
|
9
9
|
Transfer.all({ :recipient => id }, @api_key)
|
data/lib/stripe/refund.rb
CHANGED
data/lib/stripe/reversal.rb
CHANGED
data/lib/stripe/sku.rb
CHANGED
data/lib/stripe/stripe_object.rb
CHANGED
@@ -25,6 +25,13 @@ module Stripe
|
|
25
25
|
self.new(values[:id]).refresh_from(values, opts)
|
26
26
|
end
|
27
27
|
|
28
|
+
# Determines the equality of two Stripe objects. Stripe objects are
|
29
|
+
# considered to be equal if they have the same set of values and each one
|
30
|
+
# of those values is the same.
|
31
|
+
def ==(other)
|
32
|
+
@values == other.instance_variable_get(:@values)
|
33
|
+
end
|
34
|
+
|
28
35
|
def to_s(*args)
|
29
36
|
JSON.pretty_generate(@values)
|
30
37
|
end
|
data/lib/stripe/token.rb
CHANGED
data/lib/stripe/transfer.rb
CHANGED
data/lib/stripe/version.rb
CHANGED
@@ -39,10 +39,10 @@ module Stripe
|
|
39
39
|
|
40
40
|
should "using a nil api key should raise an exception" do
|
41
41
|
assert_raises TypeError do
|
42
|
-
Stripe::Customer.
|
42
|
+
Stripe::Customer.list({}, nil)
|
43
43
|
end
|
44
44
|
assert_raises TypeError do
|
45
|
-
Stripe::Customer.
|
45
|
+
Stripe::Customer.list({}, { :api_key => nil })
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -231,17 +231,17 @@ module Stripe
|
|
231
231
|
should "urlencode values in GET params" do
|
232
232
|
response = make_response(make_charge_array)
|
233
233
|
@mock.expects(:get).with("#{Stripe.api_base}/v1/charges?customer=test%20customer", nil, nil).returns(response)
|
234
|
-
charges = Stripe::Charge.
|
234
|
+
charges = Stripe::Charge.list(:customer => 'test customer').data
|
235
235
|
assert charges.kind_of? Array
|
236
236
|
end
|
237
237
|
|
238
238
|
should "construct URL properly with base query parameters" do
|
239
239
|
response = make_response(make_invoice_customer_array)
|
240
240
|
@mock.expects(:get).with("#{Stripe.api_base}/v1/invoices?customer=test_customer", nil, nil).returns(response)
|
241
|
-
invoices = Stripe::Invoice.
|
241
|
+
invoices = Stripe::Invoice.list(:customer => 'test_customer')
|
242
242
|
|
243
243
|
@mock.expects(:get).with("#{Stripe.api_base}/v1/invoices?customer=test_customer&paid=true", nil, nil).returns(response)
|
244
|
-
invoices.
|
244
|
+
invoices.list(:paid => true)
|
245
245
|
end
|
246
246
|
|
247
247
|
should "a 400 should give an InvalidRequestError with http status, body, and JSON body" do
|
@@ -311,7 +311,7 @@ module Stripe
|
|
311
311
|
(url =~ %r{^#{Stripe.api_base}/v1/charges?} &&
|
312
312
|
query.keys.sort == ['offset', 'sad'])
|
313
313
|
end.returns(make_response({ :count => 1, :data => [make_charge] }))
|
314
|
-
Stripe::Charge.
|
314
|
+
Stripe::Charge.list(:count => nil, :offset => 5, :sad => false)
|
315
315
|
|
316
316
|
@mock.expects(:post).with do |url, api_key, params|
|
317
317
|
url == "#{Stripe.api_base}/v1/charges" &&
|
@@ -335,8 +335,9 @@ module Stripe
|
|
335
335
|
|
336
336
|
should "making a GET request with parameters should have a query string and no body" do
|
337
337
|
params = { :limit => 1 }
|
338
|
-
@mock.expects(:get).once.with("#{Stripe.api_base}/v1/charges?limit=1", nil, nil).
|
339
|
-
|
338
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/v1/charges?limit=1", nil, nil).
|
339
|
+
returns(make_response({ :data => [make_charge] }))
|
340
|
+
Stripe::Charge.list(params)
|
340
341
|
end
|
341
342
|
|
342
343
|
should "making a POST request with parameters should have a body and no query string" do
|
@@ -407,7 +408,7 @@ module Stripe
|
|
407
408
|
|
408
409
|
should "loading all of an APIResource should return an array of recursively instantiated objects" do
|
409
410
|
@mock.expects(:get).once.returns(make_response(make_charge_array))
|
410
|
-
c = Stripe::Charge.
|
411
|
+
c = Stripe::Charge.list.data
|
411
412
|
assert c.kind_of? Array
|
412
413
|
assert c[0].kind_of? Stripe::Charge
|
413
414
|
assert c[0].card.kind_of?(Stripe::StripeObject) && c[0].card.object == 'card'
|
@@ -4,7 +4,7 @@ module Stripe
|
|
4
4
|
class ApplicationFeeTest < Test::Unit::TestCase
|
5
5
|
should "application fees should be listable" do
|
6
6
|
@mock.expects(:get).once.returns(make_response(make_application_fee_array))
|
7
|
-
fees = Stripe::ApplicationFee.
|
7
|
+
fees = Stripe::ApplicationFee.list
|
8
8
|
assert fees.data.kind_of? Array
|
9
9
|
fees.each do |fee|
|
10
10
|
assert fee.kind_of?(Stripe::ApplicationFee)
|
@@ -16,7 +16,7 @@ module Stripe
|
|
16
16
|
|
17
17
|
should "all should list bitcoin receivers" do
|
18
18
|
@mock.expects(:get).once.returns(make_response(make_bitcoin_receiver_array))
|
19
|
-
receivers = Stripe::BitcoinReceiver.
|
19
|
+
receivers = Stripe::BitcoinReceiver.list
|
20
20
|
assert_equal 3, receivers.data.length
|
21
21
|
assert receivers.data.kind_of? Array
|
22
22
|
receivers.each do |receiver|
|
@@ -31,7 +31,7 @@ module Stripe
|
|
31
31
|
@mock.expects(:get).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver", nil, nil).once.returns(make_response(make_bitcoin_receiver))
|
32
32
|
receiver = Stripe::BitcoinReceiver.retrieve('btcrcv_test_receiver')
|
33
33
|
@mock.expects(:get).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver/transactions", nil, nil).once.returns(make_response(make_bitcoin_transaction_array))
|
34
|
-
transactions = receiver.transactions.
|
34
|
+
transactions = receiver.transactions.list
|
35
35
|
assert_equal(3, transactions.data.length)
|
36
36
|
end
|
37
37
|
|
@@ -18,7 +18,7 @@ module Stripe
|
|
18
18
|
with("#{Stripe.api_base}/v1/bitcoin/transactions", nil, nil).
|
19
19
|
once.
|
20
20
|
returns(make_response(make_bitcoin_transaction_array))
|
21
|
-
transactions = Stripe::BitcoinTransaction.
|
21
|
+
transactions = Stripe::BitcoinTransaction.list
|
22
22
|
assert_equal 3, transactions.data.length
|
23
23
|
assert transactions.data.kind_of? Array
|
24
24
|
transactions.each do |transaction|
|
data/test/stripe/charge_test.rb
CHANGED
@@ -4,7 +4,7 @@ module Stripe
|
|
4
4
|
class ChargeTest < Test::Unit::TestCase
|
5
5
|
should "charges should be listable" do
|
6
6
|
@mock.expects(:get).once.returns(make_response(make_charge_array))
|
7
|
-
c = Stripe::Charge.
|
7
|
+
c = Stripe::Charge.list
|
8
8
|
assert c.data.kind_of? Array
|
9
9
|
c.each do |charge|
|
10
10
|
assert charge.kind_of?(Stripe::Charge)
|
@@ -12,7 +12,7 @@ module Stripe
|
|
12
12
|
should "customer cards should be listable" do
|
13
13
|
c = customer
|
14
14
|
@mock.expects(:get).once.returns(make_response(make_customer_card_array(customer.id)))
|
15
|
-
cards = c.sources.
|
15
|
+
cards = c.sources.list(:object => "card").data
|
16
16
|
assert cards.kind_of? Array
|
17
17
|
assert cards[0].kind_of? Stripe::Card
|
18
18
|
end
|
@@ -4,7 +4,7 @@ module Stripe
|
|
4
4
|
class CustomerTest < Test::Unit::TestCase
|
5
5
|
should "customers should be listable" do
|
6
6
|
@mock.expects(:get).once.returns(make_response(make_customer_array))
|
7
|
-
c = Stripe::Customer.
|
7
|
+
c = Stripe::Customer.list.data
|
8
8
|
assert c.kind_of? Array
|
9
9
|
assert c[0].kind_of? Stripe::Customer
|
10
10
|
end
|
data/test/stripe/dispute_test.rb
CHANGED
@@ -10,7 +10,7 @@ module Stripe
|
|
10
10
|
|
11
11
|
should "disputes should be listable" do
|
12
12
|
@mock.expects(:get).once.returns(make_response(make_dispute_array))
|
13
|
-
d = Stripe::Dispute.
|
13
|
+
d = Stripe::Dispute.list
|
14
14
|
assert d.data.kind_of? Array
|
15
15
|
d.each do |dispute|
|
16
16
|
assert dispute.kind_of?(Stripe::Dispute)
|
@@ -31,7 +31,7 @@ module Stripe
|
|
31
31
|
with("#{Stripe.uploads_base}/v1/files", nil, nil).
|
32
32
|
returns(make_response(make_file_array))
|
33
33
|
|
34
|
-
c = Stripe::FileUpload.
|
34
|
+
c = Stripe::FileUpload.list.data
|
35
35
|
assert c.kind_of? Array
|
36
36
|
assert c[0].kind_of? Stripe::FileUpload
|
37
37
|
end
|
@@ -2,6 +2,123 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class ListObjectTest < Test::Unit::TestCase
|
5
|
+
should "provide .empty_list" do
|
6
|
+
list = Stripe::ListObject.empty_list
|
7
|
+
assert list.empty?
|
8
|
+
end
|
9
|
+
|
10
|
+
should "provide #count via enumerable" do
|
11
|
+
list = Stripe::ListObject.construct_from(make_charge_array)
|
12
|
+
assert_equal 3, list.count
|
13
|
+
end
|
14
|
+
|
15
|
+
should "provide #each" do
|
16
|
+
arr = [
|
17
|
+
{ :id => 1 },
|
18
|
+
{ :id => 2 },
|
19
|
+
{ :id => 3 },
|
20
|
+
]
|
21
|
+
expected = Util.convert_to_stripe_object(arr, {})
|
22
|
+
list = Stripe::ListObject.construct_from({ :data => arr })
|
23
|
+
assert_equal expected, list.each.to_a
|
24
|
+
end
|
25
|
+
|
26
|
+
should "provide #auto_paging_each" do
|
27
|
+
arr = [
|
28
|
+
{ :id => 1 },
|
29
|
+
{ :id => 2 },
|
30
|
+
{ :id => 3 },
|
31
|
+
]
|
32
|
+
expected = Util.convert_to_stripe_object(arr, {})
|
33
|
+
|
34
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
|
35
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
36
|
+
returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
37
|
+
|
38
|
+
assert_equal expected, list.auto_paging_each.to_a
|
39
|
+
end
|
40
|
+
|
41
|
+
should "provide #auto_paging_each that responds to a block" do
|
42
|
+
arr = [
|
43
|
+
{ :id => 1 },
|
44
|
+
{ :id => 2 },
|
45
|
+
{ :id => 3 },
|
46
|
+
]
|
47
|
+
expected = Util.convert_to_stripe_object(arr, {})
|
48
|
+
|
49
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
|
50
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
51
|
+
returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
52
|
+
|
53
|
+
actual = []
|
54
|
+
list.auto_paging_each do |obj|
|
55
|
+
actual << obj
|
56
|
+
end
|
57
|
+
|
58
|
+
assert_equal expected, actual
|
59
|
+
end
|
60
|
+
|
61
|
+
should "provide #empty?" do
|
62
|
+
list = Stripe::ListObject.construct_from({ :data => [] })
|
63
|
+
assert list.empty?
|
64
|
+
list = Stripe::ListObject.construct_from({ :data => [{}] })
|
65
|
+
refute list.empty?
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# next_page
|
70
|
+
#
|
71
|
+
|
72
|
+
should "fetch a next page through #next_page" do
|
73
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
|
74
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
75
|
+
returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
|
76
|
+
next_list = list.next_page
|
77
|
+
refute next_list.empty?
|
78
|
+
end
|
79
|
+
|
80
|
+
should "fetch a next page through #next_page and respect limit" do
|
81
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => true })
|
82
|
+
list.limit = 3
|
83
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?limit=3&starting_after=1", nil, nil).
|
84
|
+
returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
|
85
|
+
next_list = list.next_page
|
86
|
+
assert_equal 3, next_list.limit
|
87
|
+
end
|
88
|
+
|
89
|
+
should "fetch an empty page through #next_page" do
|
90
|
+
list = TestListObject.construct_from({ :data => [{ :id => 1 }], :has_more => false })
|
91
|
+
next_list = list.next_page
|
92
|
+
assert_equal Stripe::ListObject.empty_list, next_list
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# previous_page
|
97
|
+
#
|
98
|
+
|
99
|
+
should "fetch a next page through #previous_page" do
|
100
|
+
list = TestListObject.construct_from({ :data => [{ :id => 2 }] })
|
101
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?ending_before=2", nil, nil).
|
102
|
+
returns(make_response({ :data => [{ :id => 1 }] }))
|
103
|
+
next_list = list.previous_page
|
104
|
+
refute next_list.empty?
|
105
|
+
end
|
106
|
+
|
107
|
+
should "fetch a next page through #previous_page and respect limit" do
|
108
|
+
list = TestListObject.construct_from({ :data => [{ :id => 2 }] })
|
109
|
+
list.limit = 3
|
110
|
+
@mock.expects(:get).once.with("#{Stripe.api_base}/things?ending_before=2&limit=3", nil, nil).
|
111
|
+
returns(make_response({ :data => [{ :id => 1 }] }))
|
112
|
+
next_list = list.previous_page
|
113
|
+
assert_equal 3, next_list.limit
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# backward compatibility
|
118
|
+
#
|
119
|
+
|
120
|
+
# note that the name #all is deprecated, as is using it fetch the next page
|
121
|
+
# in a list
|
5
122
|
should "be able to retrieve full lists given a listobject" do
|
6
123
|
@mock.expects(:get).twice.returns(make_response(make_charge_array))
|
7
124
|
c = Stripe::Charge.all
|
@@ -12,19 +129,12 @@ module Stripe
|
|
12
129
|
assert_equal('/v1/charges', all.url)
|
13
130
|
assert all.data.kind_of?(Array)
|
14
131
|
end
|
132
|
+
end
|
133
|
+
end
|
15
134
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
refute object.empty?
|
21
|
-
end
|
22
|
-
|
23
|
-
should "provide enumerable functionality" do
|
24
|
-
@mock.expects(:get).once.returns(make_response(make_charge_array))
|
25
|
-
c = Stripe::Charge.all
|
26
|
-
assert c.kind_of?(Stripe::ListObject)
|
27
|
-
assert_equal 3, c.count
|
28
|
-
end
|
135
|
+
# A helper class with a URL that allows us to try out pagination.
|
136
|
+
class TestListObject < Stripe::ListObject
|
137
|
+
def url
|
138
|
+
"/things"
|
29
139
|
end
|
30
140
|
end
|
data/test/stripe/order_test.rb
CHANGED
@@ -4,7 +4,7 @@ module Stripe
|
|
4
4
|
class OrderTest < Test::Unit::TestCase
|
5
5
|
should "orders should be listable" do
|
6
6
|
@mock.expects(:get).once.returns(make_response(make_order_array))
|
7
|
-
orders = Stripe::Order.
|
7
|
+
orders = Stripe::Order.list
|
8
8
|
assert orders.data.kind_of?(Array)
|
9
9
|
orders.each do |order|
|
10
10
|
assert order.kind_of?(Stripe::Order)
|
data/test/stripe/product_test.rb
CHANGED
@@ -4,7 +4,7 @@ module Stripe
|
|
4
4
|
class ProductTest < Test::Unit::TestCase
|
5
5
|
should "products should be listable" do
|
6
6
|
@mock.expects(:get).once.returns(make_response(make_product_array))
|
7
|
-
products = Stripe::Product.
|
7
|
+
products = Stripe::Product.list
|
8
8
|
assert products.data.kind_of?(Array)
|
9
9
|
products.each do |product|
|
10
10
|
assert product.kind_of?(Stripe::Product)
|
@@ -12,7 +12,7 @@ module Stripe
|
|
12
12
|
should "recipient cards should be listable" do
|
13
13
|
c = recipient
|
14
14
|
@mock.expects(:get).once.returns(make_response(make_recipient_card_array(recipient.id)))
|
15
|
-
cards = c.cards.
|
15
|
+
cards = c.cards.list.data
|
16
16
|
assert cards.kind_of? Array
|
17
17
|
assert cards[0].kind_of? Stripe::Card
|
18
18
|
end
|
data/test/stripe/refund_test.rb
CHANGED
data/test/stripe/sku_test.rb
CHANGED
@@ -5,7 +5,7 @@ module Stripe
|
|
5
5
|
should "SKUs should be listable" do
|
6
6
|
@mock.expects(:get).once.
|
7
7
|
returns(make_response(make_sku_array("test_product")))
|
8
|
-
skus = Stripe::SKU.
|
8
|
+
skus = Stripe::SKU.list
|
9
9
|
assert skus.data.kind_of? Array
|
10
10
|
skus.each do |sku|
|
11
11
|
assert sku.kind_of?(Stripe::SKU)
|
@@ -2,7 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
module Stripe
|
4
4
|
class StripeObjectTest < Test::Unit::TestCase
|
5
|
-
should "implement
|
5
|
+
should "implement #==" do
|
6
|
+
obj1 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "bar" })
|
7
|
+
obj2 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "bar" })
|
8
|
+
obj3 = Stripe::StripeObject.construct_from({ :id => 1, :foo => "rab" })
|
9
|
+
|
10
|
+
assert obj1 == obj2
|
11
|
+
refute obj1 == obj3
|
12
|
+
end
|
13
|
+
|
14
|
+
should "implement #respond_to" do
|
6
15
|
obj = Stripe::StripeObject.construct_from({ :id => 1, :foo => 'bar' })
|
7
16
|
assert obj.respond_to?(:id)
|
8
17
|
assert obj.respond_to?(:foo)
|