Class: AirbrakeAPI::Client
- Inherits:
-
Object
- Object
- AirbrakeAPI::Client
- Defined in:
- lib/airbrake-api/client.rb
Constant Summary collapse
- PER_PAGE =
30
- PARALLEL_WORKERS =
10
Instance Method Summary collapse
-
#deploys(project_id, options = {}) ⇒ Object
deploys.
- #deploys_path(project_id) ⇒ Object
- #error(error_id, options = {}) ⇒ Object
- #error_path(error_id) ⇒ Object
- #errors(options = {}) ⇒ Object
- #errors_path ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #notice(notice_id, error_id, options = {}) ⇒ Object
-
#notice_path(notice_id, error_id) ⇒ Object
notices.
- #notices(error_id, notice_options = {}, &block) ⇒ Object
- #notices_path(error_id) ⇒ Object
- #projects(options = {}) ⇒ Object
-
#projects_path ⇒ Object
projects.
-
#unformatted_error_path(error_id) ⇒ Object
errors.
- #update(error, options = {}) ⇒ Object
- #url_for(endpoint, *args) ⇒ Object
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(={}) attrs = AirbrakeAPI..merge() 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, = {}) results = request(:get, deploys_path(project_id), ) 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, = {}) results = request(:get, error_path(error_id), ) 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( = {}) results = request(:get, errors_path, ) results.group || results.groups end |
#errors_path ⇒ Object
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, = {}) hash = request(:get, notice_path(notice_id, error_id), ) 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, notice_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 132 133 |
# File 'lib/airbrake-api/client.rb', line 101 def notices(error_id, = {}, &block) = {} notices = [] page = [:page] page_count = 0 # a specific page is requested, only return that page # if no page is specified, start on page 1 if page [:pages] = 1 else page = 1 end while ![:pages] || (page_count + 1) <= [:pages] [:page] = page + page_count hash = request(:get, notices_path(error_id), ) batch = if [:raw] hash.notices else Parallel.map(hash.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( = {}) results = request(:get, projects_path, ) results.projects.project end |
#projects_path ⇒ Object
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, = {}) results = request(:put, unformatted_error_path(error), ) 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 [account_path, path.split('.').first].join('') end |