Skip to content

Commit

Permalink
Load defaults before passed arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kyledrake committed Jul 18, 2011
1 parent c9e4266 commit 9b40955
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/geoloqi/config.rb
Expand Up @@ -2,10 +2,10 @@ module Geoloqi
class Config
attr_accessor :client_id, :client_secret, :redirect_uri, :adapter, :enable_logging, :use_hashie_mash, :throw_exceptions
def initialize(opts={})
opts.each {|k,v| send("#{k}=", v)}
self.enable_logging ||= false
self.use_hashie_mash ||= false
self.throw_exceptions ||= true
opts.each {|k,v| send("#{k}=", v)}
begin
require 'hashie' if self.use_hashie_mash && !defined?(Hashie::Mash)
rescue LoadError
Expand Down
2 changes: 1 addition & 1 deletion lib/geoloqi/session.rb
Expand Up @@ -46,7 +46,7 @@ def run(meth, path, query=nil)
begin
response = execute meth, path, query
hash = JSON.parse response.body
raise ApiError.new(response.status, hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error'] && !config.throw_exceptions
raise ApiError.new(response.status, hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error'] && @config.throw_exceptions
rescue Geoloqi::ApiError
raise Error.new('Unable to procure fresh access token from API on second attempt') if retry_attempt > 0
if hash['error'] == 'expired_token'
Expand Down
4 changes: 2 additions & 2 deletions lib/geoloqi/version.rb
@@ -1,5 +1,5 @@
module Geoloqi
def self.version
'0.9.14'
'0.9.15'
end
end
end
6 changes: 6 additions & 0 deletions spec/geoloqi_spec.rb
Expand Up @@ -76,6 +76,12 @@
end
end

describe 'with access token and throw exceptions not set' do
it 'should throw api error exception' do
expect { rescuing {Geoloqi::Session.new(:access_token => 'access_token1234').get('badmethodcall')}.class == Geoloqi::ApiError }
end
end

describe 'with access token and throw exceptions false' do
before do
@session = Geoloqi::Session.new :access_token => 'access_token1234', :config => {:throw_exceptions => false}
Expand Down

0 comments on commit 9b40955

Please sign in to comment.