Class: Crashdesk::Reporters::Remote
- Inherits:
-
Object
- Object
- Crashdesk::Reporters::Remote
- Defined in:
- lib/crashdesk/reporters/remote.rb
Constant Summary collapse
- NOTICES_URI =
'/v1/crashes'.freeze
- HTTP_ERRORS =
[Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ECONNREFUSED].freeze
- HEADERS =
{ 'Content-type' => 'application/json', 'Accept' => 'application/json' }
Instance Attribute Summary collapse
-
#http_open_timeout ⇒ Object
readonly
Returns the value of attribute http_open_timeout.
-
#http_read_timeout ⇒ Object
readonly
Returns the value of attribute http_read_timeout.
-
#proxy_host ⇒ Object
readonly
Returns the value of attribute proxy_host.
-
#proxy_pass ⇒ Object
readonly
Returns the value of attribute proxy_pass.
-
#proxy_port ⇒ Object
readonly
Returns the value of attribute proxy_port.
-
#proxy_user ⇒ Object
readonly
Returns the value of attribute proxy_user.
-
#secure ⇒ Object
(also: #secure?)
readonly
Returns the value of attribute secure.
-
#use_system_ssl_cert_chain ⇒ Object
(also: #use_system_ssl_cert_chain?)
readonly
Returns the value of attribute use_system_ssl_cert_chain.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Remote
constructor
A new instance of Remote.
- #run(crashlog) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Remote
Returns a new instance of Remote.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/crashdesk/reporters/remote.rb', line 39 def initialize( = {}) [ :proxy_host, :proxy_port, :proxy_user, :proxy_pass, :protocol, :host, :port, :secure, :use_system_ssl_cert_chain, :http_open_timeout, :http_read_timeout ].each do |option| instance_variable_set("@#{option}", [option]) end end |
Instance Attribute Details
#http_open_timeout ⇒ Object (readonly)
Returns the value of attribute http_open_timeout.
89 90 91 |
# File 'lib/crashdesk/reporters/remote.rb', line 89 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object (readonly)
Returns the value of attribute http_read_timeout.
89 90 91 |
# File 'lib/crashdesk/reporters/remote.rb', line 89 def http_read_timeout @http_read_timeout end |
#proxy_host ⇒ Object (readonly)
Returns the value of attribute proxy_host.
89 90 91 |
# File 'lib/crashdesk/reporters/remote.rb', line 89 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object (readonly)
Returns the value of attribute proxy_pass.
89 90 91 |
# File 'lib/crashdesk/reporters/remote.rb', line 89 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object (readonly)
Returns the value of attribute proxy_port.
89 90 91 |
# File 'lib/crashdesk/reporters/remote.rb', line 89 def proxy_port @proxy_port end |
#proxy_user ⇒ Object (readonly)
Returns the value of attribute proxy_user.
89 90 91 |
# File 'lib/crashdesk/reporters/remote.rb', line 89 def proxy_user @proxy_user end |
#secure ⇒ Object (readonly) Also known as: secure?
Returns the value of attribute secure.
89 90 91 |
# File 'lib/crashdesk/reporters/remote.rb', line 89 def secure @secure end |
#use_system_ssl_cert_chain ⇒ Object (readonly) Also known as: use_system_ssl_cert_chain?
Returns the value of attribute use_system_ssl_cert_chain.
89 90 91 |
# File 'lib/crashdesk/reporters/remote.rb', line 89 def use_system_ssl_cert_chain @use_system_ssl_cert_chain end |
Instance Method Details
#run(crashlog) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/crashdesk/reporters/remote.rb', line 56 def run(crashlog) hash = crashlog.to_hash unless hash.respond_to? :to_json require 'json' unless hash.respond_to? :to_json raise StandardError.new("You need a json gem/library installed to send errors to as JSON (Object.to_json not defined). \nInstall json_pure, yajl-ruby, json-jruby, or the c-based json gem") end end data = hash.to_json http = setup_http_connection headers = HEADERS.merge('X-Crashdesk-AppKey' => Crashdesk.configuration.app_key) response = begin log "Sending crash report to #{url} with data: #{data}" http.post(url.path, data, headers) rescue *HTTP_ERRORS => e log "Unable to connect the Creashdesk server. HTTP Error=#{e}", :error nil end case response when Net::HTTPSuccess then log "Success: #{response.class} #{response}" else log "Failure: #{response.class} #{response}" end rescue => e log "Error sending: #{e.class} - #{e.}\nBacktrace:\n#{e.backtrace.join("\n\t")}", :error nil end |