stripe 1.7.4 → 1.7.6

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 CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.7.6 2012-10-30
2
+ * Add support for creating invoices.
3
+
4
+ === 1.7.5 2012-10-25
5
+ * Add support for new API lists.
6
+
1
7
  === 1.7.4 2012-10-08
2
8
 
3
9
  * Fix bug introduced in 1.7.3 calling API methods that take no
@@ -56,7 +62,7 @@
56
62
  * A whole bunch of releases between 1.5.0 and 1.6.0, but few changes, mainly the addition of:
57
63
  - plans
58
64
  - coupons
59
- - events
65
+ - events
60
66
  - tokens
61
67
  * 1.6.0 also contains a new inspect/to_string implementation
62
68
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.7.4
1
+ 1.7.6
data/lib/stripe.rb CHANGED
@@ -24,6 +24,7 @@ require 'stripe/json'
24
24
  require 'stripe/stripe_object'
25
25
  require 'stripe/api_resource'
26
26
  require 'stripe/singleton_api_resource'
27
+ require 'stripe/list_object'
27
28
  require 'stripe/account'
28
29
  require 'stripe/customer'
29
30
  require 'stripe/invoice'
@@ -46,7 +47,7 @@ require 'stripe/errors/authentication_error'
46
47
  module Stripe
47
48
  @@ssl_bundle_path = File.join(File.dirname(__FILE__), 'data/ca-certificates.crt')
48
49
  @@api_key = nil
49
- @@api_base = 'https://api.stripe.com/v1'
50
+ @@api_base = 'https://api.stripe.com'
50
51
  @@verify_ssl_certs = true
51
52
 
52
53
  def self.api_url(url='')
@@ -8,7 +8,7 @@ module Stripe
8
8
  if self == APIResource
9
9
  raise NotImplementedError.new('APIResource is an abstract class. You should perform actions on its subclasses (Charge, Customer, etc.)')
10
10
  end
11
- "/#{CGI.escape(class_name.downcase)}s"
11
+ "/v1/#{CGI.escape(class_name.downcase)}s"
12
12
  end
13
13
 
14
14
  def url
@@ -2,6 +2,7 @@ module Stripe
2
2
  class Invoice < APIResource
3
3
  include Stripe::APIOperations::List
4
4
  include Stripe::APIOperations::Update
5
+ include Stripe::APIOperations::Create
5
6
 
6
7
  def self.upcoming(params)
7
8
  response, api_key = Stripe.request(:get, upcoming_url, @api_key, params)
@@ -0,0 +1,14 @@
1
+ module Stripe
2
+ class ListObject < StripeObject
3
+
4
+ def each(&blk)
5
+ self.data.each(&blk)
6
+ end
7
+
8
+ def all(filters={})
9
+ response, api_key = Stripe.request(:get, url, api_key, filters)
10
+ Util.convert_to_stripe_object(response, api_key)
11
+ end
12
+
13
+ end
14
+ end
@@ -1,16 +1,5 @@
1
1
  module Stripe
2
2
  class Transfer < APIResource
3
3
  include Stripe::APIOperations::List
4
-
5
- def transactions(params={})
6
- response, api_key = Stripe.request(:get, transactions_url, @api_key, params)
7
- Util.convert_to_stripe_object(response, api_key)
8
- end
9
-
10
- private
11
-
12
- def transactions_url
13
- url + '/transactions'
14
- end
15
4
  end
16
5
  end
data/lib/stripe/util.rb CHANGED
@@ -24,7 +24,8 @@ module Stripe
24
24
  'plan' => Plan,
25
25
  'coupon' => Coupon,
26
26
  'event' => Event,
27
- 'transfer' => Transfer
27
+ 'transfer' => Transfer,
28
+ 'list' => ListObject
28
29
  }
29
30
  case resp
30
31
  when Array
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.7.4'
2
+ VERSION = '1.7.6'
3
3
  end
data/test/test_helper.rb CHANGED
@@ -56,7 +56,11 @@ def test_customer(params={})
56
56
  end
57
57
 
58
58
  def test_customer_array
59
- {:data => [test_customer, test_customer, test_customer]}
59
+ {
60
+ :data => [test_customer, test_customer, test_customer],
61
+ :object => 'list',
62
+ :url => '/v1/customers'
63
+ }
60
64
  end
61
65
 
62
66
  def test_charge(params={})
@@ -83,7 +87,11 @@ def test_charge(params={})
83
87
  end
84
88
 
85
89
  def test_charge_array
86
- {:data => [test_charge, test_charge, test_charge]}
90
+ {
91
+ :data => [test_charge, test_charge, test_charge],
92
+ :object => 'list',
93
+ :url => '/v1/charges'
94
+ }
87
95
  end
88
96
 
89
97
  def test_card(params={})
data/test/test_stripe.rb CHANGED
@@ -115,7 +115,7 @@ class TestStripeRuby < Test::Unit::TestCase
115
115
 
116
116
  should "urlencode values in GET params" do
117
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)
118
+ @mock.expects(:get).with("#{Stripe.api_base}/v1/charges?customer=test%20customer", nil, nil).returns(response)
119
119
  charges = Stripe::Charge.all(:customer => 'test customer').data
120
120
  assert charges.kind_of? Array
121
121
  end
@@ -172,20 +172,20 @@ class TestStripeRuby < Test::Unit::TestCase
172
172
  @mock.expects(:get).with do |url, api_key, params|
173
173
  uri = URI(url)
174
174
  query = CGI.parse(uri.query)
175
- (url =~ %r{^https://api.stripe.com/v1/charges?} &&
175
+ (url =~ %r{^#{Stripe.api_base}/v1/charges?} &&
176
176
  query.keys.sort == ['offset', 'sad'])
177
177
  end.returns(test_response({ :count => 1, :data => [test_charge] }))
178
178
  c = Stripe::Charge.all(:count => nil, :offset => 5, :sad => false)
179
179
 
180
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'] }
181
+ url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == { 'amount' => ['50'], 'currency' => ['usd'] }
182
182
  end.returns(test_response({ :count => 1, :data => [test_charge] }))
183
183
  c = Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
184
184
  end
185
185
 
186
186
  should "requesting with a unicode ID should result in a request" do
187
187
  response = test_response(test_missing_id_error, 404)
188
- @mock.expects(:get).once.with("https://api.stripe.com/v1/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404))
188
+ @mock.expects(:get).once.with("#{Stripe.api_base}/v1/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404))
189
189
  c = Stripe::Customer.new("☃")
190
190
  assert_raises(Stripe::InvalidRequestError) { c.refresh }
191
191
  end
@@ -197,7 +197,7 @@ class TestStripeRuby < Test::Unit::TestCase
197
197
 
198
198
  should "making a GET request with parameters should have a query string and no body" do
199
199
  params = { :limit => 1 }
200
- @mock.expects(:get).once.with("https://api.stripe.com/v1/charges?limit=1", nil, nil).returns(test_response([test_charge]))
200
+ @mock.expects(:get).once.with("#{Stripe.api_base}/v1/charges?limit=1", nil, nil).returns(test_response([test_charge]))
201
201
  c = Stripe::Charge.all(params)
202
202
  end
203
203
 
@@ -233,7 +233,7 @@ class TestStripeRuby < Test::Unit::TestCase
233
233
 
234
234
  should "updating an object should issue a POST request with only the changed properties" do
235
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']}
236
+ url == "#{Stripe.api_base}/v1/customers/c_test_customer" && api_key.nil? && CGI.parse(params) == {'mnemonic' => ['another_mn']}
237
237
  end.once.returns(test_response(test_customer))
238
238
  c = Stripe::Customer.construct_from(test_customer)
239
239
  c.mnemonic = "another_mn"
@@ -251,7 +251,7 @@ class TestStripeRuby < Test::Unit::TestCase
251
251
  should "deleting should send no props and result in an object that has no props other deleted" do
252
252
  @mock.expects(:get).never
253
253
  @mock.expects(:post).never
254
- @mock.expects(:delete).with("https://api.stripe.com/v1/customers/c_test_customer", nil, nil).once.returns(test_response({ "id" => "test_customer", "deleted" => true }))
254
+ @mock.expects(:delete).with("#{Stripe.api_base}/v1/customers/c_test_customer", nil, nil).once.returns(test_response({ "id" => "test_customer", "deleted" => true }))
255
255
 
256
256
  c = Stripe::Customer.construct_from(test_customer)
257
257
  c.delete
@@ -287,12 +287,28 @@ class TestStripeRuby < Test::Unit::TestCase
287
287
  end
288
288
  end
289
289
 
290
+ context "list tests" do
291
+ should "be able to retrieve full lists given a listobject" do
292
+ @mock.expects(:get).twice.returns(test_response(test_charge_array))
293
+ c = Stripe::Charge.all
294
+ assert c.kind_of?(Stripe::ListObject)
295
+ assert_equal('/v1/charges', c.url)
296
+ all = c.all
297
+ assert all.kind_of?(Stripe::ListObject)
298
+ assert_equal('/v1/charges', all.url)
299
+ assert all.data.kind_of?(Array)
300
+ end
301
+ end
302
+
290
303
  context "charge tests" do
291
304
 
292
305
  should "charges should be listable" do
293
306
  @mock.expects(:get).once.returns(test_response(test_charge_array))
294
- c = Stripe::Charge.all.data
295
- assert c.kind_of? Array
307
+ c = Stripe::Charge.all
308
+ assert c.data.kind_of? Array
309
+ c.each do |charge|
310
+ assert charge.kind_of?(Stripe::Charge)
311
+ end
296
312
  end
297
313
 
298
314
  should "charges should be refundable" do
@@ -328,7 +344,7 @@ class TestStripeRuby < Test::Unit::TestCase
328
344
 
329
345
  should "execute should return a new, fully executed charge when passed correct parameters" do
330
346
  @mock.expects(:post).with do |url, api_key, params|
331
- url == 'https://api.stripe.com/v1/charges' && api_key.nil? && CGI.parse(params) == {
347
+ url == "#{Stripe.api_base}/v1/charges" && api_key.nil? && CGI.parse(params) == {
332
348
  'currency' => ['usd'], 'amount' => ['100'],
333
349
  'card[exp_year]' => ['2012'],
334
350
  'card[number]' => ['4242424242424242'],
@@ -393,7 +409,7 @@ class TestStripeRuby < Test::Unit::TestCase
393
409
  c = Stripe::Customer.retrieve("test_customer")
394
410
 
395
411
  @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']}
412
+ url == "#{Stripe.api_base}/v1/customers/c_test_customer/subscription" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
397
413
  end.returns(test_response(test_subscription('silver')))
398
414
  s = c.update_subscription({:plan => 'silver'})
399
415
 
@@ -407,10 +423,10 @@ class TestStripeRuby < Test::Unit::TestCase
407
423
 
408
424
  # Not an accurate response, but whatever
409
425
 
410
- @mock.expects(:delete).once.with("https://api.stripe.com/v1/customers/c_test_customer/subscription?at_period_end=true", nil, nil).returns(test_response(test_subscription('silver')))
426
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription?at_period_end=true", nil, nil).returns(test_response(test_subscription('silver')))
411
427
  s = c.cancel_subscription({:at_period_end => 'true'})
412
428
 
413
- @mock.expects(:delete).once.with("https://api.stripe.com/v1/customers/c_test_customer/subscription", nil, nil).returns(test_response(test_subscription('silver')))
429
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription", nil, nil).returns(test_response(test_subscription('silver')))
414
430
  s = c.cancel_subscription
415
431
  end
416
432
 
@@ -418,7 +434,7 @@ class TestStripeRuby < Test::Unit::TestCase
418
434
  @mock.expects(:get).once.returns(test_response(test_customer))
419
435
  c = Stripe::Customer.retrieve("test_customer")
420
436
 
421
- @mock.expects(:delete).once.with("https://api.stripe.com/v1/customers/c_test_customer/discount", nil, nil).returns(test_response(test_delete_discount_response))
437
+ @mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/discount", nil, nil).returns(test_response(test_delete_discount_response))
422
438
  s = c.delete_discount
423
439
  assert_equal nil, c.discount
424
440
  end
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: 3
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
- - 4
10
- version: 1.7.4
9
+ - 6
10
+ version: 1.7.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ross Boucher
@@ -16,12 +16,10 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-10-09 00:00:00 Z
19
+ date: 2012-10-31 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- name: rest-client
24
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ requirement: &id001 !ruby/object:Gem::Requirement
25
23
  none: false
26
24
  requirements:
27
25
  - - ~>
@@ -31,12 +29,12 @@ dependencies:
31
29
  - 1
32
30
  - 4
33
31
  version: "1.4"
34
- requirement: *id001
32
+ name: rest-client
35
33
  type: :runtime
36
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
37
35
  prerelease: false
38
- name: multi_json
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ - !ruby/object:Gem::Dependency
37
+ requirement: &id002 !ruby/object:Gem::Requirement
40
38
  none: false
41
39
  requirements:
42
40
  - - ~>
@@ -46,12 +44,12 @@ dependencies:
46
44
  - 1
47
45
  - 1
48
46
  version: "1.1"
49
- requirement: *id002
47
+ name: multi_json
50
48
  type: :runtime
51
- - !ruby/object:Gem::Dependency
49
+ version_requirements: *id002
52
50
  prerelease: false
53
- name: mocha
54
- version_requirements: &id003 !ruby/object:Gem::Requirement
51
+ - !ruby/object:Gem::Dependency
52
+ requirement: &id003 !ruby/object:Gem::Requirement
55
53
  none: false
56
54
  requirements:
57
55
  - - ">="
@@ -60,12 +58,12 @@ dependencies:
60
58
  segments:
61
59
  - 0
62
60
  version: "0"
63
- requirement: *id003
61
+ name: mocha
64
62
  type: :development
65
- - !ruby/object:Gem::Dependency
63
+ version_requirements: *id003
66
64
  prerelease: false
67
- name: shoulda
68
- version_requirements: &id004 !ruby/object:Gem::Requirement
65
+ - !ruby/object:Gem::Dependency
66
+ requirement: &id004 !ruby/object:Gem::Requirement
69
67
  none: false
70
68
  requirements:
71
69
  - - ">="
@@ -74,12 +72,12 @@ dependencies:
74
72
  segments:
75
73
  - 0
76
74
  version: "0"
77
- requirement: *id004
75
+ name: shoulda
78
76
  type: :development
79
- - !ruby/object:Gem::Dependency
77
+ version_requirements: *id004
80
78
  prerelease: false
81
- name: test-unit
82
- version_requirements: &id005 !ruby/object:Gem::Requirement
79
+ - !ruby/object:Gem::Dependency
80
+ requirement: &id005 !ruby/object:Gem::Requirement
83
81
  none: false
84
82
  requirements:
85
83
  - - ">="
@@ -88,12 +86,12 @@ dependencies:
88
86
  segments:
89
87
  - 0
90
88
  version: "0"
91
- requirement: *id005
89
+ name: test-unit
92
90
  type: :development
93
- - !ruby/object:Gem::Dependency
91
+ version_requirements: *id005
94
92
  prerelease: false
95
- name: rake
96
- version_requirements: &id006 !ruby/object:Gem::Requirement
93
+ - !ruby/object:Gem::Dependency
94
+ requirement: &id006 !ruby/object:Gem::Requirement
97
95
  none: false
98
96
  requirements:
99
97
  - - ">="
@@ -102,8 +100,10 @@ dependencies:
102
100
  segments:
103
101
  - 0
104
102
  version: "0"
105
- requirement: *id006
103
+ name: rake
106
104
  type: :development
105
+ version_requirements: *id006
106
+ prerelease: false
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
@@ -153,6 +153,7 @@ files:
153
153
  - lib/stripe/invoice.rb
154
154
  - lib/stripe/invoice_item.rb
155
155
  - lib/stripe/json.rb
156
+ - lib/stripe/list_object.rb
156
157
  - lib/stripe/plan.rb
157
158
  - lib/stripe/singleton_api_resource.rb
158
159
  - lib/stripe/stripe_object.rb