toadhopper 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/.yardopts +0 -1
  2. data/lib/toadhopper.rb +32 -38
  3. metadata +3 -3
data/.yardopts CHANGED
@@ -1,4 +1,3 @@
1
- --no-private
2
1
  -r
3
2
  README.md
4
3
  -
data/lib/toadhopper.rb CHANGED
@@ -4,7 +4,7 @@ require 'ostruct'
4
4
 
5
5
  # Posts errors to the Hoptoad API
6
6
  class Toadhopper
7
- VERSION = "1.0.1"
7
+ VERSION = "1.0.2"
8
8
 
9
9
  # Hoptoad API response
10
10
  class Response < Struct.new(:status, :body, :errors); end
@@ -20,11 +20,6 @@ class Toadhopper
20
20
  @filters = filters.flatten
21
21
  end
22
22
 
23
- # @private
24
- def filters
25
- [@filters].flatten.compact
26
- end
27
-
28
23
  # Posts an exception to hoptoad.
29
24
  #
30
25
  # @param [Exception] error the error to post
@@ -56,32 +51,6 @@ class Toadhopper
56
51
  post_document(document_for(error, options), {'X-Hoptoad-Client-Name' => options[:notifier_name]})
57
52
  end
58
53
 
59
- # @private
60
- def post_document(document, headers={})
61
- uri = URI.parse("http://hoptoadapp.com:80/notifier_api/v2/notices")
62
- Net::HTTP.start(uri.host, uri.port) do |http|
63
- http.read_timeout = 5 # seconds
64
- http.open_timeout = 2 # seconds
65
- begin
66
- response = http.post uri.path,
67
- document,
68
- {'Content-type' => 'text/xml', 'Accept' => 'text/xml, application/xml'}.merge(headers)
69
- Response.new response.code.to_i,
70
- response.body,
71
- response.body.scan(%r{<error>(.+)<\/error>}).flatten
72
- rescue TimeoutError => e
73
- Response.new(500, '', ['Timeout error'])
74
- end
75
- end
76
- end
77
-
78
- # @private
79
- def document_for(exception, options={})
80
- data = document_data(exception, options)
81
- scope = OpenStruct.new(data).extend(ERB::Util)
82
- scope.instance_eval ERB.new(notice_template, nil, '-').src
83
- end
84
-
85
54
  def document_defaults(error)
86
55
  {
87
56
  :error => error,
@@ -107,17 +76,44 @@ class Toadhopper
107
76
  data
108
77
  end
109
78
 
110
- # @private
79
+ private
80
+
81
+ def filters
82
+ [@filters].flatten.compact
83
+ end
84
+
85
+ def post_document(document, headers={})
86
+ uri = URI.parse("http://hoptoadapp.com:80/notifier_api/v2/notices")
87
+ Net::HTTP.start(uri.host, uri.port) do |http|
88
+ http.read_timeout = 5 # seconds
89
+ http.open_timeout = 2 # seconds
90
+ begin
91
+ response = http.post uri.path,
92
+ document,
93
+ {'Content-type' => 'text/xml', 'Accept' => 'text/xml, application/xml'}.merge(headers)
94
+ Response.new response.code.to_i,
95
+ response.body,
96
+ response.body.scan(%r{<error>(.+)<\/error>}).flatten
97
+ rescue TimeoutError => e
98
+ Response.new(500, '', ['Timeout error'])
99
+ end
100
+ end
101
+ end
102
+
103
+ def document_for(exception, options={})
104
+ data = document_data(exception, options)
105
+ scope = OpenStruct.new(data).extend(ERB::Util)
106
+ scope.instance_eval ERB.new(notice_template, nil, '-').src
107
+ end
108
+
111
109
  def backtrace_line(line)
112
- Struct.new(:file, :number, :method).new(*line.match(%r{^([^:]+):(\d+)(?::in `([^']+)')?$}).captures)
110
+ Struct.new(:file, :number, :method).new(*line.match(%r{^(.+):(\d+)(?::in `([^']+)')?$}).captures)
113
111
  end
114
112
 
115
- # @private
116
113
  def notice_template
117
114
  File.read(::File.join(::File.dirname(__FILE__), 'notice.erb'))
118
115
  end
119
116
 
120
- # @private
121
117
  def clean(hash)
122
118
  hash.inject({}) do |acc, (k, v)|
123
119
  acc[k] = (v.is_a?(Hash) ? clean(v) : filtered_value(k,v)) if serializable?(v)
@@ -125,7 +121,6 @@ class Toadhopper
125
121
  end
126
122
  end
127
123
 
128
- # @private
129
124
  def filtered_value(key, value)
130
125
  if filters.any? {|f| key.to_s =~ Regexp.new(f)}
131
126
  "[FILTERED]"
@@ -134,7 +129,6 @@ class Toadhopper
134
129
  end
135
130
  end
136
131
 
137
- # @private
138
132
  def serializable?(value)
139
133
  [Fixnum, Array, String, Hash, Bignum].any? {|c| value.is_a?(c)}
140
134
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tim Lucas
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-03-23 00:00:00 -07:00
20
+ date: 2010-03-24 00:00:00 -07:00
21
21
  default_executable:
22
22
  dependencies: []
23
23