stripe 1.8.2 → 1.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 1.8.3 2013-05-06
2
+
3
+ * 1 bugfix:
4
+ * Fix handling of per-call API keys (github issue #67)
5
+
1
6
  === 1.8.2 2013-05-01
2
7
 
3
8
  * 3 minor enhancement:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.2
1
+ 1.8.3
@@ -91,7 +91,7 @@ module Stripe
91
91
  payload = uri_encode(params)
92
92
  end
93
93
 
94
- request_opts.update(:headers => request_headers.update(headers),
94
+ request_opts.update(:headers => request_headers(api_key).update(headers),
95
95
  :method => method, :open_timeout => 30,
96
96
  :payload => payload, :url => url, :timeout => 80)
97
97
 
@@ -117,7 +117,7 @@ module Stripe
117
117
  handle_restclient_error(e)
118
118
  end
119
119
 
120
- parse(response)
120
+ [parse(response), api_key]
121
121
  end
122
122
 
123
123
  private
@@ -165,7 +165,7 @@ module Stripe
165
165
  map { |k,v| "#{k}=#{Util.url_encode(v)}" }.join('&')
166
166
  end
167
167
 
168
- def self.request_headers
168
+ def self.request_headers(api_key)
169
169
  headers = {
170
170
  :user_agent => "Stripe/v1 RubyBindings/#{Stripe::VERSION}",
171
171
  :authorization => "Bearer #{api_key}",
@@ -195,7 +195,7 @@ module Stripe
195
195
  raise general_api_error(response.code, response.body)
196
196
  end
197
197
 
198
- [Util.symbolize_names(response), api_key]
198
+ Util.symbolize_names(response)
199
199
  end
200
200
 
201
201
  def self.general_api_error(rcode, rbody)
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.8.2'
2
+ VERSION = '1.8.3'
3
3
  end
@@ -111,6 +111,52 @@ class TestStripeRuby < Test::Unit::TestCase
111
111
  end
112
112
  end
113
113
 
114
+ context "when specifying per-object credentials" do
115
+ context "with no global API key set" do
116
+ should "use the per-object credential when creating" do
117
+ Stripe.expects(:execute_request).with do |opts|
118
+ opts[:headers][:authorization] == 'Bearer sk_test_local'
119
+ end.returns(test_response(test_charge))
120
+
121
+ Stripe::Charge.create({:card => {:number => '4242424242424242'}},
122
+ 'sk_test_local')
123
+ end
124
+ end
125
+
126
+ context "with a global API key set" do
127
+ setup do
128
+ Stripe.api_key = "global"
129
+ end
130
+
131
+ teardown do
132
+ Stripe.api_key = nil
133
+ end
134
+
135
+ should "use the per-object credential when creating" do
136
+ Stripe.expects(:execute_request).with do |opts|
137
+ opts[:headers][:authorization] == 'Bearer local'
138
+ end.returns(test_response(test_charge))
139
+
140
+ Stripe::Charge.create({:card => {:number => '4242424242424242'}},
141
+ 'local')
142
+ end
143
+
144
+ should "use the per-object credential when retrieving and making other calls" do
145
+ Stripe.expects(:execute_request).with do |opts|
146
+ opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge" &&
147
+ opts[:headers][:authorization] == 'Bearer local'
148
+ end.returns(test_response(test_charge))
149
+ Stripe.expects(:execute_request).with do |opts|
150
+ opts[:url] == "#{Stripe.api_base}/v1/charges/ch_test_charge/refund" &&
151
+ opts[:headers][:authorization] == 'Bearer local'
152
+ end.returns(test_response(test_charge))
153
+
154
+ ch = Stripe::Charge.retrieve('ch_test_charge', 'local')
155
+ ch.refund
156
+ end
157
+ end
158
+ end
159
+
114
160
  context "with valid credentials" do
115
161
  setup do
116
162
  Stripe.api_key="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.8.2
4
+ version: 1.8.3
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-05-01 00:00:00.000000000 Z
13
+ date: 2013-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client