Skip to content
This repository has been archived by the owner on Jul 30, 2019. It is now read-only.

Commit

Permalink
Adds logger
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiokr committed May 14, 2013
1 parent dc768b6 commit a59d192
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ under config, and run scripts/parse_cctld_csv.
For non country code top level domains, the scripts/parse_cctld_csv `defaults`
list needs to be updated.

Debugging
---------

If you need to debug requests and responses, you can set a logger object, and
MooMoo will `debug` the request/response XMLs. Make sure the log level is set to
`debug`.

MooMoo.configure do |config|
config.logger = my_logger
end

Note on Patches/Pull Requests
-----------------------------

Expand Down
1 change: 1 addition & 0 deletions lib/moo_moo.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'moo_moo/exceptions'
require 'faraday'
require 'moo_moo/version'
require 'moo_moo/logger'
require 'moo_moo/config'
require 'moo_moo/base_command'
require 'moo_moo/middleware/open_srs_errors'
Expand Down
3 changes: 2 additions & 1 deletion lib/moo_moo/base_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def faraday_request(action, object, params)
c.request :open_srs_xml_builder, action, object, params, key, username
c.response :parse_open_srs
c.response :open_srs_errors
c.response :moo_moo_logger
c.adapter :net_http
end.post
end
Expand All @@ -102,4 +103,4 @@ def index_array(arr)
arr_indexed
end
end
end
end
1 change: 1 addition & 0 deletions lib/moo_moo/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Config
attr_accessor :username
attr_accessor :password
attr_accessor :port
attr_accessor :logger

def initialize
@host = default_option("host") || 'horizon.opensrs.net'
Expand Down
20 changes: 20 additions & 0 deletions lib/moo_moo/logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Faraday
class Response::MooMooLogger < Response::Middleware
def call(env)
debug("[MooMoo request] #{env[:body]}")
super
end

def on_complete(env)
debug("[MooMoo response] #{env[:response].body}")
end

private

def debug(msg)
MooMoo.config.logger.debug(msg) if MooMoo.config.logger
end
end
end

Faraday::Response.register_middleware(:moo_moo_logger => :MooMooLogger)
2 changes: 1 addition & 1 deletion moo_moo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.rubyforge_project = "opensrs"

s.add_runtime_dependency 'extlib', '~> 0.9.15'
s.add_runtime_dependency 'faraday', '~> 0.8.0.rc2'
s.add_runtime_dependency 'faraday', '~> 0.8.0'
s.add_runtime_dependency 'jruby-openssl', '~> 0.7.3' if RUBY_PLATFORM == 'java'

s.add_development_dependency 'rake', '~> 0.9.2.2'
Expand Down

0 comments on commit a59d192

Please sign in to comment.