Class: Toadhopper
- Inherits:
-
Object
- Object
- Toadhopper
- Defined in:
- lib/toadhopper.rb
Overview
Posts errors to the Airbrake API
Defined Under Namespace
Classes: BacktraceLine, Response
Constant Summary collapse
- VERSION =
'2.1'
- FILTER_REPLACEMENT =
"[FILTERED]"
- DEFAULT_DOMAIN =
'airbrake.io'
- DEFAULT_NOTIFY_HOST =
'http://'+DEFAULT_DOMAIN
- CA_FILE =
CA_FILE: Path to an updated certificate authority file, which was built from source If you provide a custom Net :transport and get erroneous SSL peer verification failures, try setting the transport’s ca_file to Toadhopper::CA_FILE
File. File.join('..', 'resources', 'ca-bundle.crt'), File.dirname(__FILE__)
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#deploy_url ⇒ Object
readonly
Returns the value of attribute deploy_url.
-
#error_url ⇒ Object
readonly
Returns the value of attribute error_url.
Instance Method Summary collapse
-
#connection(uri) ⇒ Object
Provider of the net transport used.
-
#deploy!(options = {}) ⇒ Response
Posts a deployment notification.
-
#filters=(*filters) ⇒ Object
Sets patterns to
[FILTER]
out sensitive data such as/password/
,/email/
and/credit_card_number/
. -
#initialize(api_key, params = {}) ⇒ Toadhopper
constructor
Initialize and configure a Toadhopper.
-
#post!(error, options = {}, http_headers = {}) ⇒ Response
Posts an exception to Airbrake.
- #secure? ⇒ Boolean
- #validate! ⇒ Object
- #validate_url!(sym) ⇒ Object
Constructor Details
#initialize(api_key, params = {}) ⇒ Toadhopper
Initialize and configure a Toadhopper
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/toadhopper.rb', line 33 def initialize(api_key, params = {}) @filters = [] @api_key = api_key notify_host = URI.parse(params[:notify_host] || DEFAULT_NOTIFY_HOST) @transport = params.delete :transport if @transport and not params[:notify_host] notify_host.scheme = 'https' if @transport.use_ssl? notify_host.host = @transport.address notify_host.port = @transport.port end @error_url = URI.parse(params.delete(:error_url) || "#{notify_host}/notifier_api/v2/notices") @deploy_url = URI.parse(params.delete(:deploy_url) || "#{notify_host}/deploys.txt") validate! end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
22 23 24 |
# File 'lib/toadhopper.rb', line 22 def api_key @api_key end |
#deploy_url ⇒ Object (readonly)
Returns the value of attribute deploy_url.
22 23 24 |
# File 'lib/toadhopper.rb', line 22 def deploy_url @deploy_url end |
#error_url ⇒ Object (readonly)
Returns the value of attribute error_url.
22 23 24 |
# File 'lib/toadhopper.rb', line 22 def error_url @error_url end |
Instance Method Details
#connection(uri) ⇒ Object
Provider of the net transport used
MIT Licensing Note: Portions of logic below for connecting via SSL were copied from the airbrake project under the MIT License.
144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/toadhopper.rb', line 144 def connection(uri) return @transport if @transport http = Net::HTTP.new(uri.host, uri.port) http.read_timeout = 5 # seconds http.open_timeout = 2 # seconds if uri.scheme.eql? 'https' http.use_ssl = true http.ca_file = CA_FILE http.verify_mode = OpenSSL::SSL::VERIFY_PEER end http end |
#deploy!(options = {}) ⇒ Response
Posts a deployment notification
124 125 126 127 128 129 130 131 132 |
# File 'lib/toadhopper.rb', line 124 def deploy!(={}) params = {} params['api_key'] = @api_key params['deploy[rails_env]'] = [:framework_env] || 'development' params['deploy[local_username]'] = [:username] || %x(whoami).strip params['deploy[scm_repository]'] = [:scm_repository] params['deploy[scm_revision]'] = [:scm_revision] response(@deploy_url, params) end |
#filters=(*filters) ⇒ Object
Sets patterns to [FILTER]
out sensitive data such as /password/
, /email/
and /credit_card_number/
80 81 82 |
# File 'lib/toadhopper.rb', line 80 def filters=(*filters) @filters = filters.flatten end |
#post!(error, options = {}, http_headers = {}) ⇒ Response
Posts an exception to Airbrake.
110 111 112 113 |
# File 'lib/toadhopper.rb', line 110 def post!(error, ={}, http_headers={}) [:notifier_name] ||= 'Toadhopper' post_document(document_for(error, ), {'X-Airbrake-Client-Name' => [:notifier_name]}) end |
#secure? ⇒ Boolean
134 135 136 |
# File 'lib/toadhopper.rb', line 134 def secure? connection(@deploy_url).use_ssl? and connection(@error_url).use_ssl? end |
#validate! ⇒ Object
51 52 53 54 |
# File 'lib/toadhopper.rb', line 51 def validate! validate_url! :error_url validate_url! :deploy_url end |
#validate_url!(sym) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/toadhopper.rb', line 56 def validate_url!(sym) url = instance_variable_get '@'+sym.to_s unless url.absolute? raise ToadhopperException, "#{sym} #{url.inspect} must begin with http:// or https://" end if @transport if @transport.use_ssl? != url.scheme.eql?('https') raise ToadhopperException, ":transport use_ssl? setting of #{@transport.use_ssl?.inspect} does not match" + " #{sym} scheme #{url.scheme.inspect}" elsif @transport.address != url.host raise ToadhopperException, ":transport hostname #{@transport.address.inspect} does not match" + " #{sym} hostname #{url.host.inspect}" elsif @transport.port != url.port raise ToadhopperException, ":transport port #{@transport.port.inspect} does not match" + " #{sym} port #{url.port.inspect}" end end end |