This repository was archived by the owner on Jun 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +90
-11
lines changed Expand file tree Collapse file tree 5 files changed +90
-11
lines changed Original file line number Diff line number Diff line change @@ -38,4 +38,11 @@ public function addToken(Token $token);
38
38
* @param TokenUUID $tokenUUID
39
39
*/
40
40
public function deleteToken (TokenUUID $ tokenUUID );
41
+
42
+ /**
43
+ * Get tokens.
44
+ *
45
+ * @return Token[]
46
+ */
47
+ public function getTokens (): array ;
41
48
}
Original file line number Diff line number Diff line change @@ -40,8 +40,9 @@ public function addToken(Token $token)
40
40
'post ' ,
41
41
Http::getQueryValues ($ this ),
42
42
[
43
- 'token ' => json_encode ($ token ->toArray ()),
44
- ]);
43
+ Http::TOKEN_FIELD => json_encode ($ token ->toArray ()),
44
+ ]
45
+ );
45
46
46
47
$ this ->throwTransportableExceptionIfNeeded ($ response );
47
48
}
@@ -60,9 +61,32 @@ public function deleteToken(TokenUUID $tokenUUID)
60
61
'delete ' ,
61
62
Http::getQueryValues ($ this ),
62
63
[
63
- 'token ' => json_encode ($ tokenUUID ->toArray ()),
64
- ]);
64
+ Http::TOKEN_FIELD => json_encode ($ tokenUUID ->toArray ()),
65
+ ]
66
+ );
65
67
66
68
$ this ->throwTransportableExceptionIfNeeded ($ response );
67
69
}
70
+
71
+ /**
72
+ * Get tokens.
73
+ *
74
+ * @return Token[]
75
+ */
76
+ public function getTokens (): array
77
+ {
78
+ $ response = $ this
79
+ ->httpClient
80
+ ->get (
81
+ '/token ' ,
82
+ 'get ' ,
83
+ Http::getQueryValues ($ this )
84
+ );
85
+
86
+ $ this ->throwTransportableExceptionIfNeeded ($ response );
87
+
88
+ return array_map (function (array $ token ) {
89
+ return Token::createFromArray ($ token );
90
+ }, $ response ['body ' ]);
91
+ }
68
92
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Apisearch PHP Client.
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ *
9
+ * Feel free to edit as you please, and have fun.
10
+ *
11
+ * @author Marc Morera <[email protected] >
12
+ * @author PuntMig Technologies
13
+ */
14
+
15
+ declare (strict_types=1 );
16
+
17
+ namespace Apisearch \Exception ;
18
+
19
+ /**
20
+ * Class ConnectionException.
21
+ */
22
+ class ConnectionException extends TransportableException
23
+ {
24
+ /**
25
+ * Get http error code.
26
+ *
27
+ * @return int
28
+ */
29
+ public static function getTransportableHTTPError (): int
30
+ {
31
+ return 500 ;
32
+ }
33
+ }
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ public static function all(): array
50
50
'path ' => '/v1/index/reset ' ,
51
51
'verb ' => 'post ' ,
52
52
],
53
+ 'v1-config ' => [
54
+ 'name ' => 'Config ' ,
55
+ 'description ' => 'Configure your index ' ,
56
+ 'path ' => '/v1/index ' ,
57
+ 'verb ' => 'PUT ' ,
58
+ ],
53
59
54
60
/*
55
61
* Write endpoints
@@ -100,22 +106,28 @@ public static function all(): array
100
106
'path ' => '/v1/logs/stream ' ,
101
107
'verb ' => 'get ' ,
102
108
],
103
- 'v1-config ' => [
104
- 'name ' => 'Config ' ,
105
- 'description ' => 'Configure your index ' ,
106
- 'path ' => '/v1/index ' ,
107
- 'verb ' => 'PUT ' ,
109
+ 'v1-tokens ' => [
110
+ 'name ' => 'Get tokens ' ,
111
+ 'description ' => 'Get app tokens ' ,
112
+ 'path ' => '/v1/token ' ,
113
+ 'verb ' => 'GET ' ,
108
114
],
109
115
110
116
/*
111
117
* Interaction endpoints
112
118
*/
113
119
'v1-interaction ' => [
114
- 'name ' => 'Interactions ' ,
115
- 'description ' => 'Push interactions ' ,
120
+ 'name ' => 'Add interaction ' ,
121
+ 'description ' => 'Push a new interaction ' ,
116
122
'path ' => '/v1/interaction ' ,
117
123
'verb ' => 'get ' ,
118
124
],
125
+ 'v1-interactions-delete ' => [
126
+ 'name ' => 'Delete Interactions ' ,
127
+ 'description ' => 'Delete all stored interactions ' ,
128
+ 'path ' => '/v1/interaction ' ,
129
+ 'verb ' => 'delete ' ,
130
+ ],
119
131
];
120
132
}
121
133
Original file line number Diff line number Diff line change 16
16
17
17
namespace Apisearch \Http ;
18
18
19
+ use Apisearch \Exception \ConnectionException ;
19
20
use Apisearch \Exception \InvalidFormatException ;
20
21
use Apisearch \Exception \InvalidTokenException ;
21
22
use Apisearch \Exception \ResourceExistsException ;
@@ -44,6 +45,8 @@ protected function throwTransportableExceptionIfNeeded(array $response)
44
45
throw new InvalidFormatException ($ response ['body ' ]['message ' ]);
45
46
case ResourceExistsException::getTransportableHTTPError ():
46
47
throw new ResourceExistsException ($ response ['body ' ]['message ' ]);
48
+ case ConnectionException::getTransportableHTTPError ():
49
+ throw new ConnectionException ('Apisearch returned an internal error code [500] ' );
47
50
}
48
51
}
49
52
}
You can’t perform that action at this time.
0 commit comments