Skip to content

Commit

Permalink
Changing the status of an object with a numeric labels works fine now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mroloux committed Oct 3, 2018
1 parent 38e5464 commit 3eddb32
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 41 deletions.
17 changes: 1 addition & 16 deletions src/Events/BestAvailableObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,19 @@

namespace Seatsio\Events;

use Seatsio\SeatsioJsonMapper;

class BestAvailableObjects
{
/**
* @var string[]
*/
public $objects;
/**
* @var array
* @var array[Labels]
*/
public $labels;
/**
* @var boolean
*/
public $nextToEachOther;

/**
* @param $json
* @return BestAvailableObjects
*/
static function fromJson($json)
{
$mapper = SeatsioJsonMapper::create();
$result = $mapper->map($json, new BestAvailableObjects());
array_walk($result->labels, function ($labels, $id) use ($mapper, $result) {
$result->labels[$id] = $mapper->map($labels, new Labels());
});
return $result;
}
}
17 changes: 1 addition & 16 deletions src/Events/ChangeObjectStatusResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,11 @@

namespace Seatsio\Events;

use Seatsio\SeatsioJsonMapper;

class ChangeObjectStatusResult
{
/**
* @var array
* @var array[Labels]
*/
var $labels;

/**
* @param $json
* @return ChangeObjectStatusResult
*/
static function fromJson($json)
{
$mapper = SeatsioJsonMapper::create();
$result = $mapper->map($json, new ChangeObjectStatusResult());
array_walk($result->labels, function ($labels, $id) use ($mapper, $result) {
$result->labels[$id] = $mapper->map($labels, new Labels());
});
return $result;
}
}
6 changes: 4 additions & 2 deletions src/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public function changeObjectStatus($eventKeyOrKeys, $objectOrObjects, $status, $
['json' => $request, 'query' => ['expand' => 'labels']]
);
$json = \GuzzleHttp\json_decode($res->getBody());
return ChangeObjectStatusResult::fromJson($json);
$mapper = SeatsioJsonMapper::create();
return $mapper->map($json, new ChangeObjectStatusResult());
}

/**
Expand Down Expand Up @@ -360,7 +361,8 @@ public function changeBestAvailableObjectStatus($eventKey, $number, $status, $ca
['json' => $request]
);
$json = \GuzzleHttp\json_decode($res->getBody());
return BestAvailableObjects::fromJson($json);
$mapper = SeatsioJsonMapper::create();
return $mapper->map($json, new BestAvailableObjects());
}

private static function normalizeObjects($objectOrObjects)
Expand Down
10 changes: 8 additions & 2 deletions src/SeatsioJsonMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

use JsonMapper;

class SeatsioJsonMapper
class SeatsioJsonMapper extends JsonMapper
{
/**
* @return JsonMapper
*/
public static function create()
{
$mapper = new JsonMapper();
$mapper = new SeatsioJsonMapper();
$mapper->classMap["\DateTime"] = JsonDateTime::class;
return $mapper;
}

protected function getSafeName($name)
{
// avoid object labels such as B-4 being converted into B4
return $name;
}
}
4 changes: 2 additions & 2 deletions tests/Events/ChangeObjectStatusForMultipleObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public function testQuantity()
$event = $this->seatsioClient->events->create($chartKey);
$objects = [
(new ObjectProperties("GA1"))->setQuantity(5),
(new ObjectProperties("GA2"))->setQuantity(10)
(new ObjectProperties("34"))->setQuantity(10)
];

$this->seatsioClient->events->changeObjectStatus($event->key, $objects, "lolzor");

$status1 = $this->seatsioClient->events->retrieveObjectStatus($event->key, "GA1");
self::assertEquals(5, $status1->quantity);

$status2 = $this->seatsioClient->events->retrieveObjectStatus($event->key, "GA2");
$status2 = $this->seatsioClient->events->retrieveObjectStatus($event->key, "34");
self::assertEquals(10, $status2->quantity);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Events/ChangeObjectStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function testGA()
$chartKey = $this->createTestChart();
$event = $this->seatsioClient->events->create($chartKey);

$result = $this->seatsioClient->events->changeObjectStatus($event->key, "GA1", "lolzor");
$result = $this->seatsioClient->events->changeObjectStatus($event->key, "34", "lolzor");

self::assertEquals([
"GA1" => someLabels("GA1", "generalAdmission")
"34" => someLabels("34", "generalAdmission")
], $result->labels);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/sampleChart.json
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
"categoryLabel": "Cat2",
"categoryKey": 10,
"capacity": 100,
"label": "GA2",
"label": "34",
"labelSize": 24,
"labelShown": true,
"labelHorizontalOffset": 0,
Expand Down

0 comments on commit 3eddb32

Please sign in to comment.