stripe 1.28.1 → 1.29.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +2 -2
  3. data/VERSION +1 -1
  4. data/lib/stripe/account.rb +2 -2
  5. data/lib/stripe/api_operations/create.rb +3 -9
  6. data/lib/stripe/api_operations/list.rb +17 -9
  7. data/lib/stripe/application_fee.rb +1 -1
  8. data/lib/stripe/application_fee_refund.rb +1 -1
  9. data/lib/stripe/balance_transaction.rb +1 -1
  10. data/lib/stripe/bank_account.rb +1 -1
  11. data/lib/stripe/bitcoin_receiver.rb +2 -2
  12. data/lib/stripe/bitcoin_transaction.rb +1 -1
  13. data/lib/stripe/card.rb +1 -1
  14. data/lib/stripe/charge.rb +2 -2
  15. data/lib/stripe/coupon.rb +2 -2
  16. data/lib/stripe/customer.rb +2 -2
  17. data/lib/stripe/dispute.rb +2 -2
  18. data/lib/stripe/event.rb +1 -1
  19. data/lib/stripe/file_upload.rb +2 -2
  20. data/lib/stripe/invoice.rb +2 -2
  21. data/lib/stripe/invoice_item.rb +2 -2
  22. data/lib/stripe/list_object.rb +64 -3
  23. data/lib/stripe/order.rb +2 -2
  24. data/lib/stripe/plan.rb +2 -2
  25. data/lib/stripe/product.rb +2 -2
  26. data/lib/stripe/recipient.rb +2 -2
  27. data/lib/stripe/refund.rb +2 -2
  28. data/lib/stripe/reversal.rb +1 -1
  29. data/lib/stripe/sku.rb +2 -2
  30. data/lib/stripe/stripe_object.rb +7 -0
  31. data/lib/stripe/token.rb +1 -1
  32. data/lib/stripe/transfer.rb +2 -2
  33. data/lib/stripe/version.rb +1 -1
  34. data/test/stripe/api_resource_test.rb +10 -9
  35. data/test/stripe/application_fee_test.rb +1 -1
  36. data/test/stripe/bitcoin_receiver_test.rb +2 -2
  37. data/test/stripe/bitcoin_transaction_test.rb +1 -1
  38. data/test/stripe/charge_test.rb +1 -1
  39. data/test/stripe/customer_card_test.rb +1 -1
  40. data/test/stripe/customer_test.rb +1 -1
  41. data/test/stripe/dispute_test.rb +1 -1
  42. data/test/stripe/file_upload_test.rb +1 -1
  43. data/test/stripe/list_object_test.rb +123 -13
  44. data/test/stripe/order_test.rb +1 -1
  45. data/test/stripe/product_test.rb +1 -1
  46. data/test/stripe/recipient_card_test.rb +1 -1
  47. data/test/stripe/refund_test.rb +1 -1
  48. data/test/stripe/sku_test.rb +1 -1
  49. data/test/stripe/stripe_object_test.rb +10 -1
  50. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 083eab18104ef39dd85e2646f9a0a8da259d159d
4
- data.tar.gz: 9f1695c23d275adcfef769c577b81865c1739e84
3
+ metadata.gz: cad15842f509a5f748f5e644a3932ea8b45ae480
4
+ data.tar.gz: defecc310910f380f32d973ec2c1032b08e85a51
5
5
  SHA512:
6
- metadata.gz: 1ab0cdfe76978d120847fc213d4cfa5cb0887f5b1d7486471528630a8ff643828962d8620f42700e2ce7f355983ab252a932353bdaa2faf94f9524ac8c22eda9
7
- data.tar.gz: d27dabf527fe69329dbf827d9bcab1deb3a4e3cec1fb00e59ffffcc68d414ded73bfa5f2eb8696288d6021cb85bbe537bf27cfb232e09b59a61627b56ca11fca
6
+ metadata.gz: 0776d66e4e13d87f2b5478e24cd00e4e00c4990bf7cf2f0e652e6f052cb17c7e90c0e4514f8ab7daa485b33751acf79fa11d6a1d5908d5536f2a63d7fdf2fc3a
7
+ data.tar.gz: 0e1e2e41df59fb7ec775240b279a4bde6087883d37024b6f01794ccdc0ab91aaa100b39c35b06e5f8242f246f9e8d3ff8dd9795ed12ceab9a69404b2dbaca2ea
@@ -1,6 +1,6 @@
1
- === 1.28.1 2015-10-05
1
+ === 1.29.0 2015-10-05
2
2
 
3
- * DESCRIBE CHANGES HERE (try to use the same style, tense, etc. as the other entries)
3
+ * Add pagination helpers `#auto_paging_each`, `#previous_page`, and `#next_page`
4
4
 
5
5
  === 1.28.1 2015-10-05
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.28.1
1
+ 1.29.0
@@ -1,8 +1,8 @@
1
1
  module Stripe
2
2
  class Account < APIResource
3
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::List
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
- module ClassMethods
5
- def create(params={}, opts={})
6
- response, opts = request(:post, url, params, opts)
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
- module ClassMethods
5
- def all(filters={}, opts={})
6
- opts = Util.normalize_opts(opts)
7
- response, opts = request(:get, url, filters, opts)
8
- Util.convert_to_stripe_object(response, opts)
9
- end
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
- def self.included(base)
13
- base.extend(ClassMethods)
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
@@ -1,6 +1,6 @@
1
1
  module Stripe
2
2
  class ApplicationFee < APIResource
3
- include Stripe::APIOperations::List
3
+ extend Stripe::APIOperations::List
4
4
 
5
5
  def self.url
6
6
  '/v1/application_fees'
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class ApplicationFeeRefund < APIResource
3
3
  include Stripe::APIOperations::Update
4
- include Stripe::APIOperations::List
4
+ extend Stripe::APIOperations::List
5
5
 
6
6
  def url
7
7
  "#{ApplicationFee.url}/#{CGI.escape(fee)}/refunds/#{CGI.escape(id)}"
@@ -1,6 +1,6 @@
1
1
  module Stripe
2
2
  class BalanceTransaction < APIResource
3
- include Stripe::APIOperations::List
3
+ extend Stripe::APIOperations::List
4
4
 
5
5
  def self.url
6
6
  '/v1/balance/history'
@@ -2,7 +2,7 @@ module Stripe
2
2
  class BankAccount < APIResource
3
3
  include Stripe::APIOperations::Update
4
4
  include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::List
5
+ extend Stripe::APIOperations::List
6
6
 
7
7
  def url
8
8
  if respond_to?(:customer)
@@ -1,9 +1,9 @@
1
1
  module Stripe
2
2
  class BitcoinReceiver < APIResource
3
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Update
5
5
  include Stripe::APIOperations::Delete
6
- include Stripe::APIOperations::List
6
+ extend Stripe::APIOperations::List
7
7
 
8
8
  def self.url
9
9
  "/v1/bitcoin/receivers"
@@ -1,6 +1,6 @@
1
1
  module Stripe
2
2
  class BitcoinTransaction < APIResource
3
- include Stripe::APIOperations::List
3
+ extend Stripe::APIOperations::List
4
4
 
5
5
  def self.url
6
6
  "/v1/bitcoin/transactions"
@@ -2,7 +2,7 @@ module Stripe
2
2
  class Card < APIResource
3
3
  include Stripe::APIOperations::Update
4
4
  include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::List
5
+ extend Stripe::APIOperations::List
6
6
 
7
7
  def url
8
8
  if respond_to?(:recipient)
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Charge < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::List
4
+ extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Update
6
6
 
7
7
  def refund(params={}, opts={})
@@ -1,8 +1,8 @@
1
1
  module Stripe
2
2
  class Coupon < APIResource
3
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Update
5
5
  include Stripe::APIOperations::Delete
6
- include Stripe::APIOperations::List
6
+ extend Stripe::APIOperations::List
7
7
  end
8
8
  end
@@ -1,9 +1,9 @@
1
1
  module Stripe
2
2
  class Customer < APIResource
3
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
5
  include Stripe::APIOperations::Update
6
- include Stripe::APIOperations::List
6
+ extend Stripe::APIOperations::List
7
7
 
8
8
  def add_invoice_item(params, opts={})
9
9
  opts = @opts.merge(Util.normalize_opts(opts))
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Dispute < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::List
4
+ extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Update
6
6
 
7
7
  def close(params={}, opts={})
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  class Event < APIResource
3
- include Stripe::APIOperations::List
3
+ extend Stripe::APIOperations::List
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class FileUpload < APIResource
3
- include Stripe::APIOperations::Create
4
- include Stripe::APIOperations::List
3
+ extend Stripe::APIOperations::Create
4
+ extend Stripe::APIOperations::List
5
5
 
6
6
  def self.url
7
7
  "/v1/files"
@@ -1,8 +1,8 @@
1
1
  module Stripe
2
2
  class Invoice < APIResource
3
- include Stripe::APIOperations::List
3
+ extend Stripe::APIOperations::List
4
4
  include Stripe::APIOperations::Update
5
- include Stripe::APIOperations::Create
5
+ extend Stripe::APIOperations::Create
6
6
 
7
7
  def self.upcoming(params, opts={})
8
8
  response, opts = request(:get, upcoming_url, params, opts)
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class InvoiceItem < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
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
@@ -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
- def all(params={}, opts={})
36
- response, opts = request(:get, url, params, opts)
37
- Util.convert_to_stripe_object(response, opts)
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
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Order < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::List
4
+ extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Update
6
6
 
7
7
  def pay(params, opts={})
@@ -1,8 +1,8 @@
1
1
  module Stripe
2
2
  class Plan < APIResource
3
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
- include Stripe::APIOperations::List
5
+ extend Stripe::APIOperations::List
6
6
  include Stripe::APIOperations::Update
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Product < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
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
@@ -1,9 +1,9 @@
1
1
  module Stripe
2
2
  class Recipient < APIResource
3
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::Create
4
4
  include Stripe::APIOperations::Delete
5
5
  include Stripe::APIOperations::Update
6
- include Stripe::APIOperations::List
6
+ extend Stripe::APIOperations::List
7
7
 
8
8
  def transfers
9
9
  Transfer.all({ :recipient => id }, @api_key)
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Refund < APIResource
3
- include Stripe::APIOperations::Create
4
- include Stripe::APIOperations::List
3
+ extend Stripe::APIOperations::Create
4
+ extend Stripe::APIOperations::List
5
5
  include Stripe::APIOperations::Update
6
6
  end
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Reversal < APIResource
3
3
  include Stripe::APIOperations::Update
4
- include Stripe::APIOperations::List
4
+ extend Stripe::APIOperations::List
5
5
 
6
6
  def url
7
7
  "#{Transfer.url}/#{CGI.escape(transfer)}/reversals/#{CGI.escape(id)}"
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class SKU < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::List
4
+ extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Update
6
6
 
7
7
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  class Token < APIResource
3
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::Create
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  module Stripe
2
2
  class Transfer < APIResource
3
- include Stripe::APIOperations::List
4
- include Stripe::APIOperations::Create
3
+ extend Stripe::APIOperations::List
4
+ extend Stripe::APIOperations::Create
5
5
  include Stripe::APIOperations::Update
6
6
 
7
7
  def cancel
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.28.1'
2
+ VERSION = '1.29.0'
3
3
  end
@@ -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.all({}, nil)
42
+ Stripe::Customer.list({}, nil)
43
43
  end
44
44
  assert_raises TypeError do
45
- Stripe::Customer.all({}, { :api_key => nil })
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.all(:customer => 'test customer').data
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.all(:customer => 'test_customer')
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.all(:paid => true)
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.all(:count => nil, :offset => 5, :sad => false)
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).returns(make_response([make_charge]))
339
- Stripe::Charge.all(params)
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.all.data
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.all
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.all
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.all
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.all
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|
@@ -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.all
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.all(:object => "card").data
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.all.data
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
@@ -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.all
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.all.data
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
- should "provide #empty?" do
17
- object = Stripe::ListObject.construct_from({ :data => [] })
18
- assert object.empty?
19
- object = Stripe::ListObject.construct_from({ :data => [{}] })
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
@@ -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.all
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)
@@ -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.all
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.all.data
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
@@ -7,7 +7,7 @@ module Stripe
7
7
  with("#{Stripe.api_base}/v1/refunds", nil, nil).
8
8
  once.returns(make_response(make_refund_array))
9
9
 
10
- refunds = Stripe::Refund.all
10
+ refunds = Stripe::Refund.list
11
11
 
12
12
  assert refunds.first.kind_of?(Stripe::Refund)
13
13
  end
@@ -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.all
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 #respond_to correctly" do
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.28.1
4
+ version: 1.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Boucher