Permalink
Browse files

Add support for explicit logger

* also, use with_indifferent_access for options and credentials
  so keys shouldn't matter
  • Loading branch information...
mtodd committed Mar 1, 2011
1 parent 98e6725 commit 2d6a87ac6e9ad438855e3c4fa532bfd80a4e537b
Showing with 92 additions and 5 deletions.
  1. +4 −3 lib/pingdom/client.rb
  2. +1 −1 spec/pingdom-client_spec.rb
  3. +3 −1 spec/spec_helper.rb
  4. +84 −0 spec/test.log
View
@@ -5,19 +5,20 @@ class Client
attr_accessor :limit
- def initialize(credentials = {})
+ def initialize(options = {})
+ @options = options.with_indifferent_access
@connection = Faraday::Connection.new(:url => "https://api/pingdom.com/api/2.0/") do |builder|
builder.url_prefix = "https://api.pingdom.com/api/2.0"
- builder.adapter :logger
+ builder.adapter :logger, @options[:logger]
builder.adapter :excon
# builder.use Gzip # TODO: write GZip response handler, add Accept-Encoding: gzip header
builder.response :yajl
builder.use Tinder::FaradayResponse::WithIndifferentAccess
- builder.basic_auth credentials[:username], credentials[:password]
+ builder.basic_auth @options[:username], @options[:password]
end
end
@@ -1,7 +1,7 @@
require 'spec_helper'
describe Pingdom::Client do
- let(:client){ Pingdom::Client.new(CREDENTIALS) }
+ let(:client){ Pingdom::Client.new(CREDENTIALS.merge(:logger => LOGGER)) }
describe "#test!" do
it "should test a single endpoint" do
View
@@ -3,6 +3,8 @@
require 'bundler/setup'
require 'pingdom-client'
+require 'logger'
require 'rspec'
-CREDENTIALS = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'credentials.yml')).inject({}){ |h,(k,v)| h[k.to_sym] = v; h }
+LOGGER = Logger.new(File.join(File.dirname(__FILE__), 'test.log'))
+CREDENTIALS = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'credentials.yml')).with_indifferent_access
View
@@ -0,0 +1,84 @@
+I, [2011-03-01T18:12:05.112878 #47853] INFO -- : get https://api.pingdom.com/api/2.0/single?type=http&host=pingdom.com
+D, [2011-03-01T18:12:05.113063 #47853] DEBUG -- request: authorization: "Basic bGJlcm5zdGVpbkBkZW1hbmRiYXNlLmNvbTpZekJsWVdJNVpHUTA="
+I, [2011-03-01T18:12:06.832192 #47853] INFO -- Status: 200
+D, [2011-03-01T18:12:06.832352 #47853] DEBUG -- response: x-powered-by: "PHP/5.3.2-1ubuntu4.7"
+connection: "close"
+content-type: "application/json; charset=utf-8"
+server: "Apache/2.2.14 (Ubuntu)"
+req-limit-short: "Remaining: 993 Time until reset: 3444"
+date: "Tue, 01 Mar 2011 23:12:05 GMT"
+server-time: "1299021126"
+content-length: "125"
+req-limit-long: "Remaining: 4768 Time until reset: 65107"
+cache-control: "no-cache"
+vary: "Accept-Encoding"
+I, [2011-03-01T18:12:06.834581 #47853] INFO -- : get https://api.pingdom.com/api/2.0/checks
+D, [2011-03-01T18:12:06.834704 #47853] DEBUG -- request: authorization: "Basic bGJlcm5zdGVpbkBkZW1hbmRiYXNlLmNvbTpZekJsWVdJNVpHUTA="
+I, [2011-03-01T18:12:07.669780 #47853] INFO -- Status: 200
+D, [2011-03-01T18:12:07.670133 #47853] DEBUG -- response: x-powered-by: "PHP/5.3.2-1ubuntu4.7"
+connection: "close"
+content-type: "application/json; charset=utf-8"
+server: "Apache/2.2.14 (Ubuntu)"
+req-limit-short: "Remaining: 992 Time until reset: 3442"
+date: "Tue, 01 Mar 2011 23:12:07 GMT"
+server-time: "1299021127"
+content-length: "290"
+req-limit-long: "Remaining: 4767 Time until reset: 65105"
+cache-control: "no-cache"
+vary: "Accept-Encoding"
+I, [2011-03-01T18:12:07.714023 #47853] INFO -- : get https://api.pingdom.com/api/2.0/single?type=http&host=pingdom.com
+D, [2011-03-01T18:12:07.714255 #47853] DEBUG -- request: authorization: "Basic bGJlcm5zdGVpbkBkZW1hbmRiYXNlLmNvbTpZekJsWVdJNVpHUTA="
+I, [2011-03-01T18:12:08.705458 #47853] INFO -- Status: 200
+D, [2011-03-01T18:12:08.705633 #47853] DEBUG -- response: x-powered-by: "PHP/5.3.2-1ubuntu4.7"
+connection: "close"
+content-type: "application/json; charset=utf-8"
+server: "Apache/2.2.14 (Ubuntu)"
+req-limit-short: "Remaining: 991 Time until reset: 3441"
+date: "Tue, 01 Mar 2011 23:12:08 GMT"
+server-time: "1299021128"
+content-length: "129"
+req-limit-long: "Remaining: 4766 Time until reset: 65104"
+cache-control: "no-cache"
+vary: "Accept-Encoding"
+I, [2011-03-01T18:12:08.708341 #47853] INFO -- : get https://api.pingdom.com/api/2.0/single?type=http&host=pingdom.com
+D, [2011-03-01T18:12:08.708500 #47853] DEBUG -- request: authorization: "Basic bGJlcm5zdGVpbkBkZW1hbmRiYXNlLmNvbTpZekJsWVdJNVpHUTA="
+I, [2011-03-01T18:12:09.994683 #47853] INFO -- Status: 200
+D, [2011-03-01T18:12:09.994880 #47853] DEBUG -- response: x-powered-by: "PHP/5.3.2-1ubuntu4.7"
+connection: "close"
+content-type: "application/json; charset=utf-8"
+server: "Apache/2.2.14 (Ubuntu)"
+req-limit-short: "Remaining: 990 Time until reset: 3440"
+date: "Tue, 01 Mar 2011 23:12:09 GMT"
+server-time: "1299021129"
+content-length: "132"
+req-limit-long: "Remaining: 4765 Time until reset: 65103"
+cache-control: "no-cache"
+vary: "Accept-Encoding"
+I, [2011-03-01T18:12:09.997716 #47853] INFO -- : get https://api.pingdom.com/api/2.0/single?type=http&host=pingdom.com
+D, [2011-03-01T18:12:09.997868 #47853] DEBUG -- request: authorization: "Basic bGJlcm5zdGVpbkBkZW1hbmRiYXNlLmNvbTpZekJsWVdJNVpHUTA="
+I, [2011-03-01T18:12:11.708165 #47853] INFO -- Status: 200
+D, [2011-03-01T18:12:11.708351 #47853] DEBUG -- response: x-powered-by: "PHP/5.3.2-1ubuntu4.7"
+connection: "close"
+content-type: "application/json; charset=utf-8"
+server: "Apache/2.2.14 (Ubuntu)"
+req-limit-short: "Remaining: 989 Time until reset: 3439"
+date: "Tue, 01 Mar 2011 23:12:10 GMT"
+server-time: "1299021131"
+content-length: "125"
+req-limit-long: "Remaining: 4764 Time until reset: 65102"
+cache-control: "no-cache"
+vary: "Accept-Encoding"
+I, [2011-03-01T18:12:11.710796 #47853] INFO -- : get https://api.pingdom.com/api/2.0/single?type=http&host=pingdom.com
+D, [2011-03-01T18:12:11.710908 #47853] DEBUG -- request: authorization: "Basic bGJlcm5zdGVpbkBkZW1hbmRiYXNlLmNvbTpZekJsWVdJNVpHUTA="
+I, [2011-03-01T18:12:13.696981 #47853] INFO -- Status: 200
+D, [2011-03-01T18:12:13.697129 #47853] DEBUG -- response: x-powered-by: "PHP/5.3.2-1ubuntu4.7"
+connection: "close"
+content-type: "application/json; charset=utf-8"
+server: "Apache/2.2.14 (Ubuntu)"
+req-limit-short: "Remaining: 988 Time until reset: 3437"
+date: "Tue, 01 Mar 2011 23:12:12 GMT"
+server-time: "1299021133"
+content-length: "130"
+req-limit-long: "Remaining: 4763 Time until reset: 65100"
+cache-control: "no-cache"
+vary: "Accept-Encoding"

0 comments on commit 2d6a87a

Please sign in to comment.