geoloqi 0.9.18 → 0.9.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +5 -0
- data/README.markdown +2 -2
- data/geoloqi.gemspec +1 -1
- data/lib/geoloqi/session.rb +3 -1
- data/lib/geoloqi/version.rb +1 -1
- data/spec/geoloqi_spec.rb +35 -20
- metadata +4 -3
data/README.markdown
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Geoloqi Library for Ruby
|
|
1
|
+
Geoloqi Library for Ruby [](http://travis-ci.org/geoloqi/geoloqi-ruby)
|
|
2
2
|
===
|
|
3
3
|
Powerful, flexible, lightweight interface to the awesome Geoloqi platform API! Uses Faraday, and can be used with Ruby 1.9 and EM-Synchrony for really fast, highly concurrent development.
|
|
4
4
|
|
|
@@ -144,4 +144,4 @@ TODO / Possible projects
|
|
|
144
144
|
---
|
|
145
145
|
* Plugin for Sinatra
|
|
146
146
|
* Rails plugin (works fine as-is, but maybe we can make it easier?)
|
|
147
|
-
* More Concrete API in addition to the simple one?
|
|
147
|
+
* More Concrete API in addition to the simple one?
|
data/geoloqi.gemspec
CHANGED
data/lib/geoloqi/session.rb
CHANGED
|
@@ -49,13 +49,15 @@ module Geoloqi
|
|
|
49
49
|
raise ApiError.new(response.status, hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error'] && @config.throw_exceptions
|
|
50
50
|
rescue Geoloqi::ApiError
|
|
51
51
|
raise Error.new('Unable to procure fresh access token from API on second attempt') if retry_attempt > 0
|
|
52
|
-
if hash['error'] == 'expired_token'
|
|
52
|
+
if hash['error'] == 'expired_token' && !(hash['error_description'] =~ /The auth code expired/)
|
|
53
53
|
renew_access_token!
|
|
54
54
|
retry_attempt += 1
|
|
55
55
|
retry
|
|
56
56
|
else
|
|
57
57
|
fail
|
|
58
58
|
end
|
|
59
|
+
rescue JSON::ParserError
|
|
60
|
+
raise Geoloqi::Error, "API returned invalid JSON. Status: #{response.status} Body: #{response.body}"
|
|
59
61
|
end
|
|
60
62
|
@config.use_hashie_mash ? Hashie::Mash.new(hash) : hash
|
|
61
63
|
end
|
data/lib/geoloqi/version.rb
CHANGED
data/spec/geoloqi_spec.rb
CHANGED
|
@@ -4,9 +4,7 @@ require './lib/geoloqi.rb'
|
|
|
4
4
|
require 'minitest/autorun'
|
|
5
5
|
require 'wrong'
|
|
6
6
|
require 'wrong/adapters/minitest'
|
|
7
|
-
require 'em-http-request' if RUBY_VERSION[0..2].to_f >= 1.9 # Preload for WebMock
|
|
8
7
|
require 'webmock'
|
|
9
|
-
require 'webmock/http_lib_adapters/em_http_request'
|
|
10
8
|
|
|
11
9
|
CLIENT_ID = 'client_id1234'
|
|
12
10
|
CLIENT_SECRET = 'client_secret1234'
|
|
@@ -145,6 +143,18 @@ describe Geoloqi::Session do
|
|
|
145
143
|
@session = Geoloqi::Session.new :access_token => ACCESS_TOKEN
|
|
146
144
|
end
|
|
147
145
|
|
|
146
|
+
it 'throws an exception on a hard request error' do
|
|
147
|
+
stub_request(:get, api_url('crashing_method')).
|
|
148
|
+
with(:headers => auth_headers).
|
|
149
|
+
to_return(:status => 500, :body => 'Something broke hard!')
|
|
150
|
+
|
|
151
|
+
expect { rescuing {Geoloqi::Session.new(:access_token => 'access_token1234').get('crashing_method')}.class == Geoloqi::Error }
|
|
152
|
+
expect {
|
|
153
|
+
rescuing {Geoloqi::Session.new(:access_token => 'access_token1234').get('crashing_method')}.message ==
|
|
154
|
+
"API returned invalid JSON. Status: 500 Body: Something broke hard!"
|
|
155
|
+
}
|
|
156
|
+
end
|
|
157
|
+
|
|
148
158
|
it 'successfully makes mock call with array' do
|
|
149
159
|
stub_request(:post, api_url('play_record_at_geoloqi_hq')).
|
|
150
160
|
with(:headers => auth_headers, :body => [{:artist => 'Television'}].to_json).
|
|
@@ -223,22 +233,6 @@ describe Geoloqi::Session do
|
|
|
223
233
|
end
|
|
224
234
|
end
|
|
225
235
|
|
|
226
|
-
# Ruby 1.9 only!
|
|
227
|
-
if RUBY_VERSION[0..2].to_f >= 1.9
|
|
228
|
-
begin
|
|
229
|
-
require 'em-synchrony'
|
|
230
|
-
rescue LoadError
|
|
231
|
-
puts 'NOTE: You need the em-synchrony gem for all tests to pass: gem install em-synchrony'
|
|
232
|
-
end
|
|
233
|
-
describe 'with em synchrony adapter and access token' do
|
|
234
|
-
it 'makes call to api' do
|
|
235
|
-
session = Geoloqi::Session.new :access_token => ACCESS_TOKEN, :config => {:adapter => :em_synchrony}
|
|
236
|
-
response = session.get 'layer/info/Gx'
|
|
237
|
-
expect { response['layer_id'] == 'Gx' }
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
|
|
242
236
|
describe 'with client id, client secret, and access token via direct hash' do
|
|
243
237
|
before do
|
|
244
238
|
@session = Geoloqi::Session.new :access_token => ACCESS_TOKEN,
|
|
@@ -318,8 +312,6 @@ describe Geoloqi::Session do
|
|
|
318
312
|
:refresh_token => 'refresh_token1234'}.each do |k,v|
|
|
319
313
|
expect { response[k] == v }
|
|
320
314
|
end
|
|
321
|
-
|
|
322
|
-
expect { (5..10).include? (Time.rfc2822(response[:expires_at]) - (Time.now+86400)).abs }
|
|
323
315
|
end
|
|
324
316
|
|
|
325
317
|
it 'does not refresh when never expires' do
|
|
@@ -333,6 +325,10 @@ describe Geoloqi::Session do
|
|
|
333
325
|
:scope => nil,
|
|
334
326
|
:expires_in => '0',
|
|
335
327
|
:refresh_token => 'never_expires'}.to_json)
|
|
328
|
+
|
|
329
|
+
stub_request(:get, api_url('account/username')).
|
|
330
|
+
with(:headers => {'Authorization'=>'OAuth access_token1234'}).
|
|
331
|
+
to_return(:body => {:username => 'bulbasaurrulzok'}.to_json)
|
|
336
332
|
|
|
337
333
|
response = @session.get_auth '1234', 'http://neverexpires.example.com/'
|
|
338
334
|
|
|
@@ -344,6 +340,25 @@ describe Geoloqi::Session do
|
|
|
344
340
|
expect { @session.auth[:access_token] == 'access_token1234' }
|
|
345
341
|
expect { response['username'] == 'bulbasaurrulzok' }
|
|
346
342
|
end
|
|
343
|
+
|
|
344
|
+
it 'does not attempt to refresh for auth code expire' do
|
|
345
|
+
stub_request(:post, api_url('oauth/token')).
|
|
346
|
+
with(:body => {:client_id => CLIENT_ID,
|
|
347
|
+
:client_secret => CLIENT_SECRET,
|
|
348
|
+
:grant_type => "authorization_code",
|
|
349
|
+
:code => "1234",
|
|
350
|
+
:redirect_uri => "http://expired_code.example.com/"}.to_json).
|
|
351
|
+
to_return(:body => {:access_token => 'access_token1234',
|
|
352
|
+
:scope => nil,
|
|
353
|
+
:expires_in => '0',
|
|
354
|
+
:refresh_token => 'never_expires'}.to_json)
|
|
355
|
+
|
|
356
|
+
stub_request(:get, api_url('account/username?code=1234')).
|
|
357
|
+
with(:headers => auth_headers).
|
|
358
|
+
to_return(:status => 200, :body => {:points => [1,2]}.to_json)
|
|
359
|
+
|
|
360
|
+
# FINISH IMPLEMENTING
|
|
361
|
+
end
|
|
347
362
|
end
|
|
348
363
|
|
|
349
364
|
describe 'with config and expired auth' do
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: geoloqi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.9.
|
|
5
|
+
version: 0.9.19
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Kyle Drake
|
|
@@ -11,7 +11,7 @@ autorequire:
|
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
13
|
|
|
14
|
-
date: 2011-
|
|
14
|
+
date: 2011-08-08 00:00:00 -07:00
|
|
15
15
|
default_executable:
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
@@ -103,6 +103,7 @@ extra_rdoc_files: []
|
|
|
103
103
|
|
|
104
104
|
files:
|
|
105
105
|
- .gitignore
|
|
106
|
+
- .travis.yml
|
|
106
107
|
- Gemfile
|
|
107
108
|
- README.markdown
|
|
108
109
|
- Rakefile
|
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
142
143
|
requirements: []
|
|
143
144
|
|
|
144
145
|
rubyforge_project: geoloqi
|
|
145
|
-
rubygems_version: 1.
|
|
146
|
+
rubygems_version: 1.5.2
|
|
146
147
|
signing_key:
|
|
147
148
|
specification_version: 3
|
|
148
149
|
summary: Powerful, flexible, lightweight interface to the awesome Geoloqi platform API
|