44
55use Illuminate \Http \Client \Response ;
66use FiveamCode \LaravelNotionApi \Notion ;
7- use GuzzleHttp \Promise \PromiseInterface ;
87use FiveamCode \LaravelNotionApi \Query \StartCursor ;
98use FiveamCode \LaravelNotionApi \Exceptions \NotionException ;
109use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
11- use FiveamCode \LaravelNotionApi \Exceptions \LaravelNotionAPIException ;
1210
11+ /**
12+ * Class Endpoint
13+ * @package FiveamCode\LaravelNotionApi\Endpoints
14+ */
1315class Endpoint
1416{
15- const BASE_URL = 'https://api.notion.com/ ' ;
16- const DATABASES = 'databases ' ;
17- const BLOCKS = 'blocks ' ;
18- const PAGES = 'pages ' ;
19- const USERS = 'users ' ;
20- const SEARCH = 'search ' ;
17+ public const BASE_URL = 'https://api.notion.com/ ' ;
18+ public const DATABASES = 'databases ' ;
19+ public const BLOCKS = 'blocks ' ;
20+ public const PAGES = 'pages ' ;
21+ public const USERS = 'users ' ;
22+ public const SEARCH = 'search ' ;
2123
24+ /**
25+ * @var Notion
26+ */
2227 public Notion $ notion ;
2328
29+ /**
30+ * @var StartCursor|null
31+ */
2432 protected ?StartCursor $ startCursor = null ;
33+
34+ /**
35+ * @var int
36+ */
2537 protected int $ pageSize = 100 ;
2638
39+ /**
40+ * @var Response|null
41+ */
2742 protected ?Response $ response = null ;
2843
2944 /**
3045 * Endpoint constructor.
3146 * @param Notion $notion
3247 * @throws HandlingException
33- * @throws LaravelNotionAPIException
3448 */
3549 public function __construct (Notion $ notion )
3650 {
3751 $ this ->notion = $ notion ;
3852
3953 if ($ this ->notion ->getConnection () === null ) {
40- throw HandlingException::instance (" Connection could not be established, please check your token. " );
54+ throw HandlingException::instance (' Connection could not be established, please check your token. ' );
4155 }
4256 }
4357
@@ -69,10 +83,11 @@ protected function getJson(string $url): array
6983
7084 /**
7185 * @param string $url
72- * @throws HandlingException
86+ * @return Response
7387 * @throws NotionException
88+ * @throws HandlingException
7489 */
75- protected function get (string $ url )
90+ protected function get (string $ url ): Response
7691 {
7792 $ response = $ this ->notion ->getConnection ()->get ($ url );
7893
@@ -86,9 +101,11 @@ protected function get(string $url)
86101 /**
87102 * @param string $url
88103 * @param array $body
89- * @return PromiseInterface|Response
104+ * @return Response
105+ * @throws HandlingException
106+ * @throws NotionException
90107 */
91- protected function post (string $ url , array $ body )
108+ protected function post (string $ url , array $ body ): Response
92109 {
93110 $ response = $ this ->notion ->getConnection ()->post ($ url , $ body );
94111
@@ -105,7 +122,7 @@ protected function post(string $url, array $body)
105122 */
106123 protected function buildPaginationQuery (): string
107124 {
108- $ paginationQuery = "" ;
125+ $ paginationQuery = '' ;
109126
110127 if ($ this ->pageSize !== null )
111128 $ paginationQuery = "page_size= {$ this ->pageSize }& " ;
@@ -131,12 +148,11 @@ public function limit(int $limit): Endpoint
131148 * @param StartCursor $startCursor
132149 * @return Endpoint
133150 * @throws HandlingException
134- * @throws LaravelNotionAPIException
135151 */
136152 public function offset (StartCursor $ startCursor ): Endpoint
137153 {
138154 // toDo
139- throw HandlingException::instance (" Not implemented yet. " );
155+ throw HandlingException::instance (' Not implemented yet. ' , compact ( $ startCursor ) );
140156 }
141157
142158}
0 commit comments