geoloqi 0.9.18 → 0.9.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - rbx
4
+ - rbx-2.0
5
+ - jruby
@@ -1,4 +1,4 @@
1
- Geoloqi Library for Ruby
1
+ Geoloqi Library for Ruby [![](https://secure.travis-ci.org/geoloqi/geoloqi-ruby.png)](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?
@@ -22,4 +22,4 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency 'minitest', '= 2.2.2'
23
23
  s.add_development_dependency 'webmock', '= 1.6.4'
24
24
  s.add_development_dependency 'hashie', '= 1.0.0'
25
- end
25
+ end
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Geoloqi
2
2
  def self.version
3
- '0.9.18'
3
+ '0.9.19'
4
4
  end
5
5
  end
@@ -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.18
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-07-26 00:00:00 -07:00
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.6.2
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