Skip to content

Commit a39e857

Browse files
committed
Merge pull request #6 from wacko/fix/querystring-params
Send querystring params on GET requests
2 parents 132ab74 + baa31cc commit a39e857

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

lib/mango.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ def self.request(method, url, api_key=nil, params={}, headers={})
3535
end
3636

3737
payload = JSON.generate(params) if method == :post || method == :patch
38+
params = nil unless method == :get
3839

3940
headers = {
41+
:params => params,
4042
:content_type => 'application/json'
4143
}.merge(headers)
4244

test/mango_test.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@
1919
end
2020

2121
test "operation retrieve" do |mock|
22-
mock.expects(:get).once.with('https://api.getmango.com/v1/customers/123/').returns(test_response(test_customer))
22+
mock.expects(:get).once.with('https://api.getmango.com/v1/customers/123/', {}).returns(test_response(test_customer))
2323
customer = Mango::Customers.retrieve 123
2424
assert_equal "customer_hash", customer[:uid]
2525
end
2626

2727
test "operation list" do |mock|
28-
mock.expects(:get).once.with('https://api.getmango.com/v1/customers/').returns(test_response([test_customer]))
28+
mock.expects(:get).once.with('https://api.getmango.com/v1/customers/', {}).returns(test_response([test_customer]))
2929
customers = Mango::Customers.list
3030
assert_equal "customer_hash", customers.first[:uid]
3131
end
3232

33+
test "aditional params on get" do |mock|
34+
mock.expects(:get).once.with('https://api.getmango.com/v1/customers/', cardtype: 'visa').returns(test_response([test_customer]))
35+
customers = Mango::Customers.list cardtype: 'visa'
36+
assert_equal "customer_hash", customers.first[:uid]
37+
end
38+
3339
test "operation create" do |mock|
3440
mock.expects(:post).once.with('https://api.getmango.com/v1/customers/', anything).returns(test_response(test_customer))
3541
customer = Mango::Customers.create customer_params

test/test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def self.mock_rest_client=(mock_client)
88
def self.execute_request(options)
99
case options[:method]
1010
when :get
11-
@mock_rest_client.get options[:url]
11+
@mock_rest_client.get options[:url], options[:headers][:params]
1212
when :post
1313
@mock_rest_client.post options[:url], options[:payload]
1414
when :patch

0 commit comments

Comments
 (0)