Class: Batbugger::Sender
- Inherits:
-
Object
- Object
- Batbugger::Sender
- Defined in:
- lib/batbugger/sender.rb
Constant Summary collapse
- NOTICES_URI =
'/v1/notices/'.freeze
- HTTP_ERRORS =
[Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError, Errno::ECONNREFUSED].freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#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.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#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 = {}) ⇒ Sender
constructor
A new instance of Sender.
- #send_to_batbugger(notice) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Sender
Returns a new instance of Sender.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/batbugger/sender.rb', line 13 def initialize( = {}) [ :api_key, :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
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def api_key @api_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def host @host end |
#http_open_timeout ⇒ Object (readonly)
Returns the value of attribute http_open_timeout.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object (readonly)
Returns the value of attribute http_read_timeout.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def http_read_timeout @http_read_timeout end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def port @port end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def protocol @protocol end |
#proxy_host ⇒ Object (readonly)
Returns the value of attribute proxy_host.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object (readonly)
Returns the value of attribute proxy_pass.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object (readonly)
Returns the value of attribute proxy_port.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def proxy_port @proxy_port end |
#proxy_user ⇒ Object (readonly)
Returns the value of attribute proxy_user.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def proxy_user @proxy_user end |
#secure ⇒ Object (readonly) Also known as: secure?
Returns the value of attribute secure.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 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.
59 60 61 |
# File 'lib/batbugger/sender.rb', line 59 def use_system_ssl_cert_chain @use_system_ssl_cert_chain end |
Instance Method Details
#send_to_batbugger(notice) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/batbugger/sender.rb', line 31 def send_to_batbugger(notice) data = notice.is_a?(String) ? notice : notice.to_json http = setup_http_connection headers = HEADERS headers.merge!({ 'X-API-Key' => api_key}) unless api_key.nil? response = begin http.post(url.path, data, headers) rescue *HTTP_ERRORS => e log(:error, "Unable to contact the Batbugger server. HTTP Error=#{e}") nil end case response when Net::HTTPSuccess then log(Batbugger.configuration.debug ? :info : :debug, "Success: #{response.class}", response, data) JSON.parse(response.body)['id'] else log(:error, "Failure: #{response.class}", response, data) nil end rescue => e log(:error, "[Batbugger::Sender#send_to_batbugger] Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}") nil end |