lilypad 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -15,7 +15,6 @@ Use it
15
15
 
16
16
  <pre>
17
17
  require 'rack/lilypad'
18
-
19
18
  use Rack::Lilypad, 'fd48c7d26f724503a0280f808f44b339fc65fab8'
20
19
  </pre>
21
20
 
@@ -27,6 +26,23 @@ use Rack::Lilypad, 'fd48c7d26f724503a0280f808f44b339fc65fab8' do |hoptoad|
27
26
  end
28
27
  </pre>
29
28
 
29
+ In Rails, you may need to do this:
30
+
31
+ <pre>
32
+ ENV['RACK_ENV'] = ENV['RAILS_ENV']
33
+ </pre>
34
+
35
+ Debug
36
+ -----
37
+
38
+ Use the log option to see what is happening:
39
+
40
+ <pre>
41
+ use Rack::Lilypad, 'fd48c7d26f724503a0280f808f44b339fc65fab8' do |hoptoad|
42
+ hoptoad.log = '/var/www/log/hoptoad.log'
43
+ end
44
+ </pre>
45
+
30
46
  Thanks
31
47
  ------
32
48
 
data/gemspec.rb CHANGED
@@ -13,5 +13,5 @@ GEM_SPEC = Gem::Specification.new do |s|
13
13
  s.name = GEM_NAME
14
14
  s.platform = Gem::Platform::RUBY
15
15
  s.require_path = "lib"
16
- s.version = "0.1.2"
16
+ s.version = "0.1.3"
17
17
  end
data/lib/rack/lilypad.rb CHANGED
@@ -6,13 +6,15 @@ module Rack
6
6
  class Lilypad
7
7
 
8
8
  attr_accessor :filters
9
+ attr_accessor :log
9
10
 
10
11
  def initialize(app, api_key = nil)
11
12
  @app = app
12
13
  @filters = []
14
+ @log = false
13
15
  yield self if block_given?
14
16
  @filters.flatten!
15
- @hoptoad = Hoptoad.new(api_key, @filters)
17
+ @hoptoad = Hoptoad.new(api_key, @filters, @log)
16
18
  end
17
19
 
18
20
  def call(env)
@@ -29,9 +31,10 @@ module Rack
29
31
 
30
32
  class Hoptoad
31
33
 
32
- def initialize(api_key = nil, filters = [])
34
+ def initialize(api_key, filters, log)
33
35
  @api_key = api_key
34
36
  @filters = filters
37
+ @log = log
35
38
  end
36
39
 
37
40
  def backtrace(exception)
@@ -49,6 +52,10 @@ module Rack
49
52
  end
50
53
  end
51
54
 
55
+ def log(msg)
56
+ ::File.open(@log, 'a') { |f| f.write(msg) } if @log
57
+ end
58
+
52
59
  def post(exception, env)
53
60
  return unless production?
54
61
  uri = URI.parse("http://hoptoadapp.com/notices/")
@@ -59,11 +66,17 @@ module Rack
59
66
  }
60
67
  http.read_timeout = 5 # seconds
61
68
  http.open_timeout = 2 # seconds
62
- begin
69
+ response = begin
63
70
  http.post uri.path, xml(exception, env), headers
64
71
  env['hoptoad.notified'] = true
65
72
  rescue TimeoutError => e
66
73
  end
74
+ case response
75
+ when Net::HTTPSuccess then
76
+ log "Hoptoad Success: #{response.class}"
77
+ else
78
+ log "Hoptoad Failure: #{response.class}\n\n#{response.body if response.respond_to? :body}\n\n#{@@last_response}"
79
+ end
67
80
  end
68
81
  end
69
82
 
@@ -10,21 +10,34 @@ describe Rack::Lilypad do
10
10
 
11
11
  before(:each) do
12
12
  ENV['RACK_ENV'] = 'production'
13
+ @app = lambda { |env| raise TestError, 'Test' }
14
+ @env = Rack::MockRequest.env_for("/raise")
13
15
  @http = mock(:http)
14
16
  @http.stub!(:read_timeout=)
15
17
  @http.stub!(:open_timeout=)
16
- @http.stub!(:post)
18
+ @http.stub!(:post).and_return Net::HTTPSuccess
17
19
  Net::HTTP.stub!(:start).and_yield(@http)
18
20
  end
19
21
 
20
- it "yields a configuration object to the block when created" do
21
- notifier = Rack::Lilypad.new(lambda {}, '') do |app|
22
+ it "should yield a configuration object to the block when created" do
23
+ notifier = Rack::Lilypad.new(@app, '') do |app|
22
24
  app.filters << %w(T1 T2)
23
25
  end
24
26
  notifier.filters.should include('T1')
25
27
  notifier.filters.should include('T2')
26
28
  end
27
29
 
30
+ it "should write to a log if specified" do
31
+ path = "#{SPEC}/fixtures/hoptoad.log"
32
+ notifier = Rack::Lilypad.new(@app, '') do |app|
33
+ app.log = path
34
+ end
35
+ notifier.call(@env) rescue nil
36
+ File.exists?(path).should == true
37
+ File.delete path
38
+ File.exists?(path).should == false
39
+ end
40
+
28
41
  it "should post an error to Hoptoad" do
29
42
  @http.should_receive(:post)
30
43
  get "/raise" rescue nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lilypad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Winton Welsh