stripe 1.30.0 → 1.30.1

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: 061c68a3e8fbf7b2adfa0a93489b1b124b08cb37
4
- data.tar.gz: 4fda58089700ad1f39ab8a084b09982679b4e9a1
3
+ metadata.gz: a744255415d993917d419962d5f1420b8daed37d
4
+ data.tar.gz: 1c9085d745949c729e3c9caa3e986d16c6373eda
5
5
  SHA512:
6
- metadata.gz: b2f3f7dff2c30038b9608f825f542061eccb6461bb1c0a9bebfb754ac5d7031c00e4df16e0a753edf92c5934435dcd1bfe191dfd2bdd5744c67ffdc268f3e16c
7
- data.tar.gz: b68dfc54c11b18e6081a5794c89d717812607f334c60744f7b0cf0ba2a65a337f8f0465c4e092471cb3709e30df8fc62267550b73d255857914b40c1d9f32c47
6
+ metadata.gz: 02b09d3707b1861f069cbd46124fe5c03aa86a44f47973a01315156056765404ddc54423b6479141f56cb1cd9ef28679dcfed3147d98e65d11835eb5622a275f
7
+ data.tar.gz: 1f7d8ccf6eac75aea02b7935587f8448d363601f92f1f5245ebb4639e6f9a6c9f71f0201c88a14d86a6e172dab79351088bd103ae47230718b18a47340dc9c17
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 1.30.1 2015-10-10
2
+
3
+ * Fix bug that prevent lists of hashes from being URI-encoded properly
4
+ * Fix bug where filter conditions were not making it fast the first instantiated `ListObject`
5
+
1
6
  === 1.30.0 2015-10-09
2
7
 
3
8
  * Add `StripeObject#deleted?` for a reliable way to check whether an object is alive
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.30.0
1
+ 1.30.1
@@ -8,9 +8,13 @@ module Stripe
8
8
  response, opts = request(:get, url, filters, opts)
9
9
  obj = ListObject.construct_from(response, opts)
10
10
 
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]
11
+ # set filters so that we can fetch the same limit, expansions, and
12
+ # predicates when accessing the next and previous pages
13
+ #
14
+ # just for general cleanliness, remove any paging options
15
+ obj.filters = filters.dup
16
+ obj.filters.delete(:ending_before)
17
+ obj.filters.delete(:starting_after)
14
18
 
15
19
  obj
16
20
  end
@@ -4,10 +4,10 @@ module Stripe
4
4
  include Stripe::APIOperations::List
5
5
  include Stripe::APIOperations::Request
6
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
7
+ # This accessor allows a `ListObject` to inherit various filters that were
8
+ # given to a predecessor. This allows for things like consistent limits,
9
+ # expansions, and predicates as a user pages through resources.
10
+ attr_accessor :filters
11
11
 
12
12
  # An empty list object. This is returned from +next+ when we know that
13
13
  # there isn't a next page in order to replicate the behavior of the API
@@ -16,6 +16,11 @@ module Stripe
16
16
  ListObject.construct_from({ :data => [] }, opts)
17
17
  end
18
18
 
19
+ def initialize(*args)
20
+ super
21
+ self.filters = {}
22
+ end
23
+
19
24
  def [](k)
20
25
  case k
21
26
  when String, Symbol
@@ -75,10 +80,9 @@ module Stripe
75
80
  return self.class.empty_list(opts) if !has_more
76
81
  last_id = data.last.id
77
82
 
78
- params = {
79
- :limit => limit, # may be nil
83
+ params = filters.merge({
80
84
  :starting_after => last_id,
81
- }.merge(params)
85
+ }).merge(params)
82
86
 
83
87
  list(params, opts)
84
88
  end
@@ -90,10 +94,9 @@ module Stripe
90
94
  def previous_page(params={}, opts={})
91
95
  first_id = data.first.id
92
96
 
93
- params = {
97
+ params = filters.merge({
94
98
  :ending_before => first_id,
95
- :limit => limit, # may be nil
96
- }.merge(params)
99
+ }).merge(params)
97
100
 
98
101
  list(params, opts)
99
102
  end
data/lib/stripe/util.rb CHANGED
@@ -127,11 +127,7 @@ module Stripe
127
127
  end
128
128
  end
129
129
 
130
- # The #sort_by call here is mostly so that we can get some stability in
131
- # our 1.8.7 test suite where Hash key order is not preserved.
132
- #
133
- # https://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/
134
- result.sort_by { |(k, _)| k }
130
+ result
135
131
  end
136
132
 
137
133
  def self.flatten_params_array(value, calculated_key)
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.30.0'
2
+ VERSION = '1.30.1'
3
3
  end
@@ -68,7 +68,7 @@ module Stripe
68
68
 
69
69
  @mock.expects(:post).
70
70
  once.
71
- with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'legal_entity[address][line1]=2+Three+Four&legal_entity[first_name]=Bob').
71
+ with('https://api.stripe.com/v1/accounts/acct_foo', nil, 'legal_entity[first_name]=Bob&legal_entity[address][line1]=2+Three+Four').
72
72
  returns(make_response(resp))
73
73
 
74
74
  a = Stripe::Account.retrieve('acct_foo')
@@ -79,11 +79,20 @@ module Stripe
79
79
 
80
80
  should "fetch a next page through #next_page and respect limit" do
81
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 }))
82
+ list.filters = { :expand => ['data.source'], :limit => 3 }
83
+ @mock.expects(:get).with do |url, _, _|
84
+ # apparently URI.parse in 1.8.7 doesn't support query parameters ...
85
+ url, query = url.split("?")
86
+ u = URI.parse(url)
87
+ params = CGI.parse(query)
88
+ u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
89
+ "expand[]" => ["data.source"],
90
+ "limit" => ["3"],
91
+ "starting_after" => ["1"],
92
+ }
93
+ end.returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
85
94
  next_list = list.next_page
86
- assert_equal 3, next_list.limit
95
+ assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
87
96
  end
88
97
 
89
98
  should "fetch an empty page through #next_page" do
@@ -106,11 +115,20 @@ module Stripe
106
115
 
107
116
  should "fetch a next page through #previous_page and respect limit" do
108
117
  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 }] }))
118
+ list.filters = { :expand => ['data.source'], :limit => 3 }
119
+ @mock.expects(:get).with do |url, _, _|
120
+ # apparently URI.parse in 1.8.7 doesn't support query parameters ...
121
+ url, query = url.split("?")
122
+ u = URI.parse(url)
123
+ params = CGI.parse(query)
124
+ u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
125
+ "ending_before" => ["2"],
126
+ "expand[]" => ["data.source"],
127
+ "limit" => ["3"],
128
+ }
129
+ end.returns(make_response({ :data => [{ :id => 1 }] }))
112
130
  next_list = list.previous_page
113
- assert_equal 3, next_list.limit
131
+ assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
114
132
  end
115
133
 
116
134
  #
@@ -60,7 +60,7 @@ module Stripe
60
60
 
61
61
  if is_greater_than_ruby_1_9?
62
62
  check_metadata({:metadata => {:initial => 'true'}},
63
- 'metadata[initial]=&metadata[uuid]=6735',
63
+ 'metadata[uuid]=6735&metadata[initial]=',
64
64
  update_actions)
65
65
  end
66
66
  end
@@ -3,13 +3,14 @@ require File.expand_path('../../test_helper', __FILE__)
3
3
  module Stripe
4
4
  class UtilTest < Test::Unit::TestCase
5
5
  should "#encode_parameters should prepare parameters for an HTTP request" do
6
- params = {
7
- :a => 3,
8
- :b => "+foo?",
9
- :c => "bar&baz",
10
- :d => { :a => "a", :b => "b" },
11
- :e => [0, 1],
12
- }
6
+ # use array instead of hash for 1.8.7 ordering
7
+ params = [
8
+ [:a, 3],
9
+ [:b, "+foo?"],
10
+ [:c, "bar&baz"],
11
+ [:d, { :a => "a", :b => "b" }],
12
+ [:e, [0, 1]],
13
+ ]
13
14
  assert_equal(
14
15
  "a=3&b=%2Bfoo%3F&c=bar%26baz&d[a]=a&d[b]=b&e[]=0&e[]=1",
15
16
  Stripe::Util.encode_parameters(params)
@@ -25,21 +26,33 @@ module Stripe
25
26
  end
26
27
 
27
28
  should "#flatten_params should encode parameters according to Rails convention" do
28
- params = {
29
- :a => 3,
30
- :b => "foo?",
31
- :c => "bar&baz",
32
- :d => { :a => "a", :b => "b" },
33
- :e => [0, 1],
34
- }
29
+ params = [
30
+ [:a, 3],
31
+ [:b, "foo?"],
32
+ [:c, "bar&baz"],
33
+ [:d, { :a => "a", :b => "b" }],
34
+ [:e, [0, 1]],
35
+ [:f, [
36
+ { :foo => "1", :bar => "2" },
37
+ { :foo => "3", :baz => "4" },
38
+ ]],
39
+ ]
35
40
  assert_equal([
36
- ["a", 3],
37
- ["b", "foo?"],
38
- ["c", "bar&baz"],
39
- ["d[a]", "a"],
40
- ["d[b]", "b"],
41
- ["e[]", 0],
42
- ["e[]", 1],
41
+ ["a", 3],
42
+ ["b", "foo?"],
43
+ ["c", "bar&baz"],
44
+ ["d[a]", "a"],
45
+ ["d[b]", "b"],
46
+ ["e[]", 0],
47
+ ["e[]", 1],
48
+
49
+ # *The key here is the order*. In order to be properly interpreted as
50
+ # an array of hashes on the server, everything from a single hash must
51
+ # come in at once. A duplicate key in an array triggers a new element.
52
+ ["f[][foo]", "1"],
53
+ ["f[][bar]", "2"],
54
+ ["f[][foo]", "3"],
55
+ ["f[][baz]", "4"],
43
56
  ], Stripe::Util.flatten_params(params))
44
57
  end
45
58
 
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.30.0
4
+ version: 1.30.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Boucher
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-09 00:00:00.000000000 Z
12
+ date: 2015-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client