Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:spagalloco/airbrake-api

Conflicts:
  lib/airbrake-api/error.rb
  • Loading branch information...
commit 307d38c2b85af88ea5c1e055930793d1f998af8c 2 parents 681722e + c565294
@stve authored
View
28 README.md
@@ -8,50 +8,50 @@ Usage
The first thing you need to set is the account name. This is the same as the web address for your account.
- Airbrake.account = 'myaccount'
+ AirbrakeAPI.account = 'myaccount'
Then, you should set the authentication token.
- Airbrake.auth_token = 'abcdefg'
+ AirbrakeAPI.auth_token = 'abcdefg'
If your account uses ssl then turn it on:
- Airbrake.secure = true
+ AirbrakeAPI.secure = true
Optionally, you can configure through a single method:
- Airbrake.configure(:account => 'anapp', :auth_token => 'abcdefg', :secure => true)
+ AirbrakeAPI.configure(:account => 'anapp', :auth_token => 'abcdefg', :secure => true)
-Once you've configured authentication, you can make calls against the API. If no token or authentication is given, a AirbrakeError exception will be raised.
+Once you've configured authentication, you can make calls against the API. If no token or authentication is given, an AirbrakeError exception will be raised.
Finding Errors
--------------
Errors are paginated, the API responds with 25 at a time, pass an optional params hash for additional pages:
- Airbrake::Error.find(:all)
- Airbrake::Error.find(:all, :page => 2)
+ AirbrakeAPI::Error.find(:all)
+ AirbrakeAPI::Error.find(:all, :page => 2)
To find an individual error, you can find by ID:
- Airbrake::Error.find(error_id)
+ AirbrakeAPI::Error.find(error_id)
Find *all* notices of an error:
- Airbrake::Notice.find_all_by_error_id(error_id)
+ AirbrakeAPI::Notice.find_all_by_error_id(error_id)
Find an individual notice:
- Airbrake::Notice.find(notice_id, error_id)
+ AirbrakeAPI::Notice.find(notice_id, error_id)
To resolve an error via the API:
- Airbrake::Error.update(1696170, :group => { :resolved => true})
+ AirbrakeAPI::Error.update(1696170, :group => { :resolved => true})
Recreate an error:
STDOUT.sync = true
- Airbrake::Notice.find_all_by_error_id(error_id) do |batch|
+ AirbrakeAPI::Notice.find_all_by_error_id(error_id) do |batch|
batch.each do |notice|
result = system "curl --silent '#{notice.request.url}' > /dev/null"
print (result ? '.' : 'F')
@@ -63,12 +63,12 @@ Projects
To retrieve a list of projects:
- Airbrake::Project.find(:all)
+ AirbrakeAPI::Project.find(:all)
Responses
---------
-If an error is returned from the API. A AirbrakeError will be raised. Successful responses will return a Hashie::Mash object based on the data from the response.
+If an error is returned from the API, an AirbrakeError will be raised. Successful responses will return a Hashie::Mash object based on the data from the response.
Contributors
View
4 airbrake-api.gemspec
@@ -4,7 +4,7 @@ require "airbrake-api/version"
Gem::Specification.new do |s|
s.name = 'airbrake-api'
- s.version = Airbrake::VERSION
+ s.version = AirbrakeAPI::VERSION
s.platform = Gem::Platform::RUBY
s.summary = "A ruby wrapper for the Airbrake API"
@@ -25,6 +25,8 @@ Gem::Specification.new do |s|
s.add_development_dependency 'simplecov', '~> 0.4.2'
s.add_development_dependency 'fakeweb', '~> 1.3.0'
s.add_development_dependency 'nokogiri', '~> 1.4'
+ s.add_development_dependency 'airbrake', '~> 3.0'
+ s.add_development_dependency 'i18n', '~> 0.6.0'
# ensure the gem is built out of versioned files
s.files = `git ls-files`.split("\n")
View
2  lib/airbrake-api.rb
@@ -1,7 +1,7 @@
require 'hashie'
require 'httparty'
-module Airbrake
+module AirbrakeAPI
extend self
attr_accessor :account, :auth_token, :secure
View
8 lib/airbrake-api/client.rb
@@ -1,4 +1,4 @@
-module Airbrake
+module AirbrakeAPI
class Base
include HTTParty
format :xml
@@ -6,8 +6,8 @@ class Base
private
def self.setup
- base_uri Airbrake.account_path
- default_params :auth_token => Airbrake.auth_token
+ base_uri AirbrakeAPI.account_path
+ default_params :auth_token => AirbrakeAPI.auth_token
check_configuration
end
@@ -20,7 +20,7 @@ def self.check_configuration
def self.fetch(path, options)
response = get(path, { :query => options })
if response.code == 403
- raise AirbrakeError.new('SSL should be enabled - use Airbrake.secure = true in configuration')
+ raise AirbrakeError.new('SSL should be enabled - use AirbrakeAPI.secure = true in configuration')
end
Hashie::Mash.new(response)
View
116 lib/airbrake-api/error.rb
@@ -1,59 +1,59 @@
-module Airbrake
- class Error < Airbrake::Base
-
- def self.find(*args)
- setup
-
- results = case args.first
- when Fixnum
- find_individual(args)
- when :all
- find_all(args)
- else
- raise AirbrakeError.new('Invalid argument')
- end
-
- raise AirbrakeError.new('No results found.') if results.nil?
- raise AirbrakeError.new(results.errors.error) if results.errors
-
- results.group || results.groups
- end
-
- def self.update(error, options)
- setup
-
- response = put(error_path(error), :body => options)
- if response.code == 403
- raise AirbrakeError.new('SSL should be enabled - use Airbrake.secure = true in configuration')
- end
- results = Hashie::Mash.new(response)
-
- raise AirbrakeError.new(results.errors.error) if results.errors
- results.group
- end
-
- private
-
- def self.find_all(args)
- options = args.extract_options!
-
- fetch(collection_path, options)
- end
-
- def self.find_individual(args)
- id = args.shift
- options = args.extract_options!
-
- fetch(error_path(id), options)
- end
-
- def self.collection_path
- '/errors.xml'
- end
-
- def self.error_path(error_id)
- "/errors/#{error_id}.xml"
- end
-
- end
+module AirbrakeAPI
+ class Error < AirbrakeAPI::Base
+
+ def self.find(*args)
+ setup
+
+ results = case args.first
+ when Fixnum
+ find_individual(args)
+ when :all
+ find_all(args)
+ else
+ raise AirbrakeError.new('Invalid argument')
+ end
+
+ raise AirbrakeError.new('No results found.') if results.nil?
+ raise AirbrakeError.new(results.errors.error) if results.errors
+
+ results.group || results.groups
+ end
+
+ def self.update(error, options)
+ setup
+
+ response = put(error_path(error), :body => options)
+ if response.code == 403
+ raise AirbrakeError.new('SSL should be enabled - use Airbrake.secure = true in configuration')
+ end
+ results = Hashie::Mash.new(response)
+
+ raise AirbrakeError.new(results.errors.error) if results.errors
+ results.group
+ end
+
+ private
+
+ def self.find_all(args)
+ options = args.extract_options!
+
+ fetch(collection_path, options)
+ end
+
+ def self.find_individual(args)
+ id = args.shift
+ options = args.extract_options!
+
+ fetch(error_path(id), options)
+ end
+
+ def self.collection_path
+ '/errors.xml'
+ end
+
+ def self.error_path(error_id)
+ "/errors/#{error_id}.xml"
+ end
+
+ end
end
View
4 lib/airbrake-api/notice.rb
@@ -1,7 +1,7 @@
require 'parallel'
-module Airbrake
- class Notice < Airbrake::Base
+module AirbrakeAPI
+ class Notice < AirbrakeAPI::Base
PER_PAGE = 30
PARALLEL_WORKERS = 10
View
4 lib/airbrake-api/project.rb
@@ -1,5 +1,5 @@
-module Airbrake
- class Project < Airbrake::Base
+module AirbrakeAPI
+ class Project < AirbrakeAPI::Base
def self.find(*args)
setup
View
4 lib/airbrake-api/version.rb
@@ -1,3 +1,3 @@
-module Airbrake
- VERSION = '3.1.0'
+module AirbrakeAPI
+ VERSION = '3.2.0'
end
View
24 spec/airbrake_api/error_spec.rb
@@ -1,51 +1,51 @@
require 'spec_helper'
-describe Airbrake::Error do
+describe AirbrakeAPI::Error do
before(:all) do
- Airbrake.account = 'myapp'
- Airbrake.auth_token = 'abcdefg123456'
- Airbrake.secure = false
+ AirbrakeAPI.account = 'myapp'
+ AirbrakeAPI.auth_token = 'abcdefg123456'
+ AirbrakeAPI.secure = false
end
it "should have correct collection path" do
- Airbrake::Error.collection_path.should == "/errors.xml"
+ AirbrakeAPI::Error.collection_path.should == "/errors.xml"
end
it "should generate correct error path given an id" do
- Airbrake::Error.error_path(1234).should == "/errors/1234.xml"
+ AirbrakeAPI::Error.error_path(1234).should == "/errors/1234.xml"
end
describe '.find' do
it "should find a page of the 30 most recent errors" do
- errors = Airbrake::Error.find(:all)
+ errors = AirbrakeAPI::Error.find(:all)
ordered = errors.sort_by(&:most_recent_notice_at).reverse
ordered.should == errors
errors.size.should == 30
end
it "should paginate errors" do
- errors = Airbrake::Error.find(:all, :page => 2)
+ errors = AirbrakeAPI::Error.find(:all, :page => 2)
ordered = errors.sort_by(&:most_recent_notice_at).reverse
ordered.should == errors
errors.size.should == 2
end
it "should find an individual error" do
- error = Airbrake::Error.find(1696170)
+ error = AirbrakeAPI::Error.find(1696170)
error.action.should == 'index'
error.id.should == 1696170
end
it "should raise an error when not passed an id" do
lambda do
- Airbrake::Error.find
- end.should raise_error(Airbrake::AirbrakeError)
+ AirbrakeAPI::Error.find
+ end.should raise_error(AirbrakeAPI::AirbrakeError)
end
end
describe '.update' do
it 'should update the status of an error' do
- error = Airbrake::Error.update(1696170, :group => { :resolved => true})
+ error = AirbrakeAPI::Error.update(1696170, :group => { :resolved => true})
error.resolved.should be_true
end
end
View
20 spec/airbrake_api/notice_spec.rb
@@ -1,31 +1,31 @@
require 'spec_helper'
-describe Airbrake::Notice do
+describe AirbrakeAPI::Notice do
before(:all) do
- Airbrake.account = 'myapp'
- Airbrake.auth_token = 'abcdefg123456'
- Airbrake.secure = false
+ AirbrakeAPI.account = 'myapp'
+ AirbrakeAPI.auth_token = 'abcdefg123456'
+ AirbrakeAPI.secure = false
end
it "should find error notices" do
- notices = Airbrake::Notice.find_by_error_id(1696170)
+ notices = AirbrakeAPI::Notice.find_by_error_id(1696170)
notices.size.should == 30
notices.first.id.should == 1234
end
it "should find all error notices" do
- notices = Airbrake::Notice.find_all_by_error_id(1696170)
+ notices = AirbrakeAPI::Notice.find_all_by_error_id(1696170)
notices.size.should == 42
end
it "should find all error notices with a page limit" do
- notices = Airbrake::Notice.find_all_by_error_id(1696171, :pages => 2)
+ notices = AirbrakeAPI::Notice.find_all_by_error_id(1696171, :pages => 2)
notices.size.should == 60
end
it "yields batches" do
batches = []
- notices = Airbrake::Notice.find_all_by_error_id(1696171, :pages => 2) do |batch|
+ notices = AirbrakeAPI::Notice.find_all_by_error_id(1696171, :pages => 2) do |batch|
batches << batch
end
notices.size.should == 60
@@ -33,10 +33,10 @@
end
it "should find individual notices" do
- Airbrake::Notice.find(1234, 1696170).should_not == nil
+ AirbrakeAPI::Notice.find(1234, 1696170).should_not == nil
end
it "should find a broken notices" do
- Airbrake::Notice.find(666, 1696170).should_not == nil
+ AirbrakeAPI::Notice.find(666, 1696170).should_not == nil
end
end
View
12 spec/airbrake_api/project_spec.rb
@@ -1,18 +1,18 @@
require 'spec_helper'
-describe Airbrake::Project do
+describe AirbrakeAPI::Project do
before(:all) do
- Airbrake.account = 'myapp'
- Airbrake.auth_token = 'abcdefg123456'
- Airbrake.secure = false
+ AirbrakeAPI.account = 'myapp'
+ AirbrakeAPI.auth_token = 'abcdefg123456'
+ AirbrakeAPI.secure = false
end
it "should have correct projects path" do
- Airbrake::Project.collection_path.should == "/data_api/v1/projects.xml"
+ AirbrakeAPI::Project.collection_path.should == "/data_api/v1/projects.xml"
end
it "should find projects" do
- projects = Airbrake::Project.find(:all)
+ projects = AirbrakeAPI::Project.find(:all)
projects.size.should == 4
projects.first.id.should == '1'
projects.first.name.should == 'Venkman'
View
44 spec/airbrake_api_spec.rb
@@ -1,58 +1,58 @@
require 'spec_helper'
-describe Airbrake do
+describe AirbrakeAPI do
context "configuration" do
before(:each) do
- Airbrake.account = nil
- Airbrake.auth_token = nil
- Airbrake.secure = false
+ AirbrakeAPI.account = nil
+ AirbrakeAPI.auth_token = nil
+ AirbrakeAPI.secure = false
end
it "should allow setting of the account" do
- Airbrake.account = 'myapp'
- Airbrake.account.should == 'myapp'
- Airbrake.account_path.should == 'http://myapp.airbrakeapp.com'
+ AirbrakeAPI.account = 'myapp'
+ AirbrakeAPI.account.should == 'myapp'
+ AirbrakeAPI.account_path.should == 'http://myapp.airbrakeapp.com'
end
it "should allow setting of the auth token" do
- Airbrake.auth_token = '123456'
- Airbrake.auth_token.should == '123456'
+ AirbrakeAPI.auth_token = '123456'
+ AirbrakeAPI.auth_token.should == '123456'
end
it "should allow setting of ssl protocol" do
- Airbrake.secure = true
- Airbrake.protocol.should == 'https'
+ AirbrakeAPI.secure = true
+ AirbrakeAPI.protocol.should == 'https'
end
it "should default to standard http" do
- Airbrake.protocol.should == 'http'
+ AirbrakeAPI.protocol.should == 'http'
end
it "should should implement #configure" do
- Airbrake.configure(:account => 'anapp', :auth_token => 'abcdefg', :secure => true)
- Airbrake.protocol.should == 'https'
- Airbrake.auth_token.should == 'abcdefg'
- Airbrake.account.should == 'anapp'
- Airbrake.account_path.should == 'https://anapp.airbrakeapp.com'
+ AirbrakeAPI.configure(:account => 'anapp', :auth_token => 'abcdefg', :secure => true)
+ AirbrakeAPI.protocol.should == 'https'
+ AirbrakeAPI.auth_token.should == 'abcdefg'
+ AirbrakeAPI.account.should == 'anapp'
+ AirbrakeAPI.account_path.should == 'https://anapp.airbrakeapp.com'
end
end
context "when using SSL" do
before(:each) do
- Airbrake.configure(:account => 'sslapp', :auth_token => 'abcdefg123456', :secure => true)
+ AirbrakeAPI.configure(:account => 'sslapp', :auth_token => 'abcdefg123456', :secure => true)
end
it "should find an error if account is SSL enabled" do
- error = Airbrake::Error.find(1696170)
+ error = AirbrakeAPI::Error.find(1696170)
error.id.should == 1696170
end
it "should raise an exception if trying to access SSL enabled account with unsecure connection" do
- Airbrake.secure = false
+ AirbrakeAPI.secure = false
lambda do
- Airbrake::Error.find(1696170)
- end.should raise_error(Airbrake::AirbrakeError)
+ AirbrakeAPI::Error.find(1696170)
+ end.should raise_error(AirbrakeAPI::AirbrakeError)
end
end
View
9 spec/spec_helper.rb
@@ -4,11 +4,16 @@
add_group 'Specs', 'spec'
end
-require File.expand_path('../../lib/airbrake-api', __FILE__)
-
require 'rspec'
require 'fakeweb'
+require 'active_support'
+require 'active_support/core_ext'
+require 'i18n'
+require 'airbrake'
+
+require File.expand_path('../../lib/airbrake-api', __FILE__)
+
FakeWeb.allow_net_connect = false
DEFAULTS = {:content_type => "application/xml; charset=utf-8", :status => ["403", "Forbidden"]}
Please sign in to comment.
Something went wrong with that request. Please try again.