Class: AirbrakeAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/airbrake-api/client.rb

Constant Summary collapse

PER_PAGE =
30
PARALLEL_WORKERS =
10

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.


16
17
18
19
20
21
# File 'lib/airbrake-api/client.rb', line 16

def initialize(options={})
  attrs = AirbrakeAPI.options.merge(options)
  AirbrakeAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", attrs[key])
  end
end

Instance Method Details

#deploys(project_id, options = {}) ⇒ Object

deploys


39
40
41
42
# File 'lib/airbrake-api/client.rb', line 39

def deploys(project_id, options = {})
  results = request(:get, deploys_path(project_id), options)
  results.projects.respond_to?(:deploy) ? results.projects.deploy : []
end

#deploys_path(project_id) ⇒ Object


44
45
46
# File 'lib/airbrake-api/client.rb', line 44

def deploys_path(project_id)
  "/projects/#{project_id}/deploys.xml"
end

#error(error_id, options = {}) ⇒ Object


77
78
79
80
# File 'lib/airbrake-api/client.rb', line 77

def error(error_id, options = {})
  results = request(:get, error_path(error_id), options)
  results.group || results.groups
end

#error_path(error_id) ⇒ Object


64
65
66
# File 'lib/airbrake-api/client.rb', line 64

def error_path(error_id)
  "#{unformatted_error_path(error_id)}.xml"
end

#errors(options = {}) ⇒ Object


82
83
84
85
86
87
# File 'lib/airbrake-api/client.rb', line 82

def errors(options = {})
  options = options.dup
  project_id = options.delete(:project_id)
  results = request(:get, errors_path(:project_id => project_id), options)
  results.group || results.groups
end

#errors_path(options = {}) ⇒ Object


68
69
70
# File 'lib/airbrake-api/client.rb', line 68

def errors_path(options={})
  "#{options[:project_id] ? "/projects/#{options[:project_id]}" : nil}/groups.xml"
end

#notice(notice_id, error_id, options = {}) ⇒ Object


99
100
101
102
# File 'lib/airbrake-api/client.rb', line 99

def notice(notice_id, error_id, options = {})
  hash = request(:get, notice_path(notice_id, error_id), options)
  hash.notice
end

#notice_path(notice_id, error_id) ⇒ Object

notices


91
92
93
# File 'lib/airbrake-api/client.rb', line 91

def notice_path(notice_id, error_id)
  "/groups/#{error_id}/notices/#{notice_id}.xml"
end

#notices(error_id, options = {}, &block) ⇒ Object


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/airbrake-api/client.rb', line 104

def notices(error_id, options = {}, &block)
  # a specific page is requested, only return that page
  # if no page is specified, start on page 1
  if options[:page]
    page = options[:page]
    options[:pages] = 1
  else
    page = 1
  end

  notices = []
  page_count = 0
  while !options[:pages] || (page_count + 1) <= options[:pages]
    data = request(:get, notices_path(error_id), :page => page + page_count)

    batch = if options[:raw]
      data.notices
    else
      # get info like backtraces by doing another api call to notice
      Parallel.map(data.notices, :in_threads => PARALLEL_WORKERS) do |notice_stub|
        notice(notice_stub.id, error_id)
      end
    end
    yield batch if block_given?
    batch.each{|n| notices << n }

    break if batch.size < PER_PAGE
    page_count += 1
  end
  notices
end

#notices_path(error_id) ⇒ Object


95
96
97
# File 'lib/airbrake-api/client.rb', line 95

def notices_path(error_id)
  "/groups/#{error_id}/notices.xml"
end

#projects(options = {}) ⇒ Object


53
54
55
56
# File 'lib/airbrake-api/client.rb', line 53

def projects(options = {})
  results = request(:get, projects_path, options)
  results.projects.project
end

#projects_pathObject

projects


49
50
51
# File 'lib/airbrake-api/client.rb', line 49

def projects_path
  '/data_api/v1/projects.xml'
end

#unformatted_error_path(error_id) ⇒ Object

errors


60
61
62
# File 'lib/airbrake-api/client.rb', line 60

def unformatted_error_path(error_id)
  "/groups/#{error_id}"
end

#update(error, options = {}) ⇒ Object


72
73
74
75
# File 'lib/airbrake-api/client.rb', line 72

def update(error, options = {})
  results = request(:put, unformatted_error_path(error), options)
  results.group
end

#url_for(endpoint, *args) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/airbrake-api/client.rb', line 23

def url_for(endpoint, *args)
  path = case endpoint.to_s
  when 'deploys' then deploys_path(*args)
  when 'projects' then '/projects'
  when 'errors' then errors_path(*args)
  when 'error' then error_path(*args)
  when 'notices' then notices_path(*args)
  when 'notice' then notice_path(*args)
  else raise ArgumentError.new("Unrecognized path: #{path}")
  end

  [, path.split('.').first].join('')
end