Skip to content

Commit

Permalink
Allow for-sale config to be specified when events and seasons are cre…
Browse files Browse the repository at this point in the history
…ated (#89)

Co-authored-by: Steve Chaloner <[email protected]>
  • Loading branch information
schaloner and Steve Chaloner authored Oct 16, 2023
1 parent b513171 commit 82f6a4c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 12 deletions.
24 changes: 18 additions & 6 deletions lib/seatsio/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,26 @@ class ForSaleConfig

attr_reader :for_sale, :objects, :area_places, :categories

def initialize(data)
def initialize(for_sale, objects = nil, area_places = nil, categories = nil)
@for_sale = for_sale
@objects = objects
@area_places = area_places
@categories = categories
end

def self.from_json(data)
if data
@for_sale = data['forSale']
@objects = data['objects']
@area_places = data['areaPlaces']
@categories = data['categories']
ForSaleConfig.new(data['forSale'], data['objects'], data['areaPlaces'], data['categories'])
end
end

def == (other)
other != nil &&
for_sale == other.for_sale &&
objects == other.objects &&
area_places == other.area_places &&
categories == other.categories
end
end

class Category
Expand Down Expand Up @@ -160,7 +172,7 @@ def initialize(data)
@date = Date.iso8601(data['date']) if data['date']
@supports_best_available = data['supportsBestAvailable']
@table_booking_config = TableBookingConfig::from_json(data['tableBookingConfig'])
@for_sale_config = ForSaleConfig.new(data['forSaleConfig']) if data['forSaleConfig']
@for_sale_config = ForSaleConfig::from_json(data['forSaleConfig']) if data['forSaleConfig']
@created_on = parse_date(data['createdOn'])
@updated_on = parse_date(data['updatedOn'])
@channels = data['channels'].map {
Expand Down
17 changes: 14 additions & 3 deletions lib/seatsio/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def initialize(http_client)
@channels = ChannelsClient.new(@http_client)
end

def create(chart_key: nil, event_key: nil, name: nil, date: nil, table_booking_config: nil, object_categories: nil, categories: nil, channels: nil)
payload = build_event_request(chart_key, event_key, name, date, table_booking_config, object_categories, categories, channels: channels, is_in_the_past: nil)
def create(chart_key: nil, event_key: nil, name: nil, date: nil, table_booking_config: nil, object_categories: nil, categories: nil, channels: nil, for_sale_config: nil)
payload = build_event_request(chart_key, event_key, name, date, table_booking_config, object_categories, categories, channels: channels, is_in_the_past: nil, for_sale_config: for_sale_config)
response = @http_client.post("events", payload)
Event.new(response)
end
Expand Down Expand Up @@ -159,7 +159,7 @@ def build_extra_data_request(extra_data)
payload
end

def build_event_request(chart_key, event_key, name, date, table_booking_config, object_categories, categories, channels: nil, is_in_the_past: nil)
def build_event_request(chart_key, event_key, name, date, table_booking_config, object_categories, categories, channels: nil, is_in_the_past: nil, for_sale_config: nil)
result = {}
result["chartKey"] = chart_key if chart_key
result["eventKey"] = event_key if event_key
Expand All @@ -170,6 +170,7 @@ def build_event_request(chart_key, event_key, name, date, table_booking_config,
result["categories"] = categories_to_request(categories) if categories != nil
result["channels"] = ChannelsClient::channels_to_request(channels) if channels != nil
result["isInThePast"] = is_in_the_past if is_in_the_past != nil
result["forSaleConfig"] = for_sale_config_to_request(for_sale_config) if for_sale_config != nil
result
end

Expand All @@ -191,6 +192,7 @@ def event_creation_params_to_request(params)
r["objectCategories"] = param[:object_categories] if param[:object_categories] != nil
r["categories"] = categories_to_request(param[:categories]) if param[:categories] != nil
r["channels"] = ChannelsClient::channels_to_request(param[:channels]) if param[:channels] != nil
r["forSaleConfig"] = for_sale_config_to_request(param[:for_sale_config]) if param[:for_sale_config] != nil
result.push(r)
end
result
Expand All @@ -216,5 +218,14 @@ def categories_to_request(categories)
result
end

def for_sale_config_to_request(for_sale_config)
result = {}
result["forSale"] = for_sale_config.for_sale
result["objects"] = for_sale_config.objects if for_sale_config.objects != nil
result["areaPlaces"] = for_sale_config.area_places if for_sale_config.area_places != nil
result["categories"] = for_sale_config.categories if for_sale_config.categories != nil
result
end

end
end
16 changes: 13 additions & 3 deletions lib/seatsio/seasons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def initialize(http_client, seatsio_client)
end

def create(chart_key:, key: nil, number_of_events: nil, event_keys: nil,
table_booking_config: nil, channels: nil)
request = build_create_season_request(chart_key, key, number_of_events, event_keys, table_booking_config, channels)
table_booking_config: nil, channels: nil, for_sale_config: nil)
request = build_create_season_request(chart_key, key, number_of_events, event_keys, table_booking_config, channels, for_sale_config)
response = @http_client.post('seasons', request)
Season.new(response)
end
Expand Down Expand Up @@ -54,14 +54,15 @@ def remove_event_from_partial_season(top_level_season_key:, partial_season_key:,

private

def build_create_season_request(chart_key, key, number_of_events, event_keys, table_booking_config, channels)
def build_create_season_request(chart_key, key, number_of_events, event_keys, table_booking_config, channels, for_sale_config)
request = {}
request['chartKey'] = chart_key if chart_key
request['key'] = key if key
request['numberOfEvents'] = number_of_events if number_of_events
request['eventKeys'] = event_keys if event_keys
request['tableBookingConfig'] = table_booking_config_to_request(table_booking_config) if table_booking_config != nil
request['channels'] = ChannelsClient::channels_to_request(channels) if channels != nil
request['forSaleConfig'] = for_sale_config_to_request(for_sale_config) if for_sale_config != nil
request
end

Expand All @@ -72,5 +73,14 @@ def table_booking_config_to_request(table_booking_config)
request
end

def for_sale_config_to_request(for_sale_config)
result = {}
result["forSale"] = for_sale_config.for_sale
result["objects"] = for_sale_config.objects if for_sale_config.objects != nil
result["areaPlaces"] = for_sale_config.area_places if for_sale_config.area_places != nil
result["categories"] = for_sale_config.categories if for_sale_config.categories != nil
result
end

end
end
9 changes: 9 additions & 0 deletions test/events/create_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,13 @@ def test_channels

assert_equal(channels, event.channels)
end

def test_for_sale_config
chart_key = create_test_chart
for_sale_config = Seatsio::ForSaleConfig.new(false, ["A-1"], {"GA1" => 3}, ["Cat1"])

event = @seatsio.events.create chart_key: chart_key, for_sale_config: for_sale_config

assert_equal(for_sale_config, event.for_sale_config)
end
end
16 changes: 16 additions & 0 deletions test/events/create_events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,20 @@ def test_channels_can_be_passed_in
assert_equal(channels, event.channels)
end

def test_for_sale_config_can_be_passed_in
chart_key = create_test_chart
for_sale_config_1 = Seatsio::ForSaleConfig.new(false, ["A-1"], {"GA1" => 3}, ["Cat1"])
for_sale_config_2 = Seatsio::ForSaleConfig.new(false, ["A-2"], {"GA1" => 7}, ["Cat1"])
event_creation_params = [
{:for_sale_config => for_sale_config_1},
{:for_sale_config => for_sale_config_2}
]

events = @seatsio.events.create_multiple(key: chart_key, event_creation_params: event_creation_params)

assert_equal(2, events.length)
assert_equal(for_sale_config_1, events[0].for_sale_config)
assert_equal(for_sale_config_2, events[1].for_sale_config)
end

end
9 changes: 9 additions & 0 deletions test/seasons/create_season_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ def test_channels_can_be_passed_in

assert_equal(channels, season.channels)
end

def test_for_sale_config_can_be_passed_in
chart_key = create_test_chart
for_sale_config = Seatsio::ForSaleConfig.new(false, ["A-1"], {"GA1" => 3}, ["Cat1"])

season = @seatsio.seasons.create chart_key: chart_key, for_sale_config: for_sale_config

assert_equal(for_sale_config, season.for_sale_config)
end
end

0 comments on commit 82f6a4c

Please sign in to comment.