Permalink
Browse files

Support for query strings with GET requests

  • Loading branch information...
1 parent d5bcc41 commit 7c4501d36be63a651c49bbc8c24988eca1093374 @kyledrake kyledrake committed Jun 11, 2011
Showing with 31 additions and 14 deletions.
  1. +6 −0 README.markdown
  2. +10 −9 lib/geoloqi/session.rb
  3. +1 −1 lib/geoloqi/version.rb
  4. +14 −4 spec/geoloqi_spec.rb
View
@@ -45,6 +45,12 @@ This returns response['place_id'], which you can use to store and/or remove the
Which returns response['result'] with a value of "ok".
+You can send query string parameters with get requests too:
+
+ geoloqi.get 'location/history', :count => 2
+ # or
+ geoloqi.get 'location/history?count=2'
+
Implementing OAuth2
---
View
@@ -31,25 +31,26 @@ def authorize_url(redirect_uri)
Geoloqi.authorize_url @config.client_id, redirect_uri
end
- def get(path)
- run :get, path
+ def get(path, query=nil)
+ run :get, path, query
end
- def post(path, body=nil)
- run :post, path, body
+ def post(path, query=nil)
+ run :post, path, query
end
- def run(meth, path, body=nil)
+ def run(meth, path, query=nil)
+ query = Rack::Utils.parse_query query if query.is_a?(String)
renew_access_token! if auth[:expires_at] && auth[:expires_at] <= Time.now
-
- body = body.to_json if [Hash, Array].include? body.class
-
retry_attempt = 0
begin
response = @connection.send(meth) do |req|
req.url "/#{API_VERSION.to_s}/#{path.gsub(/^\//, '')}"
req.headers = headers
- req.body = body if body
+
+ if query
+ meth == :get ? req.params = query : req.body = query.to_json
+ end
end
json = JSON.parse response.body
View
@@ -1,3 +1,3 @@
module Geoloqi
- VERSION = '0.9.2'
+ VERSION = '0.9.3'
end
View
@@ -65,13 +65,11 @@
end
it 'successfully makes call to api with forward slash' do
- response = @session.get '/layer/info/Gx'
- expect { response['layer_id'] == 'Gx' }
+ expect { @session.get('/layer/info/Gx')['layer_id'] == 'Gx' }
end
it 'successfully makes call to api without forward slash' do
- response = @session.get 'layer/info/Gx'
- expect { response['layer_id'] == 'Gx' }
+ expect { @session.get('layer/info/Gx')['layer_id'] == 'Gx' }
end
it 'creates a layer, reads its info, and then deletes the layer' do
@@ -84,6 +82,18 @@
expect { layer_info['name'] == 'Test Layer' }
expect { layer_delete['result'] == 'ok' }
end
+
+ it 'makes a location/history call with get and hash params' do
+ expect { @session.get('location/history', :count => 2)['points'].count == 2 }
+ end
+
+ it 'makes a location/history call with get and query string directly in path' do
+ expect { @session.get('location/history?count=2')['points'].count == 2 }
+ end
+
+ it 'makes a location/history call with get and query string params' do
+ expect { @session.get('location/history', 'count=2')['points'].count == 2 }
+ end
end
describe 'with oauth id, secret, and access token via Geoloqi::Config' do

0 comments on commit 7c4501d

Please sign in to comment.