diff --git a/lib/seatsio/domain.rb b/lib/seatsio/domain.rb index e81cf2b..f500a44 100644 --- a/lib/seatsio/domain.rb +++ b/lib/seatsio/domain.rb @@ -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' diff --git a/lib/seatsio/events.rb b/lib/seatsio/events.rb index de5f6a5..6c9cd48 100644 --- a/lib/seatsio/events.rb +++ b/lib/seatsio/events.rb @@ -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' } @@ -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' } diff --git a/lib/seatsio/events/change_object_status_in_batch_request.rb b/lib/seatsio/events/change_object_status_in_batch_request.rb deleted file mode 100644 index 023b514..0000000 --- a/lib/seatsio/events/change_object_status_in_batch_request.rb +++ /dev/null @@ -1,6 +0,0 @@ -def create_change_object_status_in_batch_request(event_key, object_or_objects, status, hold_token = nil , order_id = nil, keep_extra_data = nil, ignore_channels = nil, channel_keys = nil) - result = create_change_object_status_request(object_or_objects, status, hold_token, order_id, '', keep_extra_data, ignore_channels, channel_keys) - result.delete(:events) - result[:event] = event_key - result -end diff --git a/lib/seatsio/events/change_object_status_request.rb b/lib/seatsio/events/change_object_status_request.rb index 950e586..a6bfd0e 100644 --- a/lib/seatsio/events/change_object_status_request.rb +++ b/lib/seatsio/events/change_object_status_request.rb @@ -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 @@ -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 diff --git a/test/events/change_object_status_in_batch_test.rb b/test/events/change_object_status_in_batch_test.rb index 150ef38..88bf78b 100644 --- a/test/events/change_object_status_in_batch_test.rb +++ b/test/events/change_object_status_in_batch_test.rb @@ -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 @@ -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) @@ -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