stripe 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stripe (1.7.2)
4
+ stripe (1.7.3)
5
5
  multi_json (~> 1.1)
6
6
  rest-client (~> 1.4)
7
7
 
@@ -1,3 +1,12 @@
1
+ === 1.7.3 2012-09-14
2
+
3
+ * Make sure that both keys and values of GET params are
4
+ URL-encoded. NOTE: If you were previously URL-encoding values
5
+ yourself, you may need to adjust your code.
6
+ * URL-encode POST params directly, instead of allowing rest-client to
7
+ do it to work around an unfortunate interaction with the hashery gem
8
+ (github issue #38)
9
+
1
10
  === 1.7.2 2012-08-31
2
11
 
3
12
  * Add support for new pay and update methods for Invoice objects
@@ -5,11 +5,11 @@
5
5
  You don't need this source code unless you want to modify the gem. If
6
6
  you just want to use the Stripe Ruby bindings, you should run:
7
7
 
8
- sudo gem install --source https://code.stripe.com stripe
8
+ gem install --source https://code.stripe.com stripe
9
9
 
10
10
  If you want to build the gem from source:
11
11
 
12
- sudo gem build stripe.gemspec
12
+ gem build stripe.gemspec
13
13
 
14
14
  == Requirements
15
15
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.7.2
1
+ 1.7.3
@@ -116,12 +116,12 @@ module Stripe
116
116
  when :get, :head, :delete
117
117
  # Make params into GET parameters
118
118
  if params && params.count
119
- query_string = Util.flatten_params(params).collect{|p| "#{p[0]}=#{p[1]}"}.join('&')
119
+ query_string = Util.flatten_params(params).collect{|key, value| "#{key}=#{Util.url_encode(value)}"}.join('&')
120
120
  url += "?#{query_string}"
121
121
  end
122
122
  payload = nil
123
123
  else
124
- payload = params
124
+ payload = Util.flatten_params(params).collect{|(key, value)| "#{key}=#{Util.url_encode(value)}"}.join('&')
125
125
  end
126
126
 
127
127
  begin
@@ -135,7 +135,8 @@ module Stripe
135
135
 
136
136
  headers = {
137
137
  :user_agent => "Stripe/v1 RubyBindings/#{Stripe::VERSION}",
138
- :authorization => "Bearer #{api_key}"
138
+ :authorization => "Bearer #{api_key}",
139
+ :content_type => 'application/x-www-form-urlencoded'
139
140
  }.merge(headers)
140
141
  opts = {
141
142
  :method => method,
@@ -67,14 +67,14 @@ module Stripe
67
67
  end
68
68
  end
69
69
 
70
- def self.encode_key(key)
70
+ def self.url_encode(key)
71
71
  URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
72
72
  end
73
73
 
74
74
  def self.flatten_params(params, parent_key=nil)
75
75
  result = []
76
76
  params.each do |key, value|
77
- calculated_key = parent_key ? "#{parent_key}[#{encode_key(key)}]" : encode_key(key)
77
+ calculated_key = parent_key ? "#{parent_key}[#{url_encode(key)}]" : url_encode(key)
78
78
  if value.is_a?(Hash)
79
79
  result += flatten_params(value, calculated_key)
80
80
  elsif value.is_a?(Array)
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.7.2'
2
+ VERSION = '1.7.3'
3
3
  end
@@ -113,6 +113,13 @@ class TestStripeRuby < Test::Unit::TestCase
113
113
  Stripe.api_key=nil
114
114
  end
115
115
 
116
+ should "urlencode values in GET params" do
117
+ response = test_response(test_charge_array)
118
+ @mock.expects(:get).with('https://api.stripe.com/v1/charges?customer=test%20customer', nil, nil).returns(response)
119
+ charges = Stripe::Charge.all(:customer => 'test customer').data
120
+ assert charges.kind_of? Array
121
+ end
122
+
116
123
  should "a 400 should give an InvalidRequestError with http status, body, and JSON body" do
117
124
  response = test_response(test_missing_id_error, 400)
118
125
  @mock.expects(:get).once.raises(RestClient::ExceptionWithResponse.new(response, 404))
@@ -170,7 +177,9 @@ class TestStripeRuby < Test::Unit::TestCase
170
177
  end.returns(test_response({ :count => 1, :data => [test_charge] }))
171
178
  c = Stripe::Charge.all(:count => nil, :offset => 5, :sad => false)
172
179
 
173
- @mock.expects(:post).with('https://api.stripe.com/v1/charges', nil, { :amount => 50, :currency => 'usd', :card => {} }).returns(test_response({ :count => 1, :data => [test_charge] }))
180
+ @mock.expects(:post).with do |url, api_key, params|
181
+ url == 'https://api.stripe.com/v1/charges' && api_key.nil? && CGI.parse(params) == { 'amount' => ['50'], 'currency' => ['usd'] }
182
+ end.returns(test_response({ :count => 1, :data => [test_charge] }))
174
183
  c = Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
175
184
  end
176
185
 
@@ -194,7 +203,9 @@ class TestStripeRuby < Test::Unit::TestCase
194
203
 
195
204
  should "making a POST request with parameters should have a body and no query string" do
196
205
  params = { :amount => 100, :currency => 'usd', :card => 'sc_token' }
197
- @mock.expects(:post).once.with { |url, get, post| get.nil? and post == params }.returns(test_response(test_charge))
206
+ @mock.expects(:post).once.with do |url, get, post|
207
+ get.nil? && CGI.parse(post) == {'amount' => ['100'], 'currency' => ['usd'], 'card' => ['sc_token']}
208
+ end.returns(test_response(test_charge))
198
209
  c = Stripe::Charge.create(params)
199
210
  end
200
211
 
@@ -221,7 +232,9 @@ class TestStripeRuby < Test::Unit::TestCase
221
232
  end
222
233
 
223
234
  should "updating an object should issue a POST request with only the changed properties" do
224
- @mock.expects(:post).with("https://api.stripe.com/v1/customers/c_test_customer", nil, {:mnemonic => 'another_mn'}).once.returns(test_response(test_customer))
235
+ @mock.expects(:post).with do |url, api_key, params|
236
+ url == "https://api.stripe.com/v1/customers/c_test_customer" && api_key.nil? && CGI.parse(params) == {'mnemonic' => ['another_mn']}
237
+ end.once.returns(test_response(test_customer))
225
238
  c = Stripe::Customer.construct_from(test_customer)
226
239
  c.mnemonic = "another_mn"
227
240
  c.save
@@ -314,10 +327,14 @@ class TestStripeRuby < Test::Unit::TestCase
314
327
  end
315
328
 
316
329
  should "execute should return a new, fully executed charge when passed correct parameters" do
317
- @mock.expects(:post).with('https://api.stripe.com/v1/charges', nil, {
318
- :currency => 'usd', :amount => 100,
319
- :card => {:exp_year => 2012, :number => '4242424242424242', :exp_month => 11}
320
- }).once.returns(test_response(test_charge))
330
+ @mock.expects(:post).with do |url, api_key, params|
331
+ url == 'https://api.stripe.com/v1/charges' && api_key.nil? && CGI.parse(params) == {
332
+ 'currency' => ['usd'], 'amount' => ['100'],
333
+ 'card[exp_year]' => ['2012'],
334
+ 'card[number]' => ['4242424242424242'],
335
+ 'card[exp_month]' => ['11']
336
+ }
337
+ end.once.returns(test_response(test_charge))
321
338
 
322
339
  c = Stripe::Charge.create({
323
340
  :amount => 100,
@@ -375,7 +392,9 @@ class TestStripeRuby < Test::Unit::TestCase
375
392
  @mock.expects(:get).once.returns(test_response(test_customer))
376
393
  c = Stripe::Customer.retrieve("test_customer")
377
394
 
378
- @mock.expects(:post).once.with("https://api.stripe.com/v1/customers/c_test_customer/subscription", nil, {:plan => 'silver'}).returns(test_response(test_subscription('silver')))
395
+ @mock.expects(:post).once.with do |url, api_key, params|
396
+ url == "https://api.stripe.com/v1/customers/c_test_customer/subscription" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
397
+ end.returns(test_response(test_subscription('silver')))
379
398
  s = c.update_subscription({:plan => 'silver'})
380
399
 
381
400
  assert_equal 'subscription', s.object
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
- - 2
10
- version: 1.7.2
9
+ - 3
10
+ version: 1.7.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ross Boucher
@@ -16,12 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-08-31 00:00:00 Z
19
+ date: 2012-09-15 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- type: :runtime
23
- name: rest-client
24
22
  prerelease: false
23
+ name: rest-client
25
24
  version_requirements: &id001 !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
@@ -33,10 +32,10 @@ dependencies:
33
32
  - 4
34
33
  version: "1.4"
35
34
  requirement: *id001
36
- - !ruby/object:Gem::Dependency
37
35
  type: :runtime
38
- name: multi_json
36
+ - !ruby/object:Gem::Dependency
39
37
  prerelease: false
38
+ name: multi_json
40
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
@@ -48,10 +47,10 @@ dependencies:
48
47
  - 1
49
48
  version: "1.1"
50
49
  requirement: *id002
50
+ type: :runtime
51
51
  - !ruby/object:Gem::Dependency
52
- type: :development
53
- name: mocha
54
52
  prerelease: false
53
+ name: mocha
55
54
  version_requirements: &id003 !ruby/object:Gem::Requirement
56
55
  none: false
57
56
  requirements:
@@ -62,10 +61,10 @@ dependencies:
62
61
  - 0
63
62
  version: "0"
64
63
  requirement: *id003
65
- - !ruby/object:Gem::Dependency
66
64
  type: :development
67
- name: shoulda
65
+ - !ruby/object:Gem::Dependency
68
66
  prerelease: false
67
+ name: shoulda
69
68
  version_requirements: &id004 !ruby/object:Gem::Requirement
70
69
  none: false
71
70
  requirements:
@@ -76,10 +75,10 @@ dependencies:
76
75
  - 0
77
76
  version: "0"
78
77
  requirement: *id004
79
- - !ruby/object:Gem::Dependency
80
78
  type: :development
81
- name: test-unit
79
+ - !ruby/object:Gem::Dependency
82
80
  prerelease: false
81
+ name: test-unit
83
82
  version_requirements: &id005 !ruby/object:Gem::Requirement
84
83
  none: false
85
84
  requirements:
@@ -90,10 +89,10 @@ dependencies:
90
89
  - 0
91
90
  version: "0"
92
91
  requirement: *id005
93
- - !ruby/object:Gem::Dependency
94
92
  type: :development
95
- name: rake
93
+ - !ruby/object:Gem::Dependency
96
94
  prerelease: false
95
+ name: rake
97
96
  version_requirements: &id006 !ruby/object:Gem::Requirement
98
97
  none: false
99
98
  requirements:
@@ -104,6 +103,7 @@ dependencies:
104
103
  - 0
105
104
  version: "0"
106
105
  requirement: *id006
106
+ type: :development
107
107
  description: Stripe is the easiest way to accept payments online. See https://stripe.com for details.
108
108
  email:
109
109
  - boucher@stripe.com
@@ -193,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  requirements: []
194
194
 
195
195
  rubyforge_project:
196
- rubygems_version: 1.8.21
196
+ rubygems_version: 1.8.24
197
197
  signing_key:
198
198
  specification_version: 3
199
199
  summary: Ruby bindings for the Stripe API