Permalink
Browse files

Much better logging style (with tests)

  • Loading branch information...
1 parent a1b0aae commit 2b522d0eed66da0d1ad83ec771c1fa6dcf1f00b6 @kyledrake kyledrake committed Aug 29, 2011
Showing with 15 additions and 9 deletions.
  1. +1 −3 lib/geoloqi/config.rb
  2. +1 −2 lib/geoloqi/session.rb
  3. +1 −1 lib/geoloqi/version.rb
  4. +12 −3 spec/geoloqi_spec.rb
View
@@ -1,8 +1,7 @@
module Geoloqi
class Config
- attr_accessor :client_id, :client_secret, :redirect_uri, :adapter, :enable_logging, :use_hashie_mash, :throw_exceptions
+ attr_accessor :client_id, :client_secret, :redirect_uri, :adapter, :logger, :use_hashie_mash, :throw_exceptions
def initialize(opts={})
- self.enable_logging ||= false
self.use_hashie_mash ||= false
self.throw_exceptions ||= true
opts.each {|k,v| send("#{k}=", v)}
@@ -11,7 +10,6 @@ def initialize(opts={})
rescue LoadError
raise Error, "You've requested Hashie::Mash, but the gem is not available. Don't set use_hashie_mash in your config, or install the hashie gem"
end
- raise ArgumentError, 'enable_logging must be boolean' unless [true, false].include? self.enable_logging
end
def client_id?
View
@@ -10,7 +10,6 @@ def initialize(opts={})
self.auth[:access_token] = opts[:access_token] if opts[:access_token]
@connection = Faraday.new(:url => Geoloqi.api_url) do |builder|
- # builder.response :logger if @config.enable_logging
builder.adapter @config.adapter || :net_http
end
end
@@ -72,7 +71,7 @@ def execute(meth, path, query=nil)
meth == :get ? req.params = query : req.body = query.to_json
end
end
- puts "Geoloqi::Session - #{meth} #{path}?#{Rack::Utils.build_query query} :\n#{raw.status}\n#{raw.headers}\n#{raw.body}" if @config.enable_logging
+ @config.logger.puts "Geoloqi::Session - #{meth.to_s.upcase} #{path}?#{Rack::Utils.build_query query}:\nStatus: #{raw.status}\nHeaders: #{raw.headers.inspect}\n#{raw.body}" if @config.logger
Response.new raw.status, raw.headers, raw.body
end
View
@@ -1,5 +1,5 @@
module Geoloqi
def self.version
- '0.9.23'
+ '0.9.24'
end
end
View
@@ -90,10 +90,19 @@ def api_url(path); "#{Geoloqi.api_url}/#{Geoloqi.api_version}/#{path}" end
"redirect_uri=#{Rack::Utils.escape 'http://blah.blah/test'}" }
end
end
-
- it 'throws exception if non-boolean value is fed to logging' do
- expect { rescuing { Geoloqi.config(:client_id => '', :client_secret => '', :enable_logging => :cats )}.class == Geoloqi::ArgumentError }
+
+ it 'displays log information if logger is provided' do
+ stub_request(:get, api_url('account/username?cats=lol')).
+ with(:headers => {'Authorization'=>'OAuth access_token1234'}).
+ to_return(:body => {'username' => 'bulbasaurrulzok'}.to_json)
+
+ io = StringIO.new
+ Geoloqi.config :client_id => CLIENT_ID, :client_secret => CLIENT_SECRET, :logger => io
+
+ Geoloqi.get ACCESS_TOKEN, 'account/username', :cats => 'lol'
+ expect { io.string =~ /Geoloqi::Session/ }
end
+
it 'correctly checks booleans for client_id and client_secret' do
[:client_id, :client_secret].each do |k|

0 comments on commit 2b522d0

Please sign in to comment.