Skip to content

Commit 14d0bc8

Browse files
ryanopilyryanopily
and
ryanopily
authored
Notes (#79)
* Added 'Notes' feature * Fixed return type in 'NotesResponse.php' * - Refactored variable names to camel case. - Ran 'composer run lint && composer run lint-fix' Co-authored-by: ryanopily <[email protected]>
1 parent 14049f7 commit 14d0bc8

File tree

6 files changed

+274
-0
lines changed

6 files changed

+274
-0
lines changed

src/Client/Client.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Instagram\SDK\Client\Features\FriendshipsFeaturesTrait;
1515
use Instagram\SDK\Client\Features\GeneralFeaturesTrait;
1616
use Instagram\SDK\Client\Features\MediaFeaturesTrait;
17+
use Instagram\SDK\Client\Features\NotesFeaturesTrait;
1718
use Instagram\SDK\Client\Features\SearchFeaturesTrait;
1819
use Instagram\SDK\Client\Features\UsersFeaturesTrait;
1920
use Instagram\SDK\Device\Builders\DeviceBuilder;
@@ -52,6 +53,7 @@ class Client
5253
use FeedFeaturesTrait;
5354
use FriendshipsFeaturesTrait;
5455
use MediaFeaturesTrait;
56+
use NotesFeaturesTrait;
5557
use UsersFeaturesTrait;
5658

5759
/** @var HttpClient */
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Instagram\SDK\Client\Features;
6+
7+
use GuzzleHttp\Promise\PromiseInterface;
8+
use Instagram\SDK\Exceptions\InstagramException;
9+
use Instagram\SDK\Request\Http\Factories\PayloadSerializerFactory;
10+
use Instagram\SDK\Request\Utils\SignatureUtils;
11+
use Instagram\SDK\Response\Responses\Common\GeneralResponse;
12+
use Instagram\SDK\Response\Responses\Notes\NotesResponse;
13+
use Instagram\SDK\Response\Responses\ResponseEnvelope;
14+
15+
/**
16+
* Trait NotesFeaturesTrait
17+
*
18+
* @package Instagram\SDK\Client\Features
19+
* @phan-file-suppress PhanUnreferencedUseNormal
20+
*/
21+
trait NotesFeaturesTrait
22+
{
23+
24+
use DefaultFeaturesTrait;
25+
26+
/**
27+
* Retrieve notes.
28+
*
29+
* @return PromiseInterface<NotesResponse|InstagramException>
30+
*/
31+
public function notes(): PromiseInterface
32+
{
33+
return $this->authenticated(function (): PromiseInterface {
34+
$request = $this->buildRequest('notes/get_notes/', new NotesResponse(), 'GET');
35+
36+
return $this->call($request);
37+
});
38+
}
39+
40+
/**
41+
* Create a note.
42+
*
43+
* @param string $text
44+
* @param int $audience
45+
* @return PromiseInterface<GeneralResponse|InstagramException>
46+
*/
47+
public function createNote(string $text, int $audience = 0): PromiseInterface
48+
{
49+
return $this->authenticated(function () use ($text, $audience): PromiseInterface {
50+
$request = $this->buildRequest('notes/create_note/', new GeneralResponse(), 'POST')
51+
->addUuid($this->session)
52+
->addPayloadParam('text', $text)
53+
->addPayloadParam('audience', $audience);
54+
55+
return $this->call($request);
56+
});
57+
}
58+
}

src/Response/DTO/Notes/Note.php

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Instagram\SDK\Response\DTO\Notes;
6+
7+
use Instagram\SDK\Response\DTO\General\User;
8+
9+
/**
10+
* Class Note
11+
*
12+
* @package Instagram\SDK\Payloads\Notes
13+
*/
14+
final class Note
15+
{
16+
17+
/**
18+
* @var int
19+
*/
20+
private $id;
21+
22+
/**
23+
* @var string
24+
*/
25+
private $text;
26+
27+
/**
28+
* @var int
29+
*/
30+
private $userId;
31+
32+
/**
33+
* @var User
34+
*/
35+
private $user;
36+
37+
/**
38+
* @var int
39+
*/
40+
private $audience;
41+
42+
/**
43+
* @var int
44+
*/
45+
private $createdAt;
46+
47+
/**
48+
* @var int
49+
*/
50+
private $expiresAt;
51+
52+
/**
53+
* @var bool
54+
*/
55+
private $isEmojiOnly;
56+
57+
/**
58+
* @var bool
59+
*/
60+
private $hasTranslation;
61+
62+
/**
63+
* @return int
64+
*/
65+
public function getId(): int
66+
{
67+
return $this->id;
68+
}
69+
70+
/**
71+
* @return string
72+
*/
73+
public function getText(): string
74+
{
75+
return $this->text;
76+
}
77+
78+
/**
79+
* @return int
80+
*/
81+
public function getUserId(): int
82+
{
83+
return $this->userId;
84+
}
85+
86+
/**
87+
* @return User
88+
*/
89+
public function getUser(): User
90+
{
91+
return $this->user;
92+
}
93+
94+
/**
95+
* @return int
96+
*/
97+
public function getAudience(): int
98+
{
99+
return $this->audience;
100+
}
101+
102+
/**
103+
* @return int
104+
*/
105+
public function getCreatedAt(): int
106+
{
107+
return $this->createdAt;
108+
}
109+
110+
/**
111+
* @return int
112+
*/
113+
public function getExpiresAt(): int
114+
{
115+
return $this->expiresAt;
116+
}
117+
118+
/**
119+
* @return bool
120+
*/
121+
public function isEmojiOnly(): bool
122+
{
123+
return $this->isEmojiOnly;
124+
}
125+
126+
/**
127+
* @return bool
128+
*/
129+
public function getHasTranslation(): bool
130+
{
131+
return $this->hasTranslation;
132+
}
133+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Instagram\SDK\Response\Responses\Notes;
6+
7+
use Instagram\SDK\Response\DTO\Notes\Note;
8+
use Instagram\SDK\Response\Responses\ResponseEnvelope;
9+
10+
/**
11+
* Class NotesResponse
12+
*
13+
* @package Instagram\SDK\Response\Responses\Notes
14+
*/
15+
final class NotesResponse extends ResponseEnvelope
16+
{
17+
18+
/**
19+
* @var Note[]
20+
*/
21+
private $items;
22+
23+
/**
24+
* @return Note[]
25+
*/
26+
public function getItems(): array
27+
{
28+
return $this->items;
29+
}
30+
}
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Instagram\SDK\Traits;
6+
7+
use Instagram\SDK\Client\Client;
8+
use Instagram\SDK\Exceptions\InstagramException;
9+
use Instagram\SDK\Response\Responses\Common\GeneralResponse;
10+
use Instagram\SDK\Response\Responses\Notes\NotesResponse;
11+
use Instagram\SDK\Utils\PromiseUtils;
12+
13+
/**
14+
* Trait MakeNotesRequestAccessible
15+
*
16+
* @package Instagram\SDK\Traits
17+
*/
18+
trait MakeNotesRequestAccessible
19+
{
20+
/**
21+
* Retrieve notes.
22+
*
23+
* @return NotesResponse
24+
* @throws InstagramException in case of an error
25+
*/
26+
public function notes(): NotesResponse
27+
{
28+
return PromiseUtils::wait($this->getClient()->notes());
29+
}
30+
31+
/**
32+
* Create a note.
33+
*
34+
* @param string $text
35+
* @param int $audience
36+
* @return GeneralResponse
37+
* @throws InstagramException in case of an error
38+
*/
39+
public function createNote(string $text, int $audience = 0): GeneralResponse
40+
{
41+
return PromiseUtils::wait($this->getClient()->createNote($text, $audience));
42+
}
43+
44+
/**
45+
* Returns the client.
46+
*
47+
* @return Client
48+
*/
49+
abstract protected function getClient(): Client;
50+
}

src/Traits/MakeRequestsAccessible.php

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ trait MakeRequestsAccessible
2222
use MakeSearchRequestsAccessible;
2323
use MakeFriendshipsRequestsAccessible;
2424
use MakeMediaRequestsAccessible;
25+
use MakeNotesRequestAccessible;
2526
use MakeUsersRequestAccessible;
2627

2728
/**

0 commit comments

Comments
 (0)