Class: AirbrakeAPI::Client

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

Constant Summary collapse

PER_PAGE =
20
PARALLEL_WORKERS =
10

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
# File 'lib/airbrake-api/client.rb', line 12

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



35
36
37
38
# File 'lib/airbrake-api/client.rb', line 35

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

#deploys_path(project_id) ⇒ Object



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

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

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



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

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

#error_path(error_id) ⇒ Object



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

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

#errors(options = {}) ⇒ Object



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

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



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

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

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



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

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



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

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

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



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

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



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

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

#projects(options = {}) ⇒ Object



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

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

#projects_pathObject

projects



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

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

#unformatted_error_path(error_id) ⇒ Object

errors



56
57
58
# File 'lib/airbrake-api/client.rb', line 56

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

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



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

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

#url_for(endpoint, *args) ⇒ Object



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

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