Skip to content

Commit

Permalink
Support for query strings with GET requests
Browse files Browse the repository at this point in the history
  • Loading branch information
kyledrake committed Jun 11, 2011
1 parent d5bcc41 commit 7c4501d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.markdown
Expand Up @@ -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
---

Expand Down
19 changes: 10 additions & 9 deletions lib/geoloqi/session.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/geoloqi/version.rb
@@ -1,3 +1,3 @@
module Geoloqi
VERSION = '0.9.2'
VERSION = '0.9.3'
end
18 changes: 14 additions & 4 deletions spec/geoloqi_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7c4501d

Please sign in to comment.