geoloqi 0.9.10 → 0.9.11

Sign up to get free protection for your applications and to get access to all the features.
data/lib/geoloqi/error.rb CHANGED
@@ -1,16 +1,17 @@
1
1
  module Geoloqi
2
2
  class ApiError < StandardError
3
- attr_reader :type
4
- attr_reader :reason
5
- def initialize(type, reason=nil)
3
+ attr_reader :status, :type, :reason
4
+ def initialize(status, type, reason=nil)
5
+ @status = status
6
6
  @type = type
7
7
  @reason = reason
8
8
  message = type
9
9
  message += " - #{reason}" if reason
10
+ message += " (#{status})"
10
11
  super message
11
12
  end
12
13
  end
13
14
 
14
15
  class Error < StandardError; end
15
16
  class ArgumentError < ArgumentError; end
16
- end
17
+ end
@@ -55,7 +55,7 @@ module Geoloqi
55
55
  end
56
56
 
57
57
  hash = JSON.parse response.body
58
- raise ApiError.new(hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error']
58
+ raise ApiError.new(response.status, hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error']
59
59
  rescue Geoloqi::ApiError
60
60
  raise Error.new('Unable to procure fresh access token from API on second attempt') if retry_attempt > 0
61
61
  if hash['error'] == 'expired_token'
@@ -1,5 +1,5 @@
1
1
  module Geoloqi
2
2
  def self.version
3
- '0.9.10'
3
+ '0.9.11'
4
4
  end
5
5
  end
data/spec/geoloqi_spec.rb CHANGED
@@ -28,10 +28,11 @@ end
28
28
 
29
29
  describe Geoloqi::ApiError do
30
30
  it 'throws exception properly and allows drill-down of message' do
31
- error = Geoloqi::ApiError.new 'not_enough_cats', 'not enough cats to complete this request'
31
+ error = Geoloqi::ApiError.new 405, 'not_enough_cats', 'not enough cats to complete this request'
32
+ expect { error.status == 405 }
32
33
  expect { error.type == 'not_enough_cats' }
33
34
  expect { error.reason == 'not enough cats to complete this request' }
34
- expect { error.message == "#{error.type} - #{error.reason}" }
35
+ expect { error.message == "#{error.type} - #{error.reason} (405)" }
35
36
  end
36
37
  end
37
38
 
@@ -182,7 +183,14 @@ describe Geoloqi::Session do
182
183
  end
183
184
 
184
185
  it 'fails with an exception' do
185
- expect { rescuing { @session.get 'message/send' }.message == 'invalid_token' }
186
+ begin
187
+ @session.get 'message/send'
188
+ rescue Exception => e
189
+ expect { e.class == Geoloqi::ApiError }
190
+ expect { e.status == 401 }
191
+ expect { e.type == 'invalid_token' }
192
+ expect { e.message == 'invalid_token (401)' }
193
+ end
186
194
  end
187
195
  end
188
196
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: geoloqi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.10
5
+ version: 0.9.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kyle Drake