Class: Ribbit::Sender
- Inherits:
-
Object
- Object
- Ribbit::Sender
- Defined in:
- lib/ribbit/sender.rb
Overview
Sends out the notice to Hoptoad
Constant Summary collapse
- NOTICES_URI =
'/notifier_api/v2/notices/'.freeze
- HEADERS =
{ 'Content-type' => 'text/xml', 'Accept' => 'text/xml, application/xml' }
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Sender
constructor
A new instance of Sender.
-
#send_to_hoptoad(data) ⇒ Object
Sends the notice data off to Hoptoad for processing.
Constructor Details
#initialize(options = {}) ⇒ Sender
Returns a new instance of Sender.
14 15 16 17 18 19 |
# File 'lib/ribbit/sender.rb', line 14 def initialize( = {}) [:proxy_host, :proxy_port, :proxy_user, :proxy_pass, :protocol, :host, :port, :secure, :http_open_timeout, :http_read_timeout].each do |option| instance_variable_set("@#{option}", [option]) end end |
Instance Method Details
#send_to_hoptoad(data) ⇒ Object
Sends the notice data off to Hoptoad for processing.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ribbit/sender.rb', line 24 def send_to_hoptoad(data) log :debug, "Sending request to #{url.to_s}:\n#{data}" http = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass). new(url.host, url.port) http.read_timeout = http_read_timeout http.open_timeout = http_open_timeout http.use_ssl = secure response = begin http.post(url.path, data, HEADERS) rescue TimeoutError => e log :error, "Timeout while contacting the Hoptoad server." nil end case response when Net::HTTPSuccess then log :info, "Success: #{response.class}" log :debug, "Response Body: #{response.body}" else log :error, "Failure: #{response.class}" log :debug, "Response Body: #{response.body}" end end |