Class: Toadhopper

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

Overview

Posts errors to the Hoptoad API

Defined Under Namespace

Classes: BacktraceLine, Response

Constant Summary collapse

VERSION =
"1.1"
FILTER_REPLACEMENT =
"[FILTERED]"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Toadhopper

Returns a new instance of Toadhopper.



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

def initialize(api_key)
  @api_key = api_key
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:



64
65
66
67
68
69
70
71
72
73
# File 'lib/toadhopper.rb', line 64

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('http://hoptoadapp.com/deploys.txt'), params)
  parse_response(response)
end

#filters=(*filters) ⇒ Object

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



20
21
22
# File 'lib/toadhopper.rb', line 20

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

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

Posts an exception to hoptoad.

Examples:

Toadhopper('apikey').post! error,
                           {:action => 'show', :controller => 'Users'},
                           {'X-Hoptoad-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:



50
51
52
53
# File 'lib/toadhopper.rb', line 50

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