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 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
@@ -22,4 +22,4 @@ module Geoloqi
22
22
  !client_secret.nil? && !client_secret.empty?
23
23
  end
24
24
  end
25
- end
25
+ end
data/lib/geoloqi/error.rb CHANGED
@@ -14,4 +14,4 @@ module Geoloqi
14
14
 
15
15
  class Error < StandardError; end
16
16
  class ArgumentError < ArgumentError; end
17
- end
17
+ end
@@ -0,0 +1,10 @@
1
+ module Geoloqi
2
+ class Response
3
+ attr_reader :status, :headers, :body
4
+ def initialize(status, headers, body)
5
+ @status = status
6
+ @headers = headers
7
+ @body = body
8
+ end
9
+ end
10
+ end
@@ -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 = @connection.send(meth) do |req|
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
@@ -1,5 +1,5 @@
1
1
  module Geoloqi
2
2
  def self.version
3
- '0.9.13'
3
+ '0.9.14'
4
4
  end
5
- end
5
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: geoloqi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.13
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