Permalink
Browse files

Use the logging gem to log things in debug mode

  • Loading branch information...
1 parent 8e938e6 commit 50a1b8a85c3615cb6e538baedf13644d32b50335 @mcmire committed Dec 19, 2011
View
@@ -3,6 +3,7 @@ PATH
specs:
address-standardization (0.4.1)
httparty (~> 0.8.1)
+ logging
mechanize (= 2.0.0)
GEM
@@ -12,6 +13,9 @@ GEM
httparty (0.8.1)
multi_json
multi_xml
+ little-plugger (1.1.3)
+ logging (1.6.1)
+ little-plugger (>= 1.1.2)
mechanize (2.0)
net-http-digest_auth (~> 1.1, >= 1.1.1)
net-http-persistent (~> 1.8)
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
# 2.0.1 contains a bug, hardcode to 2.0.0 for now until 2.1 comes out
gem.add_runtime_dependency('mechanize', '2.0.0')
gem.add_runtime_dependency('httparty', '~> 0.8.1')
+ gem.add_runtime_dependency('logging', '~> 1.6.1')
gem.add_development_dependency('rspec', '~> 2.7.0')
end
@@ -1,5 +1,7 @@
# address_standardization: A tiny Ruby library to quickly standardize a postal address.
-# Copyright (C) 2008-2010 Elliot Winkler. Released under the MIT license.
+# Copyright (C) 2008-2011 Elliot Winkler. Released under the MIT license.
+
+require 'logging'
# TODO: Force users to require MelissaData or GoogleMaps manually
# so that no dependency is required without being unused
@@ -24,14 +26,11 @@ class << self
attr_accessor :test_mode
alias_method :test_mode?, :test_mode
- attr_accessor :debug_mode
- alias_method :debug_mode?, :debug_mode
-
- def debug(*args)
- puts(*args) if debug_mode?
+ def logger
+ Logging.logger[self]
end
end
self.test_mode = false
- self.debug_mode = $DEBUG || ENV["DEBUG"] || false
+ logger.level = ($DEBUG || ENV['DEBUG']) ? :debug : :info
end
@@ -26,6 +26,14 @@ def get_canned_response(address_info)
response = (self.canned_response ||= :success)
response == :success ? Address.new(address_info) : nil
end
+
+ def get_live_response
+ raise NotImplementedError
+ end
+
+ def logger
+ AddressStandardization.logger
+ end
end
end
end
@@ -31,13 +31,13 @@ def get_live_response(address_info)
}
)
data = resp.parsed_response
- AddressStandardization.debug <<EOT
+ logger.debug <<EOT
[GoogleMaps] Response body:
--------------------------------------------------------------------------------
#{resp.body}
--------------------------------------------------------------------------------
EOT
- AddressStandardization.debug <<EOT
+ logger.debug <<EOT
[GoogleMaps] Parsed response:
--------------------------------------------------------------------------------
#{data}
@@ -18,31 +18,29 @@ def get_live_response(address_info)
url << "?" + params.join("&")
url << "&FindAddress=Submit"
- # puts "URL: <#{url}>"
-
addr = Address.new(
:country => (is_canada ? "Canada" : "United States")
)
ua = Mechanize.new
- AddressStandardization.debug "[MelissaData] Hitting URL: #{url}"
+ logger.debug "[MelissaData] Hitting URL: #{url}"
results_page = ua.get(url)
- AddressStandardization.debug "[MelissaData] Response body:"
- AddressStandardization.debug "--------------------------------------------------"
- AddressStandardization.debug results_page.body
- AddressStandardization.debug "--------------------------------------------------"
+ logger.debug "[MelissaData] Response body:"
+ logger.debug "--------------------------------------------------"
+ logger.debug results_page.body
+ logger.debug "--------------------------------------------------"
table = results_page.at("table.Tableresultborder")
unless table
- warn "Couldn't find table"
+ logger.debug "Couldn't find table"
return nil
end
status_row = table.at("div.Titresultableok")
unless status_row
- warn "Couldn't find status_row"
+ logger.debug "Couldn't find status_row"
return nil
end
unless status_row.inner_text =~ /Address Verified/
- warn "Address not verified"
+ logger.debug "Address not verified"
return nil
end
main_td = table.search("tr:eq(#{is_canada ? 2 : 3})/td:eq(2)")

0 comments on commit 50a1b8a

Please sign in to comment.