stripe 1.8.4 → 1.8.5
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.
- data/History.txt +8 -1
- data/VERSION +1 -1
- data/lib/stripe.rb +1 -1
- data/lib/stripe/api_operations/update.rb +3 -2
- data/lib/stripe/stripe_object.rb +13 -4
- data/lib/stripe/version.rb +1 -1
- data/stripe.gemspec +0 -2
- data/test/test_stripe.rb +44 -13
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
=== 1.8.
|
1
|
+
=== 1.8.5 2013-08-12
|
2
|
+
|
3
|
+
* Add support for unsetting attributes by setting to nil.
|
4
|
+
Permits unsetting email and description on customers and description on charges.
|
5
|
+
Setting properties to a blank string is now an error.
|
6
|
+
* Attempting to set an object's id is now an error.
|
7
|
+
|
8
|
+
=== 1.8.4 2013-07-11
|
2
9
|
|
3
10
|
* Add support for new cards API (Stripe API version 2013-07-05)
|
4
11
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.8.
|
1
|
+
1.8.5
|
data/lib/stripe.rb
CHANGED
@@ -3,8 +3,9 @@ module Stripe
|
|
3
3
|
module Update
|
4
4
|
def save
|
5
5
|
if @unsaved_values.length > 0
|
6
|
-
values = {}
|
7
|
-
|
6
|
+
values = @unsaved_values.reduce({}) do |h, k|
|
7
|
+
h.update(k => @values[k].nil? ? '' : @values[k])
|
8
|
+
end
|
8
9
|
values.delete(:id)
|
9
10
|
response, api_key = Stripe.request(:post, url, @api_key, values)
|
10
11
|
refresh_from(response, api_key)
|
data/lib/stripe/stripe_object.rb
CHANGED
@@ -26,7 +26,7 @@ module Stripe
|
|
26
26
|
# to have a unified inspect method
|
27
27
|
@unsaved_values = Set.new
|
28
28
|
@transient_values = Set.new
|
29
|
-
|
29
|
+
@values[:id] = id if id
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.construct_from(values, api_key=nil)
|
@@ -125,6 +125,12 @@ module Stripe
|
|
125
125
|
k_eq = :"#{k}="
|
126
126
|
define_method(k) { @values[k] }
|
127
127
|
define_method(k_eq) do |v|
|
128
|
+
if v == ""
|
129
|
+
raise ArgumentError.new(
|
130
|
+
"You cannot set #{k} to an empty string." +
|
131
|
+
"We interpret empty strings as nil in requests." +
|
132
|
+
"You may set #{self}.#{k} = nil to delete the property.")
|
133
|
+
end
|
128
134
|
@values[k] = v
|
129
135
|
@unsaved_values.add(k)
|
130
136
|
end
|
@@ -136,10 +142,13 @@ module Stripe
|
|
136
142
|
# TODO: only allow setting in updateable classes.
|
137
143
|
if name.to_s.end_with?('=')
|
138
144
|
attr = name.to_s[0...-1].to_sym
|
139
|
-
@values[attr] = args[0]
|
140
|
-
@unsaved_values.add(attr)
|
141
145
|
add_accessors([attr])
|
142
|
-
|
146
|
+
begin
|
147
|
+
mth = method(name)
|
148
|
+
rescue NameError
|
149
|
+
raise NoMethodError.new("Cannot set #{attr} on this object. HINT: you can't set: #{@@permanent_attributes.to_a.join(', ')}")
|
150
|
+
end
|
151
|
+
return mth.call(args[0])
|
143
152
|
else
|
144
153
|
return @values[name] if @values.has_key?(name)
|
145
154
|
end
|
data/lib/stripe/version.rb
CHANGED
data/stripe.gemspec
CHANGED
@@ -10,8 +10,6 @@ spec = Gem::Specification.new do |s|
|
|
10
10
|
s.authors = ['Ross Boucher', 'Greg Brockman']
|
11
11
|
s.email = ['boucher@stripe.com', 'gdb@stripe.com']
|
12
12
|
s.homepage = 'https://stripe.com/api'
|
13
|
-
s.executables = 'stripe-console'
|
14
|
-
s.require_paths = %w{lib}
|
15
13
|
|
16
14
|
s.add_dependency('rest-client', '~> 1.4')
|
17
15
|
s.add_dependency('multi_json', '>= 1.0.4', '< 2')
|
data/test/test_stripe.rb
CHANGED
@@ -240,7 +240,9 @@ class TestStripeRuby < Test::Unit::TestCase
|
|
240
240
|
c = Stripe::Charge.all(:count => nil, :offset => 5, :sad => false)
|
241
241
|
|
242
242
|
@mock.expects(:post).with do |url, api_key, params|
|
243
|
-
url == "#{Stripe.api_base}/v1/charges" &&
|
243
|
+
url == "#{Stripe.api_base}/v1/charges" &&
|
244
|
+
api_key.nil? &&
|
245
|
+
CGI.parse(params) == { 'amount' => ['50'], 'currency' => ['usd'] }
|
244
246
|
end.returns(test_response({ :count => 1, :data => [test_charge] }))
|
245
247
|
c = Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
|
246
248
|
end
|
@@ -295,17 +297,17 @@ class TestStripeRuby < Test::Unit::TestCase
|
|
295
297
|
|
296
298
|
should "updating an object should issue a POST request with only the changed properties" do
|
297
299
|
@mock.expects(:post).with do |url, api_key, params|
|
298
|
-
url == "#{Stripe.api_base}/v1/customers/c_test_customer" && api_key.nil? && CGI.parse(params) == {'
|
300
|
+
url == "#{Stripe.api_base}/v1/customers/c_test_customer" && api_key.nil? && CGI.parse(params) == {'description' => ['another_mn']}
|
299
301
|
end.once.returns(test_response(test_customer))
|
300
302
|
c = Stripe::Customer.construct_from(test_customer)
|
301
|
-
c.
|
303
|
+
c.description = "another_mn"
|
302
304
|
c.save
|
303
305
|
end
|
304
306
|
|
305
307
|
should "updating should merge in returned properties" do
|
306
308
|
@mock.expects(:post).once.returns(test_response(test_customer))
|
307
309
|
c = Stripe::Customer.new("c_test_customer")
|
308
|
-
c.
|
310
|
+
c.description = "another_mn"
|
309
311
|
c.save
|
310
312
|
assert_equal false, c.livemode
|
311
313
|
end
|
@@ -394,7 +396,36 @@ class TestStripeRuby < Test::Unit::TestCase
|
|
394
396
|
@mock.expects(:post).once.returns(test_response(test_charge))
|
395
397
|
c = Stripe::Charge.new("test_charge")
|
396
398
|
c.refresh
|
397
|
-
c.
|
399
|
+
c.description = "New charge description"
|
400
|
+
c.save
|
401
|
+
end
|
402
|
+
|
403
|
+
should "charge id should not be changeable" do
|
404
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
405
|
+
c = Stripe::Charge.new("test_charge")
|
406
|
+
c.refresh
|
407
|
+
assert_raises NoMethodError do
|
408
|
+
c.id = "my new id"
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
should "charge descriptions should not be settable to an empty string" do
|
413
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
414
|
+
c = Stripe::Charge.new("test_charge")
|
415
|
+
c.refresh
|
416
|
+
assert_raises ArgumentError do
|
417
|
+
c.description = ""
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
should "charges descriptions should pass nil as an empty string" do
|
422
|
+
@mock.expects(:get).once.returns(test_response(test_charge))
|
423
|
+
@mock.expects(:post).once.with do |url, api_key, params|
|
424
|
+
params == 'description='
|
425
|
+
end.returns(test_response(test_charge))
|
426
|
+
c = Stripe::Charge.new("test_charge")
|
427
|
+
c.refresh
|
428
|
+
c.description = nil
|
398
429
|
c.save
|
399
430
|
end
|
400
431
|
|
@@ -445,13 +476,13 @@ class TestStripeRuby < Test::Unit::TestCase
|
|
445
476
|
end
|
446
477
|
|
447
478
|
should "customers should be updateable" do
|
448
|
-
@mock.expects(:get).once.returns(test_response(test_customer({:
|
449
|
-
@mock.expects(:post).once.returns(test_response(test_customer({:
|
479
|
+
@mock.expects(:get).once.returns(test_response(test_customer({:description => "foo"})))
|
480
|
+
@mock.expects(:post).once.returns(test_response(test_customer({:description => "bar"})))
|
450
481
|
c = Stripe::Customer.new("test_customer").refresh
|
451
|
-
assert_equal c.
|
452
|
-
c.
|
482
|
+
assert_equal c.description, "foo"
|
483
|
+
c.description = "bar"
|
453
484
|
c.save
|
454
|
-
assert_equal c.
|
485
|
+
assert_equal c.description, "bar"
|
455
486
|
end
|
456
487
|
|
457
488
|
should "create should return a new customer" do
|
@@ -496,11 +527,11 @@ class TestStripeRuby < Test::Unit::TestCase
|
|
496
527
|
end
|
497
528
|
|
498
529
|
should "be able to update a customer without refreshing it first" do
|
499
|
-
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/customers/test_customer", nil, '
|
530
|
+
@mock.expects(:post).once.with("#{Stripe.api_base}/v1/customers/test_customer", nil, 'description=bar').returns(test_response(test_customer({:description => "bar"})))
|
500
531
|
c = Stripe::Customer.new("test_customer")
|
501
|
-
c.
|
532
|
+
c.description = "bar"
|
502
533
|
c.save
|
503
|
-
assert_equal c.
|
534
|
+
assert_equal c.description, "bar"
|
504
535
|
end
|
505
536
|
|
506
537
|
end
|
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.8.
|
4
|
+
version: 1.8.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|