Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Geoloqi.get and Geoloqi.post

  • Loading branch information...
commit 0af3268013f49a3e216f02b0c73ca645d4d31d96 1 parent 8802857
@kyledrake kyledrake authored
View
17 README.markdown
@@ -11,14 +11,25 @@ Installation
Basic Usage
---
-Geoloqi uses OAuth2 for authentication, but if you're only working with your own account, you don't need to go through the authorization steps! Simply go to your account settings on the [Geoloqi site](http://geoloqi.com), click on "Connections" and copy the OAuth 2 Access Token. You can use this token to run the following examples:
+Geoloqi uses OAuth2 for authentication, but if you're only working with your own account, you don't need to go through the authorization steps! Simply go to your account settings on the [Geoloqi site](http://geoloqi.com), click on "Connections" and copy the OAuth 2 Access Token. You can use this token to run the following examples.
+
+If you just need to make simple requests, you can just make a simple get or post request from Geoloqi:
+
+ require 'geoloqi'
+ result = Geoloqi.get 'YOUR ACCESS TOKEN', 'layer/info/Gx'
+ puts response.inspect
+
+ # or a POST!
+ result = Geoloqi.post 'YOUR ACCESS TOKEN', 'layer/create', :name => 'Test Layer'
+
+If you're using Geoloqi with OAuth or making multiple requests, we recommend using the Geoloqi::Session class:
require 'geoloqi'
- geoloqi = Geoloqi::Session.new :access_token => 'YOUR OAUTH2 ACCESS TOKEN GOES HERE'
+ geoloqi = Geoloqi::Session.new :access_token => 'YOUR ACCESS TOKEN'
response = geoloqi.get 'layer/info/Gx'
puts response.inspect
-This example returns a hash with the following:
+Which returns a hash with the following:
{"layer_id"=>"Gx", "user_id"=>"4", "type"=>"normal", "name"=>"USGS Earthquakes",
"description"=>"Real-time notifications of earthquakes near you.",
View
32 lib/geoloqi.rb
@@ -17,15 +17,29 @@ module Geoloqi
@@enable_logging = false
@@config = Config.new
- def self.config(opts=nil)
- return @@config if opts.nil?
- @@config = Config.new opts
- end
+ class << self
+ def config(opts=nil)
+ return @@config if opts.nil?
+ @@config = Config.new opts
+ end
+
+ def get(access_token, path, args={})
+ run :get, access_token, path, args
+ end
+
+ def post(access_token, path, args={})
+ run :post, access_token, path, args
+ end
+
+ def run(meth, access_token, path, args={})
+ Session.new(:access_token => access_token).run meth, path, args
+ end
- def self.authorize_url(client_id=nil, redirect_uri=@@config.redirect_uri, opts={})
- raise "client_id required to authorize url. Pass with Geoloqi.config" unless client_id
- url = "#{OAUTH_URL}?response_type=code&client_id=#{Rack::Utils.escape client_id}&redirect_uri=#{Rack::Utils.escape redirect_uri}"
- url += "&#{Rack::Utils.build_query opts}" unless opts.empty?
- url
+ def authorize_url(client_id=nil, redirect_uri=@@config.redirect_uri, opts={})
+ raise "client_id required to authorize url. Pass with Geoloqi.config" unless client_id
+ url = "#{OAUTH_URL}?response_type=code&client_id=#{Rack::Utils.escape client_id}&redirect_uri=#{Rack::Utils.escape redirect_uri}"
+ url += "&#{Rack::Utils.build_query opts}" unless opts.empty?
+ url
+ end
end
end
View
2  lib/geoloqi/version.rb
@@ -1,5 +1,5 @@
module Geoloqi
def self.version
- '0.9.19'
+ '0.9.20'
end
end
View
19 spec/geoloqi_spec.rb
@@ -48,6 +48,25 @@ def api_url(path); "#{Geoloqi::API_URL}/#{Geoloqi::API_VERSION}/#{path}" end
"scope=can_party_hard" }
end
end
+
+ it 'makes get request' do
+ stub_request(:get, "https://api.geoloqi.com/1/quick_get?lol=cats").
+ with(:headers => {'Authorization'=>'OAuth access_token1234'}).
+ to_return(:body => {:result => 'ok'}.to_json)
+
+ response = Geoloqi.get ACCESS_TOKEN, '/quick_get', :lol => 'cats'
+ expect { response['result'] == 'ok' }
+ end
+
+ it 'makes post request' do
+ stub_request(:post, "https://api.geoloqi.com/1/quick_post").
+ with(:headers => {'Authorization'=>'OAuth access_token1234'},
+ :body => {:lol => 'dogs'}.to_json).
+ to_return(:body => {:result => 'ok'}.to_json)
+
+ response = Geoloqi.post ACCESS_TOKEN, '/quick_post', :lol => 'dogs'
+ expect { response['result'] == 'ok' }
+ end
end
describe Geoloqi::ApiError do
Please sign in to comment.
Something went wrong with that request. Please try again.