Permalink
Browse files

Airbrake plugin, update DataMapper

  • Loading branch information...
1 parent 4e5f392 commit 55d4971304aef54dc0a67d4806bfe6ce03a8cdc4 @bgreenlee bgreenlee committed Sep 4, 2011
View
@@ -3,12 +3,8 @@ source :gemcutter
gem "capistrano"
gem "railsless-deploy", :require => nil
gem "tinder", :git => "git://github.com/collectiveidea/tinder.git"
-gem "dm-core"
-gem "dm-sqlite-adapter"
-gem "dm-migrations"
-gem "data_objects"
-gem "do_sqlite3"
-gem "json", "1.5.3"
+gem "data_mapper", "~>1.1"
+gem "dm-sqlite-adapter", "~>1.1"
gem "daemons"
gem "i18n"
gem "firering", "~>1.0.8", :git => "git://github.com/indirect/firering.git"
View
@@ -23,6 +23,13 @@ GIT
yajl-ruby (~> 0.7.6)
PATH
+ remote: campfire/polling_bot/plugins/airbrake
+ specs:
+ airbrake (1.0)
+ nokogiri
+ rest-client
+
+PATH
remote: campfire/polling_bot/plugins/image_search
specs:
image_search (1.0)
@@ -46,69 +53,105 @@ GEM
specs:
activesupport (3.1.0)
multi_json (~> 1.0)
- addressable (2.2.4)
- capistrano (2.5.19)
+ addressable (2.2.6)
+ bcrypt-ruby (2.1.4)
+ capistrano (2.8.0)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
net-ssh (>= 2.0.14)
- net-ssh-gateway (>= 1.0.0)
- chronic (0.3.0)
- columnize (0.3.2)
+ net-ssh-gateway (>= 1.1.0)
+ chronic (0.6.3)
+ columnize (0.3.4)
crack (0.1.8)
- daemons (1.1.0)
- data_objects (0.10.3)
+ daemons (1.1.4)
+ data_mapper (1.1.0)
+ dm-aggregates (= 1.1.0)
+ dm-constraints (= 1.1.0)
+ dm-core (= 1.1.0)
+ dm-migrations (= 1.1.0)
+ dm-serializer (= 1.1.0)
+ dm-timestamps (= 1.1.0)
+ dm-transactions (= 1.1.0)
+ dm-types (= 1.1.0)
+ dm-validations (= 1.1.0)
+ data_objects (0.10.6)
addressable (~> 2.1)
- diff-lcs (1.1.2)
- dm-core (1.0.2)
- addressable (~> 2.2)
- extlib (~> 0.9.15)
- dm-do-adapter (1.0.2)
+ diff-lcs (1.1.3)
+ dm-aggregates (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-constraints (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-core (1.1.0)
+ addressable (~> 2.2.4)
+ dm-do-adapter (1.1.0)
data_objects (~> 0.10.2)
- dm-core (~> 1.0.2)
- dm-migrations (1.0.2)
- dm-core (~> 1.0.2)
- dm-sqlite-adapter (1.0.2)
- dm-do-adapter (~> 1.0.2)
+ dm-core (~> 1.1.0)
+ dm-migrations (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-serializer (1.1.0)
+ dm-core (~> 1.1.0)
+ fastercsv (~> 1.5.4)
+ json (~> 1.4.6)
+ dm-sqlite-adapter (1.1.0)
+ dm-do-adapter (~> 1.1.0)
do_sqlite3 (~> 0.10.2)
- do_sqlite3 (0.10.3)
- data_objects (= 0.10.3)
+ dm-timestamps (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-transactions (1.1.0)
+ dm-core (~> 1.1.0)
+ dm-types (1.1.0)
+ bcrypt-ruby (~> 2.1.4)
+ dm-core (~> 1.1.0)
+ fastercsv (~> 1.5.4)
+ json (~> 1.4.6)
+ stringex (~> 1.2.0)
+ uuidtools (~> 2.1.2)
+ dm-validations (1.1.0)
+ dm-core (~> 1.1.0)
+ do_sqlite3 (0.10.6)
+ data_objects (= 0.10.6)
em-http-request (0.3.0)
addressable (>= 2.0.0)
escape_utils
eventmachine (>= 0.12.9)
- escape_utils (0.2.2)
+ escape_utils (0.2.4)
eventmachine (0.12.10)
- extlib (0.9.15)
- faraday (0.6.1)
- addressable (~> 2.2.4)
+ faraday (0.7.4)
+ addressable (~> 2.2.6)
multipart-post (~> 1.1.0)
rack (>= 1.1.0, < 2)
- faraday_middleware (0.6.5)
- faraday (~> 0.6.0)
+ faraday_middleware (0.7.0)
+ faraday (~> 0.7.3)
+ fastercsv (1.5.4)
google-search (1.0.2)
json
hashie (1.1.0)
- highline (1.6.1)
+ highline (1.6.2)
http_parser.rb (0.5.2)
- httparty (0.6.1)
+ httparty (0.7.8)
crack (= 0.1.8)
- i18n (0.5.0)
- json (1.5.3)
- linecache (0.43)
+ i18n (0.6.0)
+ json (1.4.6)
+ linecache (0.46)
+ rbx-require-relative (> 0.0.4)
mime-types (1.16)
multi_json (1.0.3)
multipart-post (1.1.3)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
- net-ssh (2.1.0)
- net-ssh-gateway (1.0.1)
+ net-ssh (2.2.1)
+ net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
+ nokogiri (1.5.0)
rack (1.3.2)
railsless-deploy (1.0.2)
- rake (0.8.7)
+ rake (0.9.2)
+ rbx-require-relative (0.0.5)
+ rest-client (1.6.7)
+ mime-types (>= 1.16)
rspec (2.6.0)
rspec-core (~> 2.6.0)
rspec-expectations (~> 2.6.0)
@@ -123,27 +166,26 @@ GEM
ruby-debug-base (0.10.4)
linecache (>= 0.3)
simple_oauth (0.1.5)
+ stringex (1.2.2)
twitter-stream (0.1.14)
eventmachine (>= 0.12.8)
http_parser.rb (~> 0.5.1)
simple_oauth (~> 0.1.4)
+ uuidtools (2.1.2)
yajl-ruby (0.7.9)
PLATFORMS
ruby
DEPENDENCIES
+ airbrake!
capistrano
daemons
- data_objects
- dm-core
- dm-migrations
- dm-sqlite-adapter
- do_sqlite3
+ data_mapper (~> 1.1)
+ dm-sqlite-adapter (~> 1.1)
firering (~> 1.0.8)!
i18n
image_search!
- json (= 1.5.3)
railsless-deploy
rake
remind_me!
@@ -83,6 +83,8 @@ def self.load_all(bot)
end
def self.load_plugin_classes
+ # add each plugin dir to the load path
+ Dir.glob(File.dirname(__FILE__) + "/plugins/*").each {|dir| $LOAD_PATH << dir }
# load core first
paths = Dir.glob(File.dirname(__FILE__) + "/plugins/shared/*.rb")
# load all models & plugins
@@ -100,6 +102,8 @@ def self.load_plugin_classes
def self.setup_database(datauri)
DataMapper.setup(:default, datauri)
DataMapper.auto_upgrade!
+ # not related to setting up the database, but for lack of a better place....
+ DataMapper::Model.raise_on_save_failure = true
end
# method to set or get the priority. Higher value == higher priority. Default is 0
@@ -0,0 +1 @@
+airbrake_plugin.yml
@@ -0,0 +1,7 @@
+Gem::Specification.new do |s|
+ s.name = 'airbrake'
+ s.version = '1.0'
+ s.summary = 'Plugin for Airbrake (formerly Hoptoad)'
+ s.add_dependency 'nokogiri'
+ s.add_dependency 'rest-client'
+end
@@ -0,0 +1,48 @@
+require 'nokogiri'
+require 'rest-client'
+
+module Airbrake
+ class API
+ def initialize(domain, auth_token)
+ @host = "#{domain}.airbrakeapp.com"
+ @auth_token = auth_token
+ end
+
+ def resolve_error(error_id, resolved=true)
+ api_put("/errors/#{error_id}", {}, :group => {:resolved => resolved})
+ end
+
+ def errors(show_resolved=false)
+ doc = Nokogiri::XML(api_get("/errors.xml", :show_resolved => show_resolved))
+ doc.xpath("/groups/group").map {|node| Airbrake::Error.from_xml(node) }
+ end
+
+ def error_url(error)
+ error_id = error.is_a?(Airbrake::Error) ? error.error_id : error
+ "https://#{@host}/errors/#{error_id}"
+ end
+
+ private
+
+ def api_uri(endpoint, query = {})
+ query = {:auth_token => @auth_token}.update(query)
+ uri = URI::HTTPS.build(:host => @host, :path => endpoint, :query => to_query(query))
+ return uri.to_s
+ end
+
+ # convert a hash of param to a query string
+ def to_query(params)
+ params.map{|k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"}.join('&')
+ end
+
+ def api_get(endpoint, query = {})
+ RestClient.get(api_uri(endpoint, query))
+ end
+
+ def api_put(endpoint, query = {}, params = {})
+ return RestClient.put(api_uri(endpoint, query), params)
+ rescue RestClient::Exception => e
+ return e.response
+ end
+ end
+end
@@ -0,0 +1,73 @@
+module Airbrake
+ class Error
+ include DataMapper::Resource
+ property :id, Serial
+ property :error_id, Integer, :required => true
+
+ attr_accessor :field
+
+ # Given a block of XML returned from the Airbrake API, return an
+ # Airbrake::Error object
+ def self.from_xml(xml)
+ field = {}
+ xml.xpath('./*').each do |node|
+ content = node.content
+ # convert to proper ruby types
+ type = node.attributes['type'] && node.attributes['type'].value
+ case type
+ when "boolean"
+ content = content == "true"
+ when "datetime"
+ content = Time.parse(content)
+ when "integer"
+ content = content.to_i
+ end
+ key = node.name.tr('-','_')
+ field[key.to_sym] = content
+ end
+ error = new()
+ error.field = field
+ error.error_id = field[:id]
+ return error
+ end
+
+ def summary
+ "#{@field[:error_message]} at #{@field[:file]}:#{@field[:line_number]}"
+ end
+
+ def [](key)
+ key = key.to_s.tr('-','_').to_sym
+ @field[key]
+ end
+
+ def eql?(other)
+ self.error_id.eql?(other.error_id)
+ end
+
+ def hash
+ self.error_id.hash
+ end
+ end
+end
+
+# <?xml version="1.0" encoding="UTF-8"?>
+# <groups type="array">
+# <group>
+# <created-at type="datetime">2011-09-02T18:36:59Z</created-at>
+# <notice-hash>af0bd1d1506128519c7327b0289db84e</notice-hash>
+# <project-id type="integer">42693</project-id>
+# <updated-at type="datetime">2011-09-02T18:51:39Z</updated-at>
+# <action nil="true"></action>
+# <resolved type="boolean">false</resolved>
+# <error-class>RuntimeError</error-class>
+# <error-message>RuntimeError: Test error to exercise chef-client error handler. To disable test, unset node[:test_error_handler] attribute</error-message>
+# <id type="integer">12830481</id>
+# <lighthouse-ticket-id type="integer" nil="true"></lighthouse-ticket-id>
+# <controller>component01.api-pub.ny1</controller>
+# <file>/var/cache/chef/cookbooks/daylife-ops/recipes/test-chef-handlers.rb</file>
+# <rails-env>prod</rails-env>
+# <line-number type="integer">16</line-number>
+# <most-recent-notice-at type="datetime">2011-09-02T18:51:39Z</most-recent-notice-at>
+# <notices-count type="integer">2</notices-count>
+# </group>
+# </groups>
Oops, something went wrong.

0 comments on commit 55d4971

Please sign in to comment.