Skip to content

Commit

Permalink
Allow fine-grained control over the expanded chart fields
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Jul 15, 2024
1 parent 0d98fc1 commit f4523e3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
25 changes: 21 additions & 4 deletions lib/seatsio/charts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,34 @@ def publish_draft_version(chart_key)
@http_client.post("charts/#{chart_key}/version/draft/actions/publish")
end

def list(chart_filter: nil, tag: nil, expand_events: nil, with_validation: false)
def list(chart_filter: nil, tag: nil, expand_events: false, expand_validation: false, expand_venue_type: false)
cursor = Pagination::Cursor.new(Chart, 'charts', @http_client)
cursor.set_query_param('filter', chart_filter)
cursor.set_query_param('tag', tag)

cursor.set_query_param('expand', 'events') if expand_events
cursor.set_query_param('validation', with_validation) if with_validation

expand_params = list_expand_params(expand_events, expand_validation, expand_venue_type)
cursor.set_query_param('expand', expand_params) unless expand_params.empty?
cursor
end

def list_expand_params(expand_events, expand_validation, expand_venue_type)
result = []

if expand_events
result.push('events')
end

if expand_validation
result.push('validation')
end

if expand_venue_type
result.push('venueType')
end

result
end

def list_all_tags
response = @http_client.get('charts/tags')
response['tags']
Expand Down
2 changes: 1 addition & 1 deletion lib/seatsio/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def retrieve_object_info(key:, label:)

def retrieve_object_infos(key:, labels:)
url = "events/#{key}/objects"
query_params = URI.encode_www_form(labels.map { |label| ['label', label] })
query_params = URI.encode_www_form({ label: labels })
response = @http_client.get(url, query_params)
response.each do |key, value|
response[key] = EventObjectInfo.new(value)
Expand Down
2 changes: 1 addition & 1 deletion lib/seatsio/pagination/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def keep_running?
end

def fetch_next_page
response = @http_client.get(@endpoint, @params)
response = @http_client.get(@endpoint, URI.encode_www_form(@params))

if response.nil? || response['items'].empty?
@last_response_empty = true
Expand Down
27 changes: 12 additions & 15 deletions test/charts/list_all_charts_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,40 +51,37 @@ def test_tag_and_filter
assert_equal([chart1.key], keys)
end

def test_expand
def test_expand_all
chart = @seatsio.charts.create
event1 = @seatsio.events.create chart_key: chart.key
event2 = @seatsio.events.create chart_key: chart.key

retrieved_charts = @seatsio.charts.list(expand_events: true).to_a
retrieved_charts = @seatsio.charts.list(expand_events: true, expand_validation: true, expand_venue_type: true).to_a

assert_instance_of(Seatsio::Event, retrieved_charts[0].events[0])

event_ids = retrieved_charts[0].events.collect {|event| event.id}
assert_equal([event2.id, event1.id], event_ids)
assert_equal('MIXED', retrieved_charts[0].venue_type)
assert_not_nil(retrieved_charts[0].validation)
end

def test_with_validation
@seatsio.charts.create

retrieved_charts = @seatsio.charts.list(with_validation: true).to_a

assert_equal({"errors" => [], "warnings" => []}, retrieved_charts[0].validation)
end

def test_without_validation
@seatsio.charts.create
def test_expand_none
chart = @seatsio.charts.create
event1 = @seatsio.events.create chart_key: chart.key
event2 = @seatsio.events.create chart_key: chart.key

retrieved_charts = @seatsio.charts.list().to_a
retrieved_charts = @seatsio.charts.list.to_a

assert_equal(nil, retrieved_charts[0].validation)
assert_nil(retrieved_charts[0].events)
assert_nil(retrieved_charts[0].validation)
assert_nil(retrieved_charts[0].venue_type)
end

def test_without_charts
charts = @seatsio.charts.list.to_a

assert_equal([], charts)

end

def test_chart_amount
Expand Down

0 comments on commit f4523e3

Please sign in to comment.