geoloqi 0.9.13 → 0.9.14
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/geoloqi.rb +2 -1
- data/lib/geoloqi/config.rb +1 -1
- data/lib/geoloqi/error.rb +1 -1
- data/lib/geoloqi/response.rb +10 -0
- data/lib/geoloqi/session.rb +15 -11
- data/lib/geoloqi/version.rb +2 -2
- metadata +2 -1
data/lib/geoloqi.rb
CHANGED
@@ -5,6 +5,7 @@ require 'faraday'
|
|
5
5
|
require 'logger'
|
6
6
|
require 'geoloqi/config'
|
7
7
|
require 'geoloqi/error'
|
8
|
+
require 'geoloqi/response'
|
8
9
|
require 'geoloqi/session'
|
9
10
|
require 'geoloqi/version'
|
10
11
|
|
@@ -25,4 +26,4 @@ module Geoloqi
|
|
25
26
|
raise "client_id required to authorize url. Pass with Geoloqi.config" unless client_id
|
26
27
|
"#{OAUTH_URL}?response_type=code&client_id=#{Rack::Utils.escape client_id}&redirect_uri=#{Rack::Utils.escape redirect_uri}"
|
27
28
|
end
|
28
|
-
end
|
29
|
+
end
|
data/lib/geoloqi/config.rb
CHANGED
data/lib/geoloqi/error.rb
CHANGED
data/lib/geoloqi/session.rb
CHANGED
@@ -40,20 +40,11 @@ module Geoloqi
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def run(meth, path, query=nil)
|
43
|
-
query = Rack::Utils.parse_query query if query.is_a?(String)
|
44
43
|
renew_access_token! if auth[:expires_at] && Time.rfc2822(auth[:expires_at]) <= Time.now && !(path =~ /^\/?oauth\/token$/)
|
45
44
|
retry_attempt = 0
|
46
45
|
|
47
46
|
begin
|
48
|
-
response =
|
49
|
-
req.url "/#{API_VERSION.to_s}/#{path.gsub(/^\//, '')}"
|
50
|
-
req.headers = headers
|
51
|
-
|
52
|
-
if query
|
53
|
-
meth == :get ? req.params = query : req.body = query.to_json
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
47
|
+
response = execute meth, path, query
|
57
48
|
hash = JSON.parse response.body
|
58
49
|
raise ApiError.new(response.status, hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error'] && !config.throw_exceptions
|
59
50
|
rescue Geoloqi::ApiError
|
@@ -69,6 +60,19 @@ module Geoloqi
|
|
69
60
|
@config.use_hashie_mash ? Hashie::Mash.new(hash) : hash
|
70
61
|
end
|
71
62
|
|
63
|
+
def execute(meth, path, query=nil)
|
64
|
+
query = Rack::Utils.parse_query query if query.is_a?(String)
|
65
|
+
raw = @connection.send(meth) do |req|
|
66
|
+
req.url "/#{API_VERSION.to_s}/#{path.gsub(/^\//, '')}"
|
67
|
+
req.headers = headers
|
68
|
+
|
69
|
+
if query
|
70
|
+
meth == :get ? req.params = query : req.body = query.to_json
|
71
|
+
end
|
72
|
+
end
|
73
|
+
Response.new raw.status, raw.headers, raw.body
|
74
|
+
end
|
75
|
+
|
72
76
|
def establish(opts={})
|
73
77
|
require 'client_id and client_secret are required to get access token' unless @config.client_id? && @config.client_secret?
|
74
78
|
auth = post 'oauth/token', {:client_id => @config.client_id,
|
@@ -103,4 +107,4 @@ module Geoloqi
|
|
103
107
|
headers
|
104
108
|
end
|
105
109
|
end
|
106
|
-
end
|
110
|
+
end
|
data/lib/geoloqi/version.rb
CHANGED
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.14
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kyle Drake
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/geoloqi.rb
|
102
102
|
- lib/geoloqi/config.rb
|
103
103
|
- lib/geoloqi/error.rb
|
104
|
+
- lib/geoloqi/response.rb
|
104
105
|
- lib/geoloqi/session.rb
|
105
106
|
- lib/geoloqi/version.rb
|
106
107
|
- license.txt
|