Skip to content

Commit 56bc6e4

Browse files
authored
Merge pull request #145 from rbibby/50-add-request-id-to-reply-objects
Reply Client updates
2 parents 7f2c8e3 + 89bf49f commit 56bc6e4

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

src/PSS/Entities/Reply.php

+8
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44

55
class Reply
66
{
7+
/**
8+
* @var int
9+
*/
710
public $id;
811

12+
/**
13+
* @var int
14+
*/
15+
public $requestId;
16+
917
/**
1018
* @var \UKFast\SDK\Pss\Entities\Author
1119
*/

src/PSS/ReplyClient.php

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ public function getById($id)
4141
return $this->serializeReply($body->data);
4242
}
4343

44+
/**
45+
* Gets a paginated response of all replies to a ticket
46+
*
47+
* @param int $requestId - ID of request replies belong to
48+
* @param int $page
49+
* @param int $perPage
50+
* @param array $filters
51+
* @return \UKFast\SDK\Page
52+
*/
53+
public function getPageWithoutRequest($page = 1, $perPage = 15, $filters = [])
54+
{
55+
$page = $this->paginatedRequest("v1/replies", $page, $perPage, $filters);
56+
$page->serializeWith(function ($item) {
57+
return $this->serializeReply($item);
58+
});
59+
60+
return $page;
61+
}
62+
4463
/**
4564
* @param int $requestId
4665
* @param \UKFast\SDK\PSS\Entities\Reply $reply
@@ -118,6 +137,7 @@ protected function serializeReply($item)
118137
$reply = new Entities\Reply;
119138

120139
$reply->id = $item->id;
140+
$reply->requestId = $item->request_id;
121141
$reply->author = new Entities\Author($item->author);
122142
$reply->description = $item->description;
123143
$reply->createdAt = DateTime::createFromFormat(DateTime::ISO8601, $item->created_at);

tests/PssClientTest.php

+76
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public function gets_replies()
8888
new Response(200, [], json_encode([
8989
'data' => [[
9090
'id' => 1,
91+
'request_id' => 123456,
9192
'author' => [
9293
'id' => 1,
9394
'name' => 'Jonny Test',
@@ -125,6 +126,7 @@ public function gets_replies()
125126
$reply = $page->getItems()[0];
126127

127128
$this->assertEquals(1, $reply->id);
129+
$this->assertEquals(123456, $reply->requestId);
128130
$this->assertEquals(1, $reply->author->id);
129131
$this->assertEquals('Jonny Test', $reply->author->name);
130132
$this->assertFalse($reply->read);
@@ -142,6 +144,7 @@ public function gets_replies_with_attachments()
142144
new Response(200, [], json_encode([
143145
'data' => [[
144146
'id' => 1,
147+
'request_id' => 123456,
145148
'author' => [
146149
'id' => 1,
147150
'name' => 'Jonny Test',
@@ -302,6 +305,7 @@ public function gets_one_reply()
302305
new Response(200, [], json_encode([
303306
'data' => [
304307
'id' => "C485939",
308+
'request_id' => 123456,
305309
'author' => [
306310
'id' => 10,
307311
'name' => 'Test Man',
@@ -323,8 +327,80 @@ public function gets_one_reply()
323327

324328
$this->assertTrue($reply instanceof \UKFast\SDK\PSS\Entities\Reply);
325329
$this->assertEquals('C485939', $reply->id);
330+
$this->assertEquals(123456, $reply->requestId);
326331
$this->assertEquals('test', $reply->description);
327332
$this->assertInstanceOf(DateTime::class, $reply->createdAt);
328333
$this->assertTrue($reply->read);
329334
}
335+
336+
/**
337+
* @test
338+
*/
339+
public function gets_replies_without_request_id()
340+
{
341+
$mock = new MockHandler([
342+
new Response(200, [], json_encode([
343+
'data' => [
344+
[
345+
'id' => 1,
346+
'request_id' => 123456,
347+
'author' => [
348+
'id' => 1,
349+
'name' => 'Jonny Test',
350+
'type' => 'Client',
351+
],
352+
'description' => 'Test',
353+
'created_at' => '2000-01-01T00:00:00+00',
354+
'attachments' => [],
355+
'read' => false,
356+
],
357+
[
358+
'id' => 1,
359+
'request_id' => 654321,
360+
'author' => [
361+
'id' => 1,
362+
'name' => 'Jonny Test',
363+
'type' => 'Client',
364+
],
365+
'description' => 'Test 2',
366+
'created_at' => '2000-01-01T00:00:00+00',
367+
'attachments' => [],
368+
'read' => false,
369+
]
370+
],
371+
'meta' => [
372+
'pagination' => [
373+
'total' => 2,
374+
'count' => 1,
375+
'per_page' => 2,
376+
'total_pages' => 1,
377+
'links' => [
378+
'next' => 'http://example.com/next',
379+
'previous' => 'http://example.com/previous',
380+
'first' => 'http://example.com/first',
381+
'last' => 'http://example.com/last',
382+
]
383+
]
384+
]
385+
])),
386+
]);
387+
$handler = HandlerStack::create($mock);
388+
$guzzle = new Client(['handler' => $handler]);
389+
390+
$client = new \UKFast\SDK\PSS\Client($guzzle);
391+
$page = $client->replies()->getPageWithoutRequest();
392+
393+
$this->assertTrue($page instanceof \UKFast\SDK\Page);
394+
395+
$reply = $page->getItems()[0];
396+
397+
$this->assertEquals(1, $reply->id);
398+
$this->assertEquals(123456, $reply->requestId);
399+
$this->assertEquals(1, $reply->author->id);
400+
$this->assertEquals('Jonny Test', $reply->author->name);
401+
$this->assertFalse($reply->read);
402+
$this->assertEquals('Test', $reply->description);
403+
$this->assertInstanceOf(DateTime::class, $reply->createdAt);
404+
$this->assertEquals('2000-01-01 00:00:00', $reply->createdAt->format('Y-m-d H:i:s'));
405+
}
330406
}

0 commit comments

Comments
 (0)