geoloqi 0.9.40 → 0.9.41

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,16 +1,13 @@
1
- Geoloqi Library for Ruby [![](https://secure.travis-ci.org/geoloqi/geoloqi-ruby.png)](http://travis-ci.org/geoloqi/geoloqi-ruby)
2
- ===
1
+ # Geoloqi Library for Ruby [![](https://secure.travis-ci.org/geoloqi/geoloqi-ruby.png)](http://travis-ci.org/geoloqi/geoloqi-ruby)
3
2
  Powerful, flexible, lightweight interface to the Geoloqi Platform API.
4
3
 
5
4
  This library was developed with two goals in mind: to be as simple as possible, but also to be very powerful to allow for much higher-end development (multiple Geoloqi apps per instance, concurrency, performance, thread-safety).
6
5
 
7
- Installation
8
- ---
6
+ ##Installation
9
7
 
10
8
  gem install geoloqi
11
9
 
12
- Basic Usage
13
- ---
10
+ ##Basic Usage
14
11
  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 Developers Site](https://developers.geoloqi.com), click on "Get Started" and copy the permanent access token. You can use this token to run the following examples.
15
12
 
16
13
  If you just need to make simple requests, you can just make a simple get or post request from Geoloqi:
@@ -62,8 +59,7 @@ You can send query string parameters with get requests too:
62
59
  # or
63
60
  geoloqi.get 'location/history?count=2'
64
61
 
65
- Hashie::Mash support
66
- ---
62
+ ##Hashie::Mash support
67
63
  Want to access in a more OOP/JSON style way? Use Hashie::Mash as the response object:
68
64
 
69
65
  require 'hashie'
@@ -74,8 +70,7 @@ Want to access in a more OOP/JSON style way? Use Hashie::Mash as the response ob
74
70
  response['layer_id'] # this works too
75
71
  response[:layer_id] # so does this
76
72
 
77
- Implementing OAuth2
78
- ---
73
+ ##Implementing OAuth2
79
74
 
80
75
  We have integrated OAuth2 support into the gem for your convenience, and provided a Geoloqi plugin for Sinatra. This is all it takes to get a "Hello World" for OAuth2 with Geoloqi:
81
76
 
@@ -102,16 +97,31 @@ Visit the [Geoloqi Sinatra plugin](http://github.com/geoloqi/sinatra-geoloqi) pa
102
97
 
103
98
  A lower-level demonstration of the OAuth2 code can be found in the examples folder. This may be useful for anyone working to embed with other frameworks (such as Ruby on Rails).
104
99
 
105
- Found a bug?
106
- ---
100
+ ##Making requests on behalf of the application
101
+ Some actions (such as creating a user account for your application) require escalated privileges. To use these, call app\_get and app\_post:
102
+
103
+ geoloqi.app_post 'user/create_anon'
104
+
105
+ ## API Documentation
106
+ The API has been extensively documented at [our developers site](https://developers.geoloqi.com/api).
107
+
108
+ ## RDoc/YARD Documentation
109
+ The code has been fully documented, and the latest version is always available at the [Rubydoc Site](http://rubydoc.info/gems/geoloqi).
110
+
111
+ ## Running the Tests
112
+
113
+ $ bundle install
114
+ $ bundle exec rake
115
+
116
+ In addition to a full test suite, there is Travis integration for 1.9, JRuby and Rubinius. 1.8 is supported, however Travis tests have been disabled because 1.8's random hashing sometimes breaks Webmock. I highly recommend looking into upgrading to Ruby 1.9.. it's awesomer.
117
+
118
+ ##Found a bug?
107
119
  Let us know! Send a pull request or a patch. Questions? Ask! We're here to help. File issues, we'll respond to them!
108
120
 
109
- Authors
110
- ---
121
+ ##Authors
111
122
  * Kyle Drake
112
123
  * Aaron Parecki
113
124
 
114
- TODO / Possible projects
115
- ---
125
+ ##TODO / Possible projects
116
126
  * Rails plugin (works fine as-is, but maybe we can make it easier?)
117
127
  * More Concrete API in addition to the simple one?
@@ -5,9 +5,8 @@ Gem::Specification.new do |s|
5
5
  s.authors = ['Kyle Drake', 'Aaron Parecki']
6
6
  s.email = ['kyle@geoloqi.com', 'aaron@geoloqi.com']
7
7
  s.homepage = 'http://github.com/geoloqi/geoloqi-ruby'
8
- s.summary = 'Powerful, flexible, lightweight interface to the awesome Geoloqi platform API'
9
- s.description = 'Powerful, flexible, lightweight interface to the awesome Geoloqi platform API! Uses Faraday, '+
10
- 'and can be used with Ruby 1.9 and EM-Synchrony for really fast, highly concurrent development.'
8
+ s.summary = 'Powerful, flexible, lightweight interface to the Geoloqi Platform API'
9
+ s.description = 'Powerful, flexible, lightweight, thread-safe interface to the Geoloqi Platform API'
11
10
 
12
11
  s.files = `git ls-files`.split("\n")
13
12
  s.require_paths = %w[lib]
@@ -83,6 +83,83 @@ module Geoloqi
83
83
  Geoloqi.authorize_url @config.client_id, redirect_uri, opts
84
84
  end
85
85
 
86
+ # Makes a GET request to the Geoloqi API server with application credentials. The client_id and client_secret are
87
+ # sent via an HTTP Authorize header, as per the OAuth2 spec. Otherwise, this method is equivelant to #get.
88
+ #
89
+ # This is required for API calls which require escalated privileges, such as retreiving user information for a user
90
+ # that is not associated with your current access token (GET user/list/ANOTHER_USERS_ID).
91
+ #
92
+ # If you don't require application privileges, you should use the regular #get method instead.
93
+ #
94
+ # See the Authorization section of the Geoloqi Platform API documentation for more information.
95
+ #
96
+ # @param [String] path
97
+ # Path to the resource being requested.
98
+ #
99
+ # @param [String, Hash] query (optional)
100
+ # A query string or Hash to be appended to the request.
101
+ #
102
+ # @param [Hash] headers (optional)
103
+ # Adds and overwrites headers in request sent to server.
104
+ #
105
+ # @return [Hash,Hashie::Mash]
106
+ # @see #app_post
107
+ # @see #get
108
+ # @example
109
+ # # Request user information, for a user not associated with the current user access token.
110
+ # result = geoloqi_session.app_get 'YOUR ACCESS TOKEN', 'user/list/ANOTHER_USERS_ID'
111
+ def app_get(path, query=nil, headers={})
112
+ app_run :get, path, query, headers
113
+ end
114
+
115
+ # Makes a POST request to the Geoloqi API server with application credentials. The client_id and client_secret are
116
+ # sent via an HTTP Authorize header, as per the OAuth2 spec. Otherwise, this method is equivelant to #post.
117
+ #
118
+ # This is required for API calls which require escalated privileges, such as creating a user account (user/create, user/create_anon)
119
+ # or making a request for an access token (oauth/token).
120
+ #
121
+ # If you don't require application privileges, you should use the regular #post method instead.
122
+ #
123
+ # See the Authorization section of the Geoloqi Platform API documentation for more information.
124
+ #
125
+ # @param [String] path
126
+ # Path to the resource being requested (example: '/account/profile').
127
+ #
128
+ # @param [String, Hash] query (optional)
129
+ # A query string or Hash to be converted to POST parameters.
130
+ #
131
+ # @param [Hash] headers (optional)
132
+ # Adds and overwrites headers in request sent to server.
133
+ #
134
+ # @return [Hash,Hashie::Mash]
135
+ # @see #app_get
136
+ # @see #post
137
+ # @example
138
+ # # Create a new layer
139
+ # result = geoloqi_session.post 'layer/create', :name => 'Portland Food Carts'
140
+ def app_post(path, query=nil, headers={})
141
+ app_run :post, path, query, headers
142
+ end
143
+
144
+ # Makes a request to the Geoloqi API server with escalated privileges.
145
+ #
146
+ # @return [Hash,Hashie::Mash]
147
+ # @see #app_get
148
+ # @see #app_post
149
+ # @example
150
+ # # Create a new layer
151
+ # result = geoloqi_session.run :get, 'layer/create', :name => 'Northeast Portland'
152
+ def app_run(meth, path, query=nil, headers={})
153
+ raise Error, 'client_id and client_secret are required to make application requests' unless @config.client_id? && @config.client_secret?
154
+
155
+ credentials = "#{@config.client_id}:#{@config.client_secret}"
156
+
157
+ # Base64.strict_encode64 in 1.9, but we're using pack directly for compatibility with 1.8.
158
+ headers['Authorization'] = "Basic " + [credentials].pack("m0")
159
+
160
+ run meth, path, query, headers
161
+ end
162
+
86
163
  # Makes a GET request to the Geoloqi API server and returns response.
87
164
  #
88
165
  # @param [String] path
@@ -95,13 +172,14 @@ module Geoloqi
95
172
  # Adds and overwrites headers in request sent to server.
96
173
  #
97
174
  # @return [Hash,Hashie::Mash]
175
+ # @see #app_get
98
176
  # @see #post
99
177
  # @example
100
178
  # # Get your user profile
101
- # result = geoloqi_session.get 'YOUR ACCESS TOKEN', 'account/profile'
179
+ # result = geoloqi_session.get 'account/profile'
102
180
  #
103
181
  # # Get the last 5 locations
104
- # result = geoloqi_session.get 'YOUR ACCESS TOKEN', 'account/profile', :count => 5
182
+ # result = geoloqi_session.get 'account/profile', :count => 5
105
183
  def get(path, query=nil, headers={})
106
184
  run :get, path, query, headers
107
185
  end
@@ -119,6 +197,7 @@ module Geoloqi
119
197
  #
120
198
  # @return [Hash,Hashie::Mash]
121
199
  # @see #get
200
+ # @see #app_post
122
201
  # @example
123
202
  # # Create a new layer
124
203
  # result = geoloqi_session.post 'layer/create', :name => 'Portland Food Carts'
@@ -216,13 +295,11 @@ module Geoloqi
216
295
  # @see #application_access_token
217
296
  def establish(opts={})
218
297
  raise Error, 'client_id and client_secret are required to get access token' unless @config.client_id? && @config.client_secret?
219
- auth = post 'oauth/token', {:client_id => @config.client_id,
298
+ auth = post 'oauth/token', {:client_id => @config.client_id,
220
299
  :client_secret => @config.client_secret}.merge!(opts)
221
300
 
222
- # expires_at is likely incorrect. I'm chopping 5 seconds
223
- # off to allow for a more graceful failover.
224
- auth['expires_at'] = auth_expires_at auth['expires_in']
225
301
  self.auth = auth
302
+ self.auth[:expires_at] = auth_expires_at auth[:expires_in]
226
303
  self.auth
227
304
  end
228
305
 
@@ -3,6 +3,6 @@ module Geoloqi
3
3
  #
4
4
  # @return [String]
5
5
  def self.version
6
- '0.9.40'
6
+ '0.9.41'
7
7
  end
8
8
  end
@@ -20,4 +20,8 @@ end
20
20
 
21
21
  def api_url(path); "#{Geoloqi.api_url}/#{Geoloqi.api_version}/#{path}" end
22
22
 
23
+ def api_url_with_auth(path)
24
+ Addressable::URI.parse(api_url(path)).merge(:user => CLIENT_ID, :password => CLIENT_SECRET).to_s
25
+ end
26
+
23
27
  include WebMock::API
@@ -261,6 +261,23 @@ describe Geoloqi::Session do
261
261
  @session = Geoloqi::Session.new :config => {:client_id => CLIENT_ID, :client_secret => CLIENT_SECRET}
262
262
  end
263
263
 
264
+ it 'should automatically provide client_id and client_secret for app resource calls' do
265
+ stub_request(:get, api_url_with_auth('user/list/notme')).
266
+ to_return(:status => 200,
267
+ :body => {:username => 'captainpicard'}.to_json)
268
+
269
+ resp = @session.app_get 'user/list/notme'
270
+ resp[:username].must_equal 'captainpicard'
271
+
272
+ stub_request(:post, api_url_with_auth('user/create_anon')).
273
+ with(:body => {:device_id => 'abcd'}.to_json).
274
+ to_return(:status => 200,
275
+ :body => {:username => 'captainpicard'}.to_json)
276
+
277
+ resp = @session.app_post 'user/create_anon', {:device_id => 'abcd'}
278
+ resp[:username].must_equal 'captainpicard'
279
+ end
280
+
264
281
  it 'retreives application access token data' do
265
282
  stub_request(:post, api_url('oauth/token')).
266
283
  with(:body => {:client_id => CLIENT_ID,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoloqi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.40
4
+ version: 0.9.41
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-16 00:00:00.000000000 Z
13
+ date: 2012-05-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
- requirement: &70104353347040 !ruby/object:Gem::Requirement
17
+ requirement: &70107121128860 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70104353347040
25
+ version_requirements: *70107121128860
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: faraday
28
- requirement: &70104353345520 !ruby/object:Gem::Requirement
28
+ requirement: &70107121127640 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 0.6.1
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70104353345520
36
+ version_requirements: *70107121127640
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rake
39
- requirement: &70104353344720 !ruby/object:Gem::Requirement
39
+ requirement: &70107121126600 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70104353344720
47
+ version_requirements: *70107121126600
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: minitest
50
- requirement: &70104353317060 !ruby/object:Gem::Requirement
50
+ requirement: &70107121141900 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - =
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 2.2.2
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70104353317060
58
+ version_requirements: *70107121141900
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: webmock
61
- requirement: &70104353316420 !ruby/object:Gem::Requirement
61
+ requirement: &70107121141060 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - =
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.6.4
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70104353316420
69
+ version_requirements: *70107121141060
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: hashie
72
- requirement: &70104353315300 !ruby/object:Gem::Requirement
72
+ requirement: &70107121140500 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - =
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 1.0.0
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70104353315300
80
+ version_requirements: *70107121140500
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: yard
83
- requirement: &70104353314800 !ruby/object:Gem::Requirement
83
+ requirement: &70107121140060 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,9 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *70104353314800
92
- description: Powerful, flexible, lightweight interface to the awesome Geoloqi platform
93
- API! Uses Faraday, and can be used with Ruby 1.9 and EM-Synchrony for really fast,
94
- highly concurrent development.
91
+ version_requirements: *70107121140060
92
+ description: Powerful, flexible, lightweight, thread-safe interface to the Geoloqi
93
+ Platform API
95
94
  email:
96
95
  - kyle@geoloqi.com
97
96
  - aaron@geoloqi.com
@@ -146,7 +145,6 @@ rubyforge_project: geoloqi
146
145
  rubygems_version: 1.8.17
147
146
  signing_key:
148
147
  specification_version: 3
149
- summary: Powerful, flexible, lightweight interface to the awesome Geoloqi platform
150
- API
148
+ summary: Powerful, flexible, lightweight interface to the Geoloqi Platform API
151
149
  test_files: []
152
150
  has_rdoc: