Skip to content

Commit

Permalink
use new RELEASE statusChangeCommand type instead of hardcoded FREE st…
Browse files Browse the repository at this point in the history
…atus, when releasing objects (#126)

* use new RELEASE statusChangeCommand type instead of hardcoded FREE status, when releasing objects

* refactoring
  • Loading branch information
bverbeken authored Oct 4, 2024
1 parent 87450ba commit f9ca086
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/seatsio/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ 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)
change_object_status(event_key_or_keys, object_or_objects, Seatsio::EventObjectInfo::FREE, hold_token: hold_token, order_id: order_id, keep_extra_data: keep_extra_data, ignore_channels: ignore_channels, channel_keys: channel_keys)
request = create_release_objects_request(object_or_objects, hold_token, order_id, event_key_or_keys, keep_extra_data, ignore_channels, channel_keys)
request[:params] = {
:expand => 'objects'
}
response = @http_client.post("events/groups/actions/change-object-status", request)
ChangeObjectStatusResult.new(response)
end

def delete(key:)
Expand Down
19 changes: 19 additions & 0 deletions lib/seatsio/events/change_object_status_request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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)
result = {}
result[:objects] = normalize(object_or_objects)
result[:type] = 'CHANGE_STATUS_TO'
result[:status] = status
result[:holdToken] = hold_token if hold_token != nil
result[:orderId] = order_id if order_id != nil
Expand All @@ -17,6 +18,24 @@ 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

0 comments on commit f9ca086

Please sign in to comment.