Skip to content

Commit

Permalink
Added support for changing object status in batch
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Feb 18, 2020
1 parent 2c787be commit bbfc4ed
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,41 @@ public function changeObjectStatus($eventKeyOrKeys, $objectOrObjects, $status, $
return $mapper->map($json, new ChangeObjectStatusResult());
}

/**
* @param $statusChangeRequests StatusChangeRequest[]
* @return ChangeObjectStatusResult[]
*/
public function changeObjectStatusInBatch($statusChangeRequests) {
$request = new \stdClass();
$request->statusChanges = \Functional\map($statusChangeRequests, function($statusChangeRequest) {
return $this->serializeStatusChangeRequest($statusChangeRequest);
});
$res = $this->client->post(
'/events/actions/change-object-status',
['json' => $request, 'query' => ['expand' => 'objects']]
);
$json = \GuzzleHttp\json_decode($res->getBody());
$mapper = SeatsioJsonMapper::create();
return $mapper->mapArray($json->results, array(), ChangeObjectStatusResult::class);
}

private function serializeStatusChangeRequest($statusChangeRequest) {
$request = new \stdClass();
$request->event = $statusChangeRequest->event;
$request->objects = self::normalizeObjects($statusChangeRequest->objectOrObjects);
$request->status = $statusChangeRequest->status;
if ($statusChangeRequest->holdToken !== null) {
$request->holdToken = $statusChangeRequest->holdToken;
}
if ($statusChangeRequest->orderId !== null) {
$request->orderId = $statusChangeRequest->orderId;
}
if ($statusChangeRequest->keepExtraData !== null) {
$request->keepExtraData = $statusChangeRequest->keepExtraData;
}
return $request;
}

/**
* @param $eventKeyOrKeys string|string[]
* @param $objectOrObjects mixed
Expand Down
46 changes: 46 additions & 0 deletions src/Events/StatusChangeRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Seatsio\Events;

class StatusChangeRequest
{
/**
* @var string
*/
public $event;

/**
* @var mixed
*/
public $objectOrObjects;

/**
* @var string
*/
public $status;

/**
* @var string
*/
public $holdToken;

/**
* @var string
*/
public $orderId;

/**
* @var boolean
*/
public $keepExtraData;

public function __construct($event, $objectOrObjects, $status, $holdToken = null, $orderId = null, $keepExtraData = null)
{
$this->event = $event;
$this->objectOrObjects = $objectOrObjects;
$this->status = $status;
$this->holdToken = $holdToken;
$this->orderId = $orderId;
$this->keepExtraData = $keepExtraData;
}
}
31 changes: 31 additions & 0 deletions tests/Events/ChangeObjectStatusInBatchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Seatsio\Events;

use Seatsio\SeatsioClientTest;

class ChangeObjectStatusInBatchTest extends SeatsioClientTest
{

public function test()
{
$chartKey1 = $this->createTestChart();
$chartKey2 = $this->createTestChart();
$event1 = $this->seatsioClient->events->create($chartKey1);
$event2 = $this->seatsioClient->events->create($chartKey2);

$response = $this->seatsioClient->events->changeObjectStatusInBatch([
new StatusChangeRequest($event1->key, "A-1", "lolzor"),
new StatusChangeRequest($event2->key, "A-2", "lolzor")
]);

self::assertEquals('lolzor', $response[0]->objects['A-1']->status);
$objectStatus1 = $this->seatsioClient->events->retrieveObjectStatus($event1->key, "A-1");
self::assertEquals("lolzor", $objectStatus1->status);

self::assertEquals('lolzor', $response[1]->objects['A-2']->status);
$objectStatus2 = $this->seatsioClient->events->retrieveObjectStatus($event2->key, "A-2");
self::assertEquals("lolzor", $objectStatus2->status);
}

}

0 comments on commit bbfc4ed

Please sign in to comment.