Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects can be released in batch #128

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/seatsio/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ def initialize(data)
end
end

class StatusChangeType
CHANGE_STATUS_TO = 'CHANGE_STATUS_TO'
RELEASE = 'RELEASE'
end

class EventObjectInfo
FREE = 'free'
BOOKED = 'booked'
Expand Down
4 changes: 2 additions & 2 deletions lib/seatsio/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def put_up_for_resale(event_key_or_keys, object_or_objects)
end

def change_object_status(event_key_or_keys, object_or_objects, status, hold_token: nil, order_id: nil, keep_extra_data: nil, ignore_channels: nil, channel_keys: nil, allowed_previous_statuses: nil, rejected_previous_statuses: nil)
request = create_change_object_status_request(object_or_objects, status, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys, allowed_previous_statuses, rejected_previous_statuses)
request = create_change_object_status_request(Seatsio::StatusChangeType::CHANGE_STATUS_TO, object_or_objects, status, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys, allowed_previous_statuses, rejected_previous_statuses)
request[:params] = {
:expand => 'objects'
}
Expand Down Expand Up @@ -117,7 +117,7 @@ def hold_best_available(key, number, hold_token, categories: nil, order_id: nil,
end

def release(event_key_or_keys, object_or_objects, hold_token: nil, order_id: nil, keep_extra_data: nil, ignore_channels: nil, channel_keys: nil)
request = create_release_objects_request(object_or_objects, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys)
request = create_change_object_status_request(Seatsio::StatusChangeType::RELEASE, object_or_objects, nil, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys, nil, nil)
request[:params] = {
:expand => 'objects'
}
Expand Down
6 changes: 0 additions & 6 deletions lib/seatsio/events/change_object_status_in_batch_request.rb

This file was deleted.

25 changes: 4 additions & 21 deletions lib/seatsio/events/change_object_status_request.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
def create_change_object_status_request(object_or_objects, status, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys, allowed_previous_statuses, rejected_previous_statuses)
def create_change_object_status_request(type, object_or_objects, status, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys, allowed_previous_statuses, rejected_previous_statuses)
result = {}
result[:type] = type
result[:objects] = normalize(object_or_objects)
result[:type] = 'CHANGE_STATUS_TO'
result[:status] = status
result[:type] = type
result[:status] = status if type != Seatsio::StatusChangeType::RELEASE
result[:holdToken] = hold_token if hold_token != nil
result[:orderId] = order_id if order_id != nil
if event_key_or_keys.is_a? Array
Expand All @@ -18,24 +19,6 @@ def create_change_object_status_request(object_or_objects, status, hold_token, o
result
end

def create_release_objects_request(object_or_objects, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys)
result = {}
result[:objects] = normalize(object_or_objects)
result[:type] = "RELEASE"
result[:holdToken] = hold_token if hold_token != nil
result[:orderId] = order_id if order_id != nil
if event_key_or_keys.is_a? Array
result[:events] = event_key_or_keys
else
result[:events] = [event_key_or_keys]
end
result[:keepExtraData] = keep_extra_data if keep_extra_data != nil
result[:ignoreChannels] = ignore_channels if ignore_channels != nil
result[:channelKeys] = channel_keys if channel_keys != nil
result
end


def normalize(object_or_objects)
if object_or_objects.is_a? Array
if object_or_objects.length == 0
Expand Down
18 changes: 16 additions & 2 deletions test/events/change_object_status_in_batch_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'test_helper'
require 'util'
require 'seatsio/domain'
require 'seatsio/events/change_object_status_in_batch_request'

class ChangeObjectStatusInBatchTest < SeatsioTestClient
def test_change_object_status_in_batch
Expand All @@ -10,7 +9,11 @@ def test_change_object_status_in_batch
chart_key2 = create_test_chart
event2 = @seatsio.events.create chart_key: chart_key2

res = @seatsio.events.change_object_status_in_batch([{ :event => event1.key, :objects => ['A-1'], :status => 'foo' }, { :event => event2.key, :objects => ['A-2'], :status => 'fa' }])
res = @seatsio.events.change_object_status_in_batch(
[
{ :type => Seatsio::StatusChangeType::CHANGE_STATUS_TO, :event => event1.key, :objects => ['A-1'], :status => 'foo' },
{ :event => event2.key, :objects => ['A-2'], :status => 'fa' }
])

assert_equal('foo', res[0].objects['A-1'].status)
assert_equal('foo', @seatsio.events.retrieve_object_info(key: event1.key, label: 'A-1').status)
Expand Down Expand Up @@ -80,4 +83,15 @@ def test_rejected_previous_statuses
assert_match /free is in the list of rejected previous statuses/, e.message.body
end
end

def release_in_batch
chart_key = create_test_chart
event = @seatsio.events.create chart_key: chart_key
@seatsio.events.book(event.key, ['A-1'])

res = @seatsio.events.change_object_status_in_batch([{ :type => Seatsio::StatusChangeType::RELEASE, :event => event.key, :objects => ['A-1'] }])

assert_equal(Seatsio::EventObjectInfo::FREE, res[0].objects['A-1'].status)
assert_equal(Seatsio::EventObjectInfo::FREE, @seatsio.events.retrieve_object_info(key: event.key, label: 'A-1').status)
end
end
Loading