airbrake 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,21 @@
1
+ Version 3.1.6 - 2012-10-23 21:15:50 +0200
2
+ ===============================================================================
3
+
4
+ Hrvoje Šimić (9):
5
+ load api key from file and env if not provided for executable
6
+ get a list of your projects from command line
7
+ create projects from command line
8
+ fix cli client host
9
+ creating deploys from command line
10
+ don't override extension methods
11
+ update heroku plan in readme
12
+ another fix for heroku readme
13
+ don't pollute global namespace with blank?
14
+
15
+ Sam Umbach (1):
16
+ Send deploy notification on deploy:cold
17
+
18
+
1
19
  Version 3.1.5 - 2012-10-05 17:32:23 +0200
2
20
  ===============================================================================
3
21
 
@@ -923,3 +941,4 @@ Nick Quaranto (3):
923
941
 
924
942
 
925
943
 
944
+
@@ -7,8 +7,8 @@ Send your application errors to our hosted service and reclaim your inbox.
7
7
  ----------------------------
8
8
  To use Airbrake on Heroku, install the Airbrake add-on:
9
9
 
10
- $ heroku addons:add airbrake:basic # This adds the the basic plan.
11
- # If you'd like another plan, specify that instead.
10
+ $ heroku addons:add airbrake:developer # If you'd like another plan, specify that instead.
11
+ # Check https://addons.heroku.com/airbrake for a full list of plans.
12
12
 
13
13
  2. Including the Airbrake notifier in your application
14
14
  --------------------------------------------------
@@ -1,46 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
- require "airbrake"
3
2
 
4
- def parse_options(array = [])
5
- opts = Hash[*array]
6
- opts[:error] = opts.delete("-e") || opts.delete("--error") { RuntimeError }
7
- opts[:message] = opts.delete("-m") || opts.delete("--message") { "I've made a huge mistake" }
8
- opts[:api_key] = opts.delete("-k") || opts.delete("--api-key")
9
- opts[:host] = opts.delete("-h") || opts.delete("--host")
10
- opts[:port] = opts.delete("-p") || opts.delete("--port")
11
- opts
12
- end
3
+ require "airbrake"
4
+ require "airbrake/cli/runner"
5
+ require "net/http"
6
+ require "uri"
13
7
 
14
8
  args = ARGV.dup
15
9
  command = args.shift.strip rescue nil
10
+ options = ARGV[1..-1]
16
11
 
17
- case command
18
- when 'raise'
19
- options = parse_options(ARGV[1..-1])
20
- abort "You didn't provide API_KEY so nothing was raised."\
21
- " Refer to usage for more info (airbrake --help)." unless options[:api_key]
22
- Airbrake.configure do |c|
23
- c.api_key = options[:api_key]
24
- c.host = options[:host] if options[:host]
25
- c.port = options[:port] if options[:port]
26
- end
27
- exception_id = Airbrake.notify(:error_class => options[:error],
28
- :error_message => "#{options[:error]}: #{options[:message]}",
29
- :cgi_data => ENV)
30
- abort "Error sending exception to Airbrake server. Try again later." unless exception_id
31
- puts "Exception sent successfully: http://airbrake.io/locate/#{exception_id}"
32
- else
33
- puts <<USAGE
34
- Usage: airbrake [COMMAND] [OPTION]...
35
- Commands:
36
- raise # Raise an exception specified by ERROR and MESSAGE.
37
-
38
- Options:
39
- -e, [--error=ERROR] # Error class to raise. Default: RuntimeError
40
- -m, [--message=MESSAGE] # Error message. Default: "I've made a huge mistake"
41
- -k, [--api-key=API_KEY] # Api key of your Airbrake application.
42
- -h, [--host=HOST] # URL of the Airbrake API server. Default: api.airbrake.io
43
- -p, [--port=PORT] # Port of the Airbrake API server. Default: 80
44
- -h, [--help] # Show this usage
45
- USAGE
46
- end
12
+ Runner.run!(command, options)
@@ -2,7 +2,7 @@ require "girl_friday"
2
2
  require 'net/http'
3
3
  require 'net/https'
4
4
  require 'rubygems'
5
- require 'airbrake/utils/blank'
5
+ require 'airbrake/extensions/blank'
6
6
  require 'airbrake/version'
7
7
  require 'airbrake/configuration'
8
8
  require 'airbrake/notice'
@@ -7,6 +7,7 @@ module Airbrake
7
7
  configuration.load do
8
8
  after "deploy", "airbrake:deploy"
9
9
  after "deploy:migrations", "airbrake:deploy"
10
+ after "deploy:cold", "airbrake:deploy"
10
11
 
11
12
  namespace :airbrake do
12
13
  desc <<-DESC
@@ -0,0 +1,68 @@
1
+ require File.expand_path( "../runner", __FILE__)
2
+
3
+ module Client
4
+ extend self
5
+
6
+ def options
7
+ Runner.options
8
+ end
9
+
10
+ def fetch_projects
11
+ uri = URI.parse "http://#{options.account}.airbrake.io"\
12
+ "/data_api/v1/projects.xml?auth_token=#{options.auth_token}"
13
+ http = Net::HTTP.new(uri.host,uri.port)
14
+ request = Net::HTTP::Get.new(uri.request_uri)
15
+ response = http.request(request)
16
+ response.body
17
+ end
18
+
19
+ def create_project
20
+ uri = URI.parse "http://#{options.account}.airbrake.io"\
21
+ "/data_api/v1/projects.xml"
22
+ http = Net::HTTP.new(uri.host,uri.port)
23
+ request = Net::HTTP::Post.new(uri.request_uri)
24
+ request.set_form_data('project[name]' => options.name,'auth_token' => options.auth_token)
25
+ response = http.request(request)
26
+ response.body
27
+
28
+ print_project_response(response.body)
29
+ end
30
+
31
+ def create_deploy
32
+ uri = URI.parse "http://airbrake.io"\
33
+ "/projects/1/deploys.xml"
34
+ http = Net::HTTP.new(uri.host,uri.port)
35
+ request = Net::HTTP::Post.new(uri.request_uri)
36
+ request.set_form_data('deploy[rails_env]' => options.rails_env,"api_key" => options.api_key)
37
+ response = http.request(request)
38
+ puts response.body
39
+ end
40
+
41
+ def print_projects
42
+ factory = ProjectFactory.new
43
+ projects = fetch_projects
44
+ factory.create_projects_from_xml(projects)
45
+ abort "No projects were fetched. Did you provide the correct auth token?" if projects.match(/error/m)
46
+ puts "\nProjects\n" + "".rjust(63,"#")
47
+ factory.projects.each do |project|
48
+ puts project
49
+ end
50
+ puts
51
+ end
52
+
53
+ def print_project_response(response)
54
+ case response
55
+ when /errors/
56
+ puts "Error creating project: #{response.gsub("\n","").scan(/.*<error[^>]*>(.*?)<\/error>.*/).last.first.gsub(/\s{1,}/," ")}"
57
+ when /project/
58
+ project = Project.new(:id => response[/<id[^>]*>(.*?)<\/id>/,1],
59
+ :name => response[/<name[^>]*>(.*?)<\/name>/,1],
60
+ :api_key => response[/<api-key[^>]*>(.*?)<\/api-key>/,1])
61
+ puts "\nProject details\n" + "".rjust(63,"#")
62
+ puts project
63
+ else
64
+ puts "Unexpected error. Please try again!\n"
65
+ puts response
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,41 @@
1
+ class Options
2
+
3
+ ATTRIBUTES = [:error, :message, :api_key, :host, :port, :auth_token, :name, :account, :rails_env]
4
+
5
+ ATTRIBUTES.each do |attribute|
6
+ attr_reader attribute
7
+ end
8
+
9
+ private
10
+
11
+ # You should not write to this from outside
12
+ ATTRIBUTES.each do |attribute|
13
+ attr_writer attribute
14
+ end
15
+
16
+ public
17
+
18
+ # Parses all the options passed and stores them in attributes
19
+ def initialize(array = [])
20
+ opts = Hash[*array]
21
+ self.error = opts.delete("-e") || opts.delete("--error") { RuntimeError }
22
+ self.message = opts.delete("-m") || opts.delete("--message") { "I've made a huge mistake" }
23
+ self.api_key = opts.delete("-k") || opts.delete("--api-key") || config_from_file.api_key || ENV["AIRBRAKE_API_KEY"]
24
+ self.host = opts.delete("-h") || opts.delete("--host") || config_from_file.host
25
+ self.port = opts.delete("-p") || opts.delete("--port") || config_from_file.port
26
+ self.auth_token = opts.delete("-t") || opts.delete("--auth-token") || ENV["AIRBRAKE_AUTH_TOKEN"]
27
+ self.name = opts.delete("-n") || opts.delete("--name")
28
+ self.account = opts.delete("-a") || opts.delete("--account") || ENV["AIRBRAKE_ACCOUNT"]
29
+ self.rails_env = opts.delete("-E") || opts.delete("--rails-env") || ENV["RAILS_ENV"] || "production"
30
+ opts
31
+ end
32
+
33
+ # Fallback to read from the initializer
34
+ def config_from_file
35
+ begin
36
+ load "config/initializers/airbrake.rb"
37
+ rescue LoadError
38
+ end
39
+ Airbrake.configuration
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ module Printer
2
+ def self.print(collection)
3
+ collection.each do |element|
4
+ puts element
5
+ end
6
+ end
7
+
8
+ def self.print_usage
9
+ puts <<-USAGE
10
+ Usage: airbrake [COMMAND] [OPTION]...
11
+ Commands:
12
+ raise # Raise an exception specified by ERROR and MESSAGE.
13
+ list # List all the projects for given AUTH_TOKEN and ACCOUNT.
14
+ create # Create a project with the given NAME.
15
+ deploy # Send a new deployment notification to a project that matches the API_KEY.
16
+
17
+ Options:
18
+ -e, [--error=ERROR] # Error class to raise. Default: RuntimeError
19
+ -m, [--message=MESSAGE] # Error message. Default: "I've made a huge mistake"
20
+ -k, [--api-key=API_KEY] # Api key of your Airbrake application.
21
+ -h, [--host=HOST] # URL of the Airbrake API server. Default: api.airbrake.io
22
+ -p, [--port=PORT] # Port of the Airbrake API server. Default: 80
23
+ -t, [--auth-token=AUTH_TOKEN] # The auth token used for API requests.
24
+ -a, [--account=ACCOUNT] # The account used for API requests.
25
+ -n, [--name=NAME] # The name of the project you're trying to create.
26
+ -E, [--rails-env=NAME] # The name of the environment you're deploying to. Default: production
27
+ -h, [--help] # Show this usage
28
+ USAGE
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ class Project
2
+ attr_writer :name, :id, :api_key
3
+
4
+ def initialize(attributes = {})
5
+ attributes.keys.each do |key|
6
+ instance_variable_set("@#{key}",attributes[key])
7
+ end
8
+ end
9
+
10
+ def to_s
11
+ "#{@name}".rjust(20) + "(#{@id}):".rjust(10) + " #{@api_key}"
12
+ end
13
+
14
+ def valid?
15
+ @name && @id && @api_key
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ require File.expand_path( "../project", __FILE__)
2
+ # Responsible for creating projects when needed.
3
+ # Creates them from XML received.
4
+ class ProjectFactory
5
+ def initialize
6
+ @project = Project.new
7
+ @projects = []
8
+ end
9
+
10
+ def project
11
+ @project
12
+ end
13
+
14
+ def create_projects_from_xml(xml)
15
+ xml.split("\n").each do |line|
16
+ /<name[^>]*>(?<name>.*?)<\/name>/ =~ line
17
+ project.name = name.capitalize if name
18
+ /<id[^>]*>(?<id>.*?)<\/id>/ =~ line
19
+ project.id = id if id
20
+ /<api-key[^>]*>(?<api_key>.*?)<\/api-key>/ =~ line
21
+ project.api_key = api_key if api_key
22
+ check_project
23
+ end
24
+ end
25
+
26
+ def check_project
27
+ if @project.valid?
28
+ projects << @project
29
+ @project = Project.new
30
+ end
31
+ end
32
+
33
+ def projects
34
+ @projects
35
+ end
36
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path( "../project_factory", __FILE__)
2
+ require File.expand_path( "../options", __FILE__)
3
+ require File.expand_path( "../validator", __FILE__)
4
+ require File.expand_path( "../printer", __FILE__)
5
+ require File.expand_path( "../client", __FILE__)
6
+
7
+ module Runner
8
+ extend Validator
9
+
10
+ extend self
11
+
12
+ attr_accessor :options
13
+
14
+ def run!(command, cli_options = {})
15
+
16
+ self.options = Options.new(cli_options)
17
+
18
+ case command
19
+ when 'raise'
20
+ validates :api_key
21
+ Airbrake.configure do |c|
22
+ c.api_key = options.api_key
23
+ c.host = options.host if options.host
24
+ c.port = options.port if options.port
25
+ end
26
+ exception_id = Airbrake.notify(:error_class => options.error,
27
+ :error_message => "#{options.error}: #{options.message}",
28
+ :cgi_data => ENV)
29
+ abort "Error sending exception to Airbrake server. Try again later." unless exception_id
30
+ puts "Exception sent successfully: http://airbrake.io/locate/#{exception_id}"
31
+
32
+ when "list"
33
+ validates :auth_token, :account
34
+ Client.print_projects
35
+
36
+ when "create"
37
+ validates :auth_token, :account
38
+ Client.create_project
39
+
40
+ when "deploy"
41
+ validates :api_key
42
+ Client.create_deploy
43
+
44
+ else
45
+ Printer.print_usage
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ module Validator
2
+ def validates(*attributes)
3
+ attributes.each do |attribute|
4
+ abort "You didn't provide #{attribute.to_s.upcase}"\
5
+ " so no API request was made." unless Runner.options.send(attribute)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,73 @@
1
+ # stolen from ActiveSupport
2
+
3
+ class Object
4
+ unless method_defined?(:blank?)
5
+ def blank?
6
+ respond_to?(:empty?) ? empty? : !self
7
+ end
8
+ end
9
+
10
+ unless method_defined?(:present?)
11
+ def present?
12
+ !blank?
13
+ end
14
+ end
15
+
16
+ unless method_defined?(:presence)
17
+ def presence
18
+ self if present?
19
+ end
20
+ end
21
+ end
22
+
23
+ class NilClass
24
+ unless method_defined?(:blank?)
25
+ def blank?
26
+ true
27
+ end
28
+ end
29
+ end
30
+
31
+ class FalseClass
32
+ unless method_defined?(:blank?)
33
+ def blank?
34
+ true
35
+ end
36
+ end
37
+ end
38
+
39
+ class TrueClass
40
+ unless method_defined?(:blank?)
41
+ def blank?
42
+ false
43
+ end
44
+ end
45
+ end
46
+
47
+ class Array
48
+ unless method_defined?(:blank?)
49
+ alias_method :blank?, :empty?
50
+ end
51
+ end
52
+
53
+ class Hash
54
+ unless method_defined?(:blank?)
55
+ alias_method :blank?, :empty?
56
+ end
57
+ end
58
+
59
+ class String
60
+ unless method_defined?(:blank?)
61
+ def blank?
62
+ self !~ /[^[:space:]]/
63
+ end
64
+ end
65
+ end
66
+
67
+ class Numeric
68
+ unless method_defined?(:blank?)
69
+ def blank?
70
+ false
71
+ end
72
+ end
73
+ end
@@ -1,3 +1,3 @@
1
1
  module Airbrake
2
- VERSION = "3.1.5".freeze
2
+ VERSION = "3.1.6".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.5
4
+ version: 3.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-05 00:00:00.000000000 Z
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
@@ -306,6 +306,13 @@ files:
306
306
  - lib/airbrake/rails/middleware/exceptions_catcher.rb
307
307
  - lib/airbrake/rails.rb
308
308
  - lib/airbrake/rack.rb
309
+ - lib/airbrake/cli/printer.rb
310
+ - lib/airbrake/cli/project_factory.rb
311
+ - lib/airbrake/cli/project.rb
312
+ - lib/airbrake/cli/client.rb
313
+ - lib/airbrake/cli/options.rb
314
+ - lib/airbrake/cli/validator.rb
315
+ - lib/airbrake/cli/runner.rb
309
316
  - lib/airbrake/tasks.rb
310
317
  - lib/airbrake/rails3_tasks.rb
311
318
  - lib/airbrake/configuration.rb
@@ -313,8 +320,8 @@ files:
313
320
  - lib/airbrake/rake_handler.rb
314
321
  - lib/airbrake/version.rb
315
322
  - lib/airbrake/backtrace.rb
316
- - lib/airbrake/utils/blank.rb
317
323
  - lib/airbrake/notice.rb
324
+ - lib/airbrake/extensions/blank.rb
318
325
  - lib/airbrake/user_informer.rb
319
326
  - lib/airbrake.rb
320
327
  - lib/rails/generators/airbrake/airbrake_generator.rb
@@ -1,53 +0,0 @@
1
- # stolen from ActiveSupport
2
-
3
- class Object
4
- def blank?
5
- respond_to?(:empty?) ? empty? : !self
6
- end
7
-
8
- def present?
9
- !blank?
10
- end
11
-
12
- def presence
13
- self if present?
14
- end
15
- end
16
-
17
- class NilClass
18
- def blank?
19
- true
20
- end
21
- end
22
-
23
- class FalseClass
24
- def blank?
25
- true
26
- end
27
- end
28
-
29
- class TrueClass
30
- def blank?
31
- false
32
- end
33
- end
34
-
35
- class Array
36
- alias_method :blank?, :empty?
37
- end
38
-
39
- class Hash
40
- alias_method :blank?, :empty?
41
- end
42
-
43
- class String
44
- def blank?
45
- self !~ /[^[:space:]]/
46
- end
47
- end
48
-
49
- class Numeric
50
- def blank?
51
- false
52
- end
53
- end