mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-08-21 00:00:42 -04:00
Put params for get/head/delete into query string
This commit is contained in:
parent
243ff69086
commit
a981f4910c
@ -452,6 +452,17 @@ module Stripe
|
||||
:publisher => 'stripe',
|
||||
:uname => uname
|
||||
}
|
||||
|
||||
params = Util.objects_to_ids(params)
|
||||
case method.to_s.downcase.to_sym
|
||||
when :get, :head, :delete
|
||||
# Make params into GET parameters
|
||||
headers = { :params => params }.merge(headers)
|
||||
payload = nil
|
||||
else
|
||||
payload = params
|
||||
end
|
||||
|
||||
headers = {
|
||||
:x_stripe_client_user_agent => JSON.dump(ua),
|
||||
:user_agent => "Stripe/v1 RubyBindings/#{Stripe.version}"
|
||||
@ -461,8 +472,8 @@ module Stripe
|
||||
:url => self.api_url(url),
|
||||
:user => api_key,
|
||||
:headers => headers,
|
||||
:payload => Util.objects_to_ids(params),
|
||||
:open_timeout => 30,
|
||||
:payload => payload,
|
||||
:timeout => 80
|
||||
}.merge(ssl_opts)
|
||||
|
||||
|
@ -14,10 +14,12 @@ module Stripe
|
||||
end
|
||||
|
||||
def self.execute_request(opts)
|
||||
get_params = (opts[:headers] || {})[:params]
|
||||
post_params = opts[:payload]
|
||||
case opts[:method]
|
||||
when :get: @mock_rest_client.get opts[:url]
|
||||
when :post: @mock_rest_client.post opts[:url], opts[:payload]
|
||||
when :delete: @mock_rest_client.delete opts[:url]
|
||||
when :get: @mock_rest_client.get opts[:url], get_params, post_params
|
||||
when :post: @mock_rest_client.post opts[:url], get_params, post_params
|
||||
when :delete: @mock_rest_client.delete opts[:url], get_params, post_params
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -72,16 +72,28 @@ class TestStripeRuby < Test::Unit::TestCase
|
||||
|
||||
should "requesting with a unicode ID should result in a request" do
|
||||
response = test_response(test_missing_id_error, 404)
|
||||
@mock.expects(:get).once.with("https://api.stripe.com/v1/customers/%E2%98%83").raises(RestClient::ExceptionWithResponse.new(response, 404))
|
||||
@mock.expects(:get).once.with("https://api.stripe.com/v1/customers/%E2%98%83", nil, nil).raises(RestClient::ExceptionWithResponse.new(response, 404))
|
||||
c = Stripe::Customer.new("☃")
|
||||
assert_raises(Stripe::InvalidRequestError) { c.refresh }
|
||||
end
|
||||
|
||||
should "requesting with no ID shuold result in an InvalidRequestError with no request" do
|
||||
should "requesting with no ID should result in an InvalidRequestError with no request" do
|
||||
c = Stripe::Customer.new
|
||||
assert_raises(Stripe::InvalidRequestError) { c.refresh }
|
||||
end
|
||||
|
||||
should "making a GET request with parameters should have a query string and no body" do
|
||||
params = { :limit => 1 }
|
||||
@mock.expects(:get).once.with { |url, get, post| get == params and post.nil? }.returns(test_response([test_charge]))
|
||||
c = Stripe::Charge.all(params)
|
||||
end
|
||||
|
||||
should "making a POST request with parameters should have a body and no query string" do
|
||||
params = { :amount => 100, :currency => 'usd', :card => 'sc_token' }
|
||||
@mock.expects(:post).once.with { |url, get, post| get.nil? and post == params }.returns(test_response(test_charge))
|
||||
c = Stripe::Charge.create(params)
|
||||
end
|
||||
|
||||
should "loading an object should issue a GET request" do
|
||||
@mock.expects(:get).once.returns(test_response(test_customer))
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
@ -105,7 +117,7 @@ class TestStripeRuby < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
should "updating an object should issue a POST request with only the changed properties" do
|
||||
@mock.expects(:post).with("https://api.stripe.com/v1/customers/c_test_customer", {:mnemonic => 'another_mn'}).once.returns(test_response(test_customer))
|
||||
@mock.expects(:post).with("https://api.stripe.com/v1/customers/c_test_customer", nil, {:mnemonic => 'another_mn'}).once.returns(test_response(test_customer))
|
||||
c = Stripe::Customer.construct_from(test_customer)
|
||||
c.mnemonic = "another_mn"
|
||||
c.save
|
||||
@ -122,7 +134,7 @@ class TestStripeRuby < Test::Unit::TestCase
|
||||
should "deleting should send no props and result in an object that has no props other deleted" do
|
||||
@mock.expects(:get).never
|
||||
@mock.expects(:post).never
|
||||
@mock.expects(:delete).with("https://api.stripe.com/v1/customers/c_test_customer").once.returns(test_response({ "id" => "test_customer", "deleted" => true }))
|
||||
@mock.expects(:delete).with("https://api.stripe.com/v1/customers/c_test_customer", nil, nil).once.returns(test_response({ "id" => "test_customer", "deleted" => true }))
|
||||
|
||||
c = Stripe::Customer.construct_from(test_customer)
|
||||
c.delete
|
||||
@ -188,7 +200,7 @@ class TestStripeRuby < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
should "execute should return a new, fully executed charge when passed correct parameters" do
|
||||
@mock.expects(:post).with('https://api.stripe.com/v1/charges', {
|
||||
@mock.expects(:post).with('https://api.stripe.com/v1/charges', nil, {
|
||||
:currency => 'usd', :amount => 100,
|
||||
:card => {:exp_year => 2012, :number => '4242424242424242', :exp_month => 11}
|
||||
}).once.returns(test_response(test_charge))
|
||||
@ -249,7 +261,7 @@ class TestStripeRuby < Test::Unit::TestCase
|
||||
@mock.expects(:get).once.returns(test_response(test_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
|
||||
@mock.expects(:post).once.with("https://api.stripe.com/v1/customers/c_test_customer/subscription", {:plan => 'silver'}).returns(test_response(test_subscription('silver')))
|
||||
@mock.expects(:post).once.with("https://api.stripe.com/v1/customers/c_test_customer/subscription", nil, {:plan => 'silver'}).returns(test_response(test_subscription('silver')))
|
||||
s = c.update_subscription({:plan => 'silver'})
|
||||
|
||||
assert_equal 'subscription', s.object
|
||||
|
Loading…
x
Reference in New Issue
Block a user