Class: Toadhopper

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

Overview

Posts errors to the Airbrake API

Defined Under Namespace

Classes: BacktraceLine, Response

Constant Summary collapse

VERSION =
"2.0"
FILTER_REPLACEMENT =
"[FILTERED]"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, params = {}) ⇒ Toadhopper

Returns a new instance of Toadhopper.



15
16
17
18
19
20
# File 'lib/toadhopper.rb', line 15

def initialize(api_key, params = {})
  @api_key     = api_key
  @notify_host = params.delete(:notify_host) || "http://airbrakeapp.com"
  @error_url   = params.delete(:error_url)   || "#{@notify_host}/notifier_api/v2/notices"
  @deploy_url  = params.delete(:deploy_url)  || "#{@notify_host}/deploys.txt"
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



13
14
15
# File 'lib/toadhopper.rb', line 13

def api_key
  @api_key
end

Instance Method Details

#deploy!(options = {}) ⇒ Response

Posts a deployment notification

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • framework_env (String)

    The framework environment your app is running under, defaults to development

  • scm_repository (String)

    The repository URL

  • scm_revision (String)

    The current repository revision

  • username (String)

    Your name, defaults to ‘whoami`

Returns:



67
68
69
70
71
72
73
74
75
76
# File 'lib/toadhopper.rb', line 67

def deploy!(options={})
  params = {}
  params['api_key'] = @api_key
  params['deploy[rails_env]'] = options[:framework_env] || 'development'
  params['deploy[local_username]'] = options[:username] || %x(whoami).strip
  params['deploy[scm_repository]'] = options[:scm_repository]
  params['deploy[scm_revision]'] = options[:scm_revision]
  response = Net::HTTP.post_form(URI.parse(@deploy_url), params)
  parse_response(response)
end

#filters=(*filters) ⇒ Object

Sets patterns to [FILTER] out sensitive data such as /password/, /email/ and /credit_card_number/



23
24
25
# File 'lib/toadhopper.rb', line 23

def filters=(*filters)
  @filters = filters.flatten
end

#post!(error, options = {}, http_headers = {}) ⇒ Response

Posts an exception to Airbrake.

Examples:

Toadhopper('apikey').post! error,
                           {:action => 'show', :controller => 'Users'},
                           {'X-Airbrake-Client-Name' => 'My Awesome Notifier'}

Parameters:

  • error (Exception)

    the error to post

  • options (Hash) (defaults to: {})
  • http_headers (Hash) (defaults to: {})

    extra HTTP headers to be sent in the post to the API

Options Hash (options):

  • url (String)

    The url for the request, required to post but not useful in a console environment

  • component (String)

    Normally this is your Controller name in an MVC framework

  • action (String)

    Normally the action for your request in an MVC framework

  • params (Hash)

    A hash of the request’s parameters

  • notifier_name (String)

    Say you’re a different notifier than Toadhopper

  • notifier_version (String)

    Specify the version of your custom notifier

  • notifier_url (String)

    Specify the project URL of your custom notifier

  • session (Hash)

    A hash of the user session in a web request

  • framework_env (String)

    The framework environment your app is running under

  • backtrace (Array)

    Normally not needed, parsed automatically from the provided exception parameter

  • environment (Hash)

    You MUST scrub your environment if you plan to use this, please do not use it though. :)

  • project_root (String)

    The root directory of your app

Returns:



53
54
55
56
# File 'lib/toadhopper.rb', line 53

def post!(error, options={}, http_headers={})
  options[:notifier_name] ||= 'Toadhopper'
  post_document(document_for(error, options), {'X-Airbrake-Client-Name' => options[:notifier_name]})
end