4
4
5
5
use Illuminate \Http \Client \Response ;
6
6
use FiveamCode \LaravelNotionApi \Notion ;
7
- use GuzzleHttp \Promise \PromiseInterface ;
8
7
use FiveamCode \LaravelNotionApi \Query \StartCursor ;
9
8
use FiveamCode \LaravelNotionApi \Exceptions \NotionException ;
10
9
use FiveamCode \LaravelNotionApi \Exceptions \HandlingException ;
11
- use FiveamCode \LaravelNotionApi \Exceptions \LaravelNotionAPIException ;
12
10
11
+ /**
12
+ * Class Endpoint
13
+ * @package FiveamCode\LaravelNotionApi\Endpoints
14
+ */
13
15
class Endpoint
14
16
{
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 ' ;
21
23
24
+ /**
25
+ * @var Notion
26
+ */
22
27
public Notion $ notion ;
23
28
29
+ /**
30
+ * @var StartCursor|null
31
+ */
24
32
protected ?StartCursor $ startCursor = null ;
33
+
34
+ /**
35
+ * @var int
36
+ */
25
37
protected int $ pageSize = 100 ;
26
38
39
+ /**
40
+ * @var Response|null
41
+ */
27
42
protected ?Response $ response = null ;
28
43
29
44
/**
30
45
* Endpoint constructor.
31
46
* @param Notion $notion
32
47
* @throws HandlingException
33
- * @throws LaravelNotionAPIException
34
48
*/
35
49
public function __construct (Notion $ notion )
36
50
{
37
51
$ this ->notion = $ notion ;
38
52
39
53
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. ' );
41
55
}
42
56
}
43
57
@@ -69,10 +83,11 @@ protected function getJson(string $url): array
69
83
70
84
/**
71
85
* @param string $url
72
- * @throws HandlingException
86
+ * @return Response
73
87
* @throws NotionException
88
+ * @throws HandlingException
74
89
*/
75
- protected function get (string $ url )
90
+ protected function get (string $ url ): Response
76
91
{
77
92
$ response = $ this ->notion ->getConnection ()->get ($ url );
78
93
@@ -86,9 +101,11 @@ protected function get(string $url)
86
101
/**
87
102
* @param string $url
88
103
* @param array $body
89
- * @return PromiseInterface|Response
104
+ * @return Response
105
+ * @throws HandlingException
106
+ * @throws NotionException
90
107
*/
91
- protected function post (string $ url , array $ body )
108
+ protected function post (string $ url , array $ body ): Response
92
109
{
93
110
$ response = $ this ->notion ->getConnection ()->post ($ url , $ body );
94
111
@@ -105,7 +122,7 @@ protected function post(string $url, array $body)
105
122
*/
106
123
protected function buildPaginationQuery (): string
107
124
{
108
- $ paginationQuery = "" ;
125
+ $ paginationQuery = '' ;
109
126
110
127
if ($ this ->pageSize !== null )
111
128
$ paginationQuery = "page_size= {$ this ->pageSize }& " ;
@@ -131,12 +148,11 @@ public function limit(int $limit): Endpoint
131
148
* @param StartCursor $startCursor
132
149
* @return Endpoint
133
150
* @throws HandlingException
134
- * @throws LaravelNotionAPIException
135
151
*/
136
152
public function offset (StartCursor $ startCursor ): Endpoint
137
153
{
138
154
// toDo
139
- throw HandlingException::instance (" Not implemented yet. " );
155
+ throw HandlingException::instance (' Not implemented yet. ' , compact ( $ startCursor ) );
140
156
}
141
157
142
158
}
0 commit comments