Skip to content

Commit

Permalink
Added method to list event log items (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux authored Jan 17, 2024
1 parent 350a426 commit c0fff26
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/seatsio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
require 'seatsio/chart_reports'
require 'seatsio/event_reports'
require 'seatsio/usage_reports'
require 'seatsio/event_log'

module Seatsio
class Client
attr_reader :charts, :workspaces, :events, :seasons,
:hold_tokens, :chart_reports, :event_reports, :usage_reports
:hold_tokens, :chart_reports, :event_reports, :usage_reports, :event_log

def initialize(region, secret_key, workspace_key = nil, max_retries = 5)
base_url = region.url
Expand All @@ -24,6 +25,7 @@ def initialize(region, secret_key, workspace_key = nil, max_retries = 5)
@chart_reports = ChartReportsClient.new(@http_client)
@event_reports = EventReportsClient.new(@http_client)
@usage_reports = UsageReportsClient.new(@http_client)
@event_log = EventLogClient.new(@http_client)
end
end

Expand Down
12 changes: 12 additions & 0 deletions lib/seatsio/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ def initialize(data)
end
end

class EventLogItem
attr_reader :id, :workspace_key, :type, :date, :data

def initialize(data)
@id = data['id']
@workspace_key = data['workspaceKey']
@type = data['type']
@date = DateTime.iso8601(data['date'])
@data = data['data']
end
end

class ChangeObjectStatusResult

attr_reader :objects
Expand Down
27 changes: 27 additions & 0 deletions lib/seatsio/event_log.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require "seatsio/exception"
require "base64"
require "seatsio/httpClient"
require "seatsio/domain"
require "json"
require "cgi"

module Seatsio
class EventLogClient

def initialize(http_client)
@http_client = http_client
end

def list(filter: nil)
extended_cursor = cursor
extended_cursor.set_query_param('filter', filter)
extended_cursor
end

private

def cursor()
Pagination::Cursor.new(EventLogItem, 'event-log', @http_client)
end
end
end
32 changes: 32 additions & 0 deletions test/event_log/list_event_log_items_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'test_helper'
require 'util'

class ListEventLogItemsTest < SeatsioTestClient
def test_list_all_event_log_items
chart = @seatsio.charts.create
@seatsio.charts.update key: chart.key, new_name: 'a chart'

sleep(2)

event_log_items = @seatsio.event_log.list

types = event_log_items.collect { |event_log_item| event_log_item.type }
assert_equal(%w[chart.created chart.published], types)
end

def test_event_log_item_properties
chart = @seatsio.charts.create

sleep(2)

event_log_items = @seatsio.event_log.list
event_log_item = event_log_items.first_page.to_a[0]

assert_equal('chart.created', event_log_item.type)
assert_true(event_log_item.id > 0)
assert_not_nil(event_log_item.date)
assert_equal(@workspace.key, event_log_item.workspace_key)
assert_equal({ "key" => chart.key }, event_log_item.data)
end

end

0 comments on commit c0fff26

Please sign in to comment.