Class: Airbrake::API

Inherits:
Object
  • Object
show all
Defined in:
lib/campfire/polling_bot/plugins/airbrake/airbrake/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(domain, auth_token) ⇒ API

Returns a new instance of API.


6
7
8
9
# File 'lib/campfire/polling_bot/plugins/airbrake/airbrake/api.rb', line 6

def initialize(domain, auth_token)
  @host = "#{domain}.airbrakeapp.com"
  @auth_token = auth_token
end

Instance Method Details

#error_url(error) ⇒ Object


33
34
35
36
# File 'lib/campfire/polling_bot/plugins/airbrake/airbrake/api.rb', line 33

def error_url(error)
  error_id = error.is_a?(Airbrake::Error) ? error.error_id : error
  "https://#{@host}/errors/#{error_id}"
end

#errors(show_resolved = false) ⇒ Object

Fetch errors from Airbrake. Their API returns errors in pages of 30 at a time, so keep fetching until we don't get anything.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/campfire/polling_bot/plugins/airbrake/airbrake/api.rb', line 18

def errors(show_resolved=false)
  options = {}
  options[:show_resolved] = 1 if show_resolved
  page = 1
  errors = []
  begin
    options[:page] = page
    doc = Nokogiri::XML(api_get("/errors.xml", options))
    new_errors = doc.xpath("/groups/group").map {|node| Airbrake::Error.from_xml(node) }
    errors += new_errors
    page += 1
  end while new_errors.any?
  return errors
end

#resolve_error(error_id, resolved = true) ⇒ Object


11
12
13
# File 'lib/campfire/polling_bot/plugins/airbrake/airbrake/api.rb', line 11

def resolve_error(error_id, resolved=true)
  api_put("/errors/#{error_id}", {}, :group => {:resolved => resolved})
end