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.



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

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



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

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



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

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

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



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

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

#error_path(error_id) ⇒ Object



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

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

#errors(options = {}) ⇒ Object



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

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

#errors_pathObject



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

def errors_path
  '/errors.xml'
end

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



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

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



88
89
90
# File 'lib/airbrake-api/client.rb', line 88

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

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



101
102
103
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
# File 'lib/airbrake-api/client.rb', line 101

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



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

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

#projects(options = {}) ⇒ Object



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

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

#projects_pathObject

projects



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

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

#unformatted_error_path(error_id) ⇒ Object

errors



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

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

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



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

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

#url_for(endpoint, *args) ⇒ Object



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

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
  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