Module: Rolltools::Utils

Defined in:
lib/rolltools/utils.rb

Class Method Summary collapse

Class Method Details

.connObject



6
7
8
# File 'lib/rolltools/utils.rb', line 6

def self.conn
  @conn ||= Faraday.new("https://api.rollbar.com")
end

.get_item_for_counter(counter) ⇒ Object



10
11
12
13
14
15
# File 'lib/rolltools/utils.rb', line 10

def self.get_item_for_counter(counter)
  token = Rolltools::Settings.get('read_token')
  raise "token is not set, use 'rolltools set_config token VALUE'" if token.nil?
  get_item_id_res = conn.get "/api/1/item_by_counter/#{counter}", access_token: token
  JSON.parse(get_item_id_res.body)['result']['itemId']
end

.get_items(counter) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rolltools/utils.rb', line 17

def self.get_items(counter)
  token = Rolltools::Settings.get('read_token')
  raise "token is not set, use 'rolltools set_config token VALUE'" if token.nil?
  item_id = get_item_for_counter(counter)

  Enumerator.new do |y|
    page = 1
    begin
      get_item_res = conn.get "/api/1/item/#{item_id}/instances/", access_token: token, page: page
      item = JSON.parse(get_item_res.body)
      item['result']['instances'].each do |i| 
        e = i['data']['body']['trace']['exception']
        y << {  url: i['data']['request']['url'],
                user_agent: i['data']['request']['headers']['User-Agent'],
                instance_id: i['id'],
                exception: "#{e['class']} #{e['message']}"
              }
      end
      page += 1
    end until item['result']['instances'].empty?
  end
end