lib/toadhopper.rb in toadhopper-1.1 vs lib/toadhopper.rb in toadhopper-1.2

- old
+ new

@@ -2,20 +2,23 @@ require 'erb' require 'ostruct' # Posts errors to the Hoptoad API class Toadhopper - VERSION = "1.1" + VERSION = "1.2" FILTER_REPLACEMENT = "[FILTERED]" # Hoptoad API response class Response < Struct.new(:status, :body, :errors); end attr_reader :api_key - def initialize(api_key) - @api_key = api_key + def initialize(api_key, params = {}) + @api_key = api_key + @notify_host = params.delete(:notify_host) || "http://hoptoadapp.com" + @error_url = params.delete(:error_url) || "#{@notify_host}/notifier_api/v2/notices" + @deploy_url = params.delete(:deploy_url) || "#{@notify_host}/deploys.txt" end # Sets patterns to +[FILTER]+ out sensitive data such as +/password/+, +/email/+ and +/credit_card_number/+ def filters=(*filters) @filters = filters.flatten @@ -66,11 +69,11 @@ 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) + response = Net::HTTP.post_form(URI.parse(@deploy_url), params) parse_response(response) end private @@ -102,10 +105,10 @@ def filters [@filters].flatten.compact end def post_document(document, headers={}) - uri = URI.parse("http://hoptoadapp.com:80/notifier_api/v2/notices") + uri = URI.parse(@error_url) Net::HTTP.start(uri.host, uri.port) do |http| http.read_timeout = 5 # seconds http.open_timeout = 2 # seconds begin response = http.post uri.path,