Skip to content

Commit

Permalink
Added cursor for some api endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
siarheipashkevich committed Feb 22, 2025
1 parent a98396a commit cc296cf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/Actions/ManagesEmployees.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ trait ManagesEmployees
* Get a list of employees.
*
* @param array $parameters
* @return Employee[]
* @return array{employees: Employee[], cursor: string}
*/
public function employees(array $parameters = []): array
{
return $this->transformCollection($this->get('employees', $parameters)['employees'], Employee::class);
$response = $this->get('employees', $parameters);

return [
'employees' => $this->transformCollection($response['employees'], Employee::class),
'cursor' => $response['cursor'],
];
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Actions/ManagesItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ trait ManagesItems
* Get a list of items.
*
* @param array $parameters
* @return Item[]
* @return array{items: Item[], cursor: string}
*/
public function items(array $parameters = []): array
{
return $this->transformCollection($this->get('items', $parameters)['items'], Item::class);
$response = $this->get('items', $parameters);

return [
'items' => $this->transformCollection($response['items'], Item::class),
'cursor' => $response['cursor'],
];
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Actions/ManagesReceipts.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ trait ManagesReceipts
* Get a list of receipts.
*
* @param array $parameters
* @return Receipt[]
* @return array{receipts: Receipt[], cursor: string}
*/
public function receipts(array $parameters = []): array
{
return $this->transformCollection($this->get('receipts', $parameters)['receipts'], Receipt::class);
$response = $this->get('receipts', $parameters);

return [
'receipts' => $this->transformCollection($response['receipts'], Receipt::class),
'cursor' => $response['cursor'],
];
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Actions/ManagesShifts.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ trait ManagesShifts
* Get a list of shifts.
*
* @param array $parameters
* @return Shift[]
* @return array{shifts: Shift[], cursor: string}
*/
public function shifts(array $parameters = []): array
{
return $this->transformCollection($this->get('shifts', $parameters)['shifts'], Shift::class);
$response = $this->get('shifts', $parameters);

return [
'shifts' => $this->transformCollection($response['shifts'], Shift::class),
'cursor' => $response['cursor'],
];
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Actions/ManagesVariants.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ trait ManagesVariants
* Get a list of item variants.
*
* @param array $parameters
* @return Variant[]
* @return array{variants: Variant[], cursor: string}
*/
public function variants(array $parameters = []): array
{
return $this->transformCollection($this->get('variants', $parameters)['variants'], Variant::class);
$response = $this->get('variants', $parameters);

return [
'variants' => $this->transformCollection($response['variants'], Variant::class),
'cursor' => $response['cursor'],
];
}

/**
Expand Down
7 changes: 5 additions & 2 deletions tests/LoyverseSDKTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ public function test_making_basic_requests()
$response->shouldReceive('getStatusCode')->once()->andReturn(200);
$response->shouldReceive('getBody')
->once()
->andReturn(Utils::streamFor('{"employees": [{"key": "value"}]}'));
->andReturn(Utils::streamFor('{"employees": [{"key": "value"}], "cursor": "value"}'));

$this->assertCount(1, $loyverse->employees());
$response = $loyverse->employees();

$this->assertCount(1, $response['employees']);
$this->assertIsString($response['cursor']);
}

public function test_handling_unknown_exception()
Expand Down

0 comments on commit cc296cf

Please sign in to comment.