Parent

HoptoadNotifier::Sender

Sends out the notice to Hoptoad

Public Class Methods

new(options = {}) click to toggle source
# File lib/hoptoad_notifier/sender.rb, line 15
def initialize(options = {})
  [: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}", options[option])
  end
end

Public Instance Methods

send_to_hoptoad(data) click to toggle source

Sends the notice data off to Hoptoad for processing.

@param [String] data The XML notice to be sent off

# File lib/hoptoad_notifier/sender.rb, line 25
def send_to_hoptoad(data)
  logger.debug { "Sending request to #{url.to_s}:\n#{data}" } if logger

  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 *HTTP_ERRORS => e
               log :error, "Timeout while contacting the Hoptoad server."
               nil
             end

  case response
  when Net::HTTPSuccess then
    log :info, "Success: #{response.class}", response
  else
    log :error, "Failure: #{response.class}", response
  end

  if response && response.respond_to?(:body)
    error_id = response.body.match(%{<error-id[^>]*>(.*?)</error-id>})
    error_id[1] if error_id
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.