geoloqi 0.9.8 → 0.9.9
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/lib/geoloqi/config.rb +1 -1
- data/lib/geoloqi/session.rb +8 -2
- data/lib/geoloqi/version.rb +1 -1
- data/spec/geoloqi_spec.rb +38 -0
- metadata +2 -2
data/lib/geoloqi/config.rb
CHANGED
data/lib/geoloqi/session.rb
CHANGED
@@ -78,7 +78,7 @@ module Geoloqi
|
|
78
78
|
|
79
79
|
# expires_at is likely incorrect. I'm chopping 5 seconds
|
80
80
|
# off to allow for a more graceful failover.
|
81
|
-
auth['expires_at'] =
|
81
|
+
auth['expires_at'] = auth_expires_at auth['expires_in']
|
82
82
|
self.auth = auth
|
83
83
|
self.auth
|
84
84
|
end
|
@@ -93,13 +93,19 @@ module Geoloqi
|
|
93
93
|
|
94
94
|
# expires_at is likely incorrect. I'm chopping 5 seconds
|
95
95
|
# off to allow for a more graceful failover.
|
96
|
-
auth['expires_at'] =
|
96
|
+
auth['expires_at'] = auth_expires_at auth['expires_in']
|
97
97
|
self.auth = auth
|
98
98
|
self.auth
|
99
99
|
end
|
100
100
|
|
101
101
|
private
|
102
102
|
|
103
|
+
def auth_expires_at(expires_in=nil)
|
104
|
+
# expires_at is likely incorrect. I'm chopping 5 seconds
|
105
|
+
# off to allow for a more graceful failover.
|
106
|
+
expires_in.to_i.zero? ? nil : ((Time.now + expires_in.to_i)-5).rfc2822
|
107
|
+
end
|
108
|
+
|
103
109
|
def headers
|
104
110
|
headers = {'Content-Type' => 'application/json', 'User-Agent' => "geoloqi-ruby #{Geoloqi.version}", 'Accept' => 'application/json'}
|
105
111
|
headers['Authorization'] = "OAuth #{access_token}" if access_token
|
data/lib/geoloqi/version.rb
CHANGED
data/spec/geoloqi_spec.rb
CHANGED
@@ -195,6 +195,27 @@ describe Geoloqi::Session do
|
|
195
195
|
|
196
196
|
expect { (5..10).include? (Time.rfc2822(response[:expires_at]) - (Time.now+86400)).abs }
|
197
197
|
end
|
198
|
+
|
199
|
+
it 'does not refresh when never expires' do
|
200
|
+
WebMock.disable_net_connect!
|
201
|
+
begin
|
202
|
+
response = @session.get_auth '1234', 'http://neverexpires.example.com/'
|
203
|
+
ensure
|
204
|
+
WebMock.allow_net_connect!
|
205
|
+
end
|
206
|
+
|
207
|
+
expect { @session.auth[:expires_in] == '0' }
|
208
|
+
expect { @session.auth[:expires_at].nil? }
|
209
|
+
|
210
|
+
WebMock.disable_net_connect!
|
211
|
+
begin
|
212
|
+
response = @session.get 'account/username'
|
213
|
+
ensure
|
214
|
+
WebMock.allow_net_connect!
|
215
|
+
end
|
216
|
+
expect { @session.auth[:access_token] == 'access_token1234' }
|
217
|
+
expect { response['username'] == 'bulbasaurrulzok' }
|
218
|
+
end
|
198
219
|
end
|
199
220
|
|
200
221
|
describe 'with config and expired auth' do
|
@@ -221,6 +242,18 @@ end
|
|
221
242
|
|
222
243
|
include WebMock::API
|
223
244
|
|
245
|
+
stub_request(:post, "https://api.geoloqi.com/1/oauth/token").
|
246
|
+
with(:body => {:client_id => ARGV[0],
|
247
|
+
:client_secret => ARGV[1],
|
248
|
+
:code => "1234",
|
249
|
+
:grant_type => "authorization_code",
|
250
|
+
:redirect_uri => "http://neverexpires.example.com/"}.to_json).
|
251
|
+
to_return(:status => 200,
|
252
|
+
:body => {:access_token => 'access_token1234',
|
253
|
+
:scope => nil,
|
254
|
+
:expires_in => '0',
|
255
|
+
:refresh_token => 'never_expires'}.to_json)
|
256
|
+
|
224
257
|
stub_request(:post, "https://api.geoloqi.com/1/oauth/token").
|
225
258
|
with(:body => {:client_id => ARGV[0],
|
226
259
|
:client_secret => ARGV[1],
|
@@ -244,6 +277,11 @@ stub_request(:post, "https://api.geoloqi.com/1/oauth/token").
|
|
244
277
|
:expires_in => '5000',
|
245
278
|
:refresh_token => 'refresh_token4567'}.to_json)
|
246
279
|
|
280
|
+
stub_request(:get, "https://api.geoloqi.com/1/account/username").
|
281
|
+
with(:headers => {'Authorization'=>'OAuth access_token1234'}).
|
282
|
+
to_return(:status => 200,
|
283
|
+
:body => {'username' => 'bulbasaurrulzok'}.to_json)
|
284
|
+
|
247
285
|
stub_request(:get, "https://api.geoloqi.com/1/account/username").
|
248
286
|
with(:headers => {'Authorization'=>'OAuth access_token4567'}).
|
249
287
|
to_return(:status => 200,
|
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.9
|
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-06
|
14
|
+
date: 2011-07-06 00:00:00 -07:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|