Class: Exceptional::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/exceptional/remote.rb

Class Method Summary collapse

Class Method Details

.call_remote(url, data) ⇒ Object



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
# File 'lib/exceptional/remote.rb', line 24

def call_remote(url, data)
  config = Exceptional::Config
  optional_proxy = Net::HTTP::Proxy(config.http_proxy_host,
                                    config.http_proxy_port,
                                    config.http_proxy_username,
                                    config.http_proxy_password)
  client = optional_proxy.new(config.remote_host, config.remote_port)
  client.open_timeout = config.http_open_timeout
  client.read_timeout = config.http_read_timeout
  client.use_ssl = config.ssl?
  client.verify_mode = OpenSSL::SSL::VERIFY_NONE if config.ssl?
  begin
    response = client.post(url, data)
    case response
      when Net::HTTPSuccess
        Exceptional.logger.info( "#{url} - #{response.message}")
        return true
      else
        Exceptional.logger.error("#{url} - #{response.code} - #{response.message}")
    end
  rescue Exception => e
    Exceptional.logger.error('Problem notifying Exceptional about the error')
    Exceptional.logger.error(e)
  end
  nil
end

.error(exception_data) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/exceptional/remote.rb', line 16

def error(exception_data)
  uniqueness_hash = exception_data.uniqueness_hash
  hash_param = uniqueness_hash.nil? ? nil: "&hash=#{uniqueness_hash}"
  url = "/api/errors?api_key=#{::Exceptional::Config.api_key}&protocol_version=#{::Exceptional::PROTOCOL_VERSION}#{hash_param}"
  compressed = Zlib::Deflate.deflate(exception_data.to_json, Zlib::BEST_SPEED)
  call_remote(url, compressed)
end

.startup_announce(startup_data) ⇒ Object



10
11
12
13
14
# File 'lib/exceptional/remote.rb', line 10

def startup_announce(startup_data)
  url = "/api/announcements?api_key=#{::Exceptional::Config.api_key}&protocol_version=#{::Exceptional::PROTOCOL_VERSION}"
  compressed = Zlib::Deflate.deflate(startup_data.to_json, Zlib::BEST_SPEED)
  call_remote(url, compressed)
end