class SentrySummary::Sentry

Attributes

organization[W]
token[W]

Public Class Methods

new(&block) click to toggle source
# File lib/sentry-summary/sentry.rb, line 8
def initialize(&block)
  block.call(self)
end

Public Instance Methods

events(issue, since = nil) click to toggle source
# File lib/sentry-summary/sentry.rb, line 25
def events(issue, since = nil)
  paginate("/issues/#{issue}/events/", since) do |event|
    Event.build(event.merge(issue_id: issue))
  end
end
issues(project, since = nil) click to toggle source
# File lib/sentry-summary/sentry.rb, line 12
def issues(project, since = nil)
  paginate("projects/#{@organization}/#{project}/issues/", since) do |issue|
    Issue.build(issue)
  end
end
latest_samples(project) click to toggle source
# File lib/sentry-summary/sentry.rb, line 18
def latest_samples(project)
  issues(project).map do |issue|
    dto = request(:get, "issues/#{issue.id}/events/latest/").merge(issue_id: issue.id)
    Event.build(dto)
  end
end

Private Instance Methods

base_url() click to toggle source
# File lib/sentry-summary/sentry.rb, line 50
def base_url
  "https://app.getsentry.com/api/0"
end
paginate(path, since, &block) click to toggle source
# File lib/sentry-summary/sentry.rb, line 54
def paginate(path, since, &block)
  since ||= "24 hours ago"
  since = Chronic.parse(since)

  items = []
  cursor = nil

  begin
    response = request(:get, path, cursor: cursor)
    new_items = response.body.map(&block)

    items_in_time_range = new_items.select { |item| item.date >= since }
    items.concat(items_in_time_range)

    cursor = response.cursor
  end while response.next? && new_items.count == items_in_time_range.count

  items
end
request(method, path, parameters = {}) click to toggle source
# File lib/sentry-summary/sentry.rb, line 33
def request(method, path, parameters = {})
  response = Nestful::Request.new("#{base_url}/#{path}",
    method: method,
    auth_type: :bearer,
    password: @token,
    params: parameters
  ).execute

  links = response.headers["Link"].split(",").map do |link|
    Link.build(link)
  end

  next_link = links.find { |link| link.rel == :next && link.results? }

  Response.new(JSON.parse(response.body, symbolize_names: true), next_link)
end