Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 9061157

Browse files
committed
Fixed some endpoints names
* Using now HttpClient Exception cacher as static method
1 parent 93fad8f commit 9061157

File tree

8 files changed

+74
-58
lines changed

8 files changed

+74
-58
lines changed

App/HttpAppRepository.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function addToken(Token $token)
4444
]
4545
);
4646

47-
$this->throwTransportableExceptionIfNeeded($response);
47+
self::throwTransportableExceptionIfNeeded($response);
4848
}
4949

5050
/**
@@ -65,7 +65,7 @@ public function deleteToken(TokenUUID $tokenUUID)
6565
]
6666
);
6767

68-
$this->throwTransportableExceptionIfNeeded($response);
68+
self::throwTransportableExceptionIfNeeded($response);
6969
}
7070

7171
/**
@@ -83,7 +83,7 @@ public function getTokens(): array
8383
Http::getQueryValues($this)
8484
);
8585

86-
$this->throwTransportableExceptionIfNeeded($response);
86+
self::throwTransportableExceptionIfNeeded($response);
8787

8888
return array_map(function (array $token) {
8989
return Token::createFromArray($token);
@@ -103,6 +103,6 @@ public function deleteTokens()
103103
Http::getQueryValues($this)
104104
);
105105

106-
$this->throwTransportableExceptionIfNeeded($response);
106+
self::throwTransportableExceptionIfNeeded($response);
107107
}
108108
}

Event/HttpEventRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function query(
5757
]
5858
);
5959

60-
$this->throwTransportableExceptionIfNeeded($response);
60+
self::throwTransportableExceptionIfNeeded($response);
6161

6262
return Events::createFromArray($response['body']);
6363
}

Http/Endpoints.php

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function all(): array
3030
{
3131
return [
3232
/*
33-
* Admin endpoints
33+
* Application endpoints
3434
*/
3535
'v1-index-create' => [
3636
'name' => 'Index create',
@@ -50,16 +50,52 @@ public static function all(): array
5050
'path' => '/v1/index/reset',
5151
'verb' => 'post',
5252
],
53-
'v1-config' => [
54-
'name' => 'Config',
53+
'v1-index-check' => [
54+
'name' => 'Index check',
55+
'description' => 'Check your index',
56+
'path' => '/v1/index',
57+
'verb' => 'head',
58+
],
59+
'v1-index-config' => [
60+
'name' => 'Index Config',
5561
'description' => 'Configure your index',
5662
'path' => '/v1/index',
5763
'verb' => 'put',
5864
],
65+
'v1-token-add' => [
66+
'name' => 'Add token',
67+
'description' => 'Add token',
68+
'path' => '/v1/token',
69+
'verb' => 'post',
70+
],
71+
'v1-token-delete' => [
72+
'name' => 'Delete token',
73+
'description' => 'Delete token',
74+
'path' => '/v1/token',
75+
'verb' => 'delete',
76+
],
77+
'v1-tokens-get' => [
78+
'name' => 'Get all tokens',
79+
'description' => 'Get all tokens',
80+
'path' => '/v1/tokens',
81+
'verb' => 'get',
82+
],
83+
'v1-tokens-delete' => [
84+
'name' => 'Delete all tokens',
85+
'description' => 'Delete all tokens',
86+
'path' => '/v1/tokens',
87+
'verb' => 'delete',
88+
],
5989

6090
/*
61-
* Write endpoints
91+
* Query endpoints
6292
*/
93+
'v1-query' => [
94+
'name' => 'Query',
95+
'description' => 'Make queries',
96+
'path' => '/v1',
97+
'verb' => 'get',
98+
],
6399
'v1-items-index' => [
64100
'name' => 'Items index',
65101
'description' => 'Index your items',
@@ -72,16 +108,16 @@ public static function all(): array
72108
'path' => '/v1/items',
73109
'verb' => 'delete',
74110
],
111+
'v1-items-update' => [
112+
'name' => 'Items update',
113+
'description' => 'Update your items',
114+
'path' => '/v1/items',
115+
'verb' => 'put',
116+
],
75117

76118
/*
77-
* Read endpoints
119+
* Events endpoints
78120
*/
79-
'v1-query' => [
80-
'name' => 'Query',
81-
'description' => 'Make queries',
82-
'path' => '/v1',
83-
'verb' => 'get',
84-
],
85121
'v1-events' => [
86122
'name' => 'Events',
87123
'description' => 'Query your events',
@@ -94,6 +130,10 @@ public static function all(): array
94130
'path' => '/v1/events/stream',
95131
'verb' => 'get',
96132
],
133+
134+
/*
135+
* Logs endpoints
136+
*/
97137
'v1-logs' => [
98138
'name' => 'Logs',
99139
'description' => 'Query your logs',
@@ -108,35 +148,7 @@ public static function all(): array
108148
],
109149

110150
/*
111-
* Tokens
112-
*/
113-
'v1-token-add' => [
114-
'name' => 'Add token',
115-
'description' => 'Add token',
116-
'path' => '/v1/token',
117-
'verb' => 'post',
118-
],
119-
'v1-token-delete' => [
120-
'name' => 'Delete token',
121-
'description' => 'Delete token',
122-
'path' => '/v1/token',
123-
'verb' => 'delete',
124-
],
125-
'v1-tokens-get' => [
126-
'name' => 'Get all tokens',
127-
'description' => 'Get all tokens',
128-
'path' => '/v1/tokens',
129-
'verb' => 'get',
130-
],
131-
'v1-tokens-delete-all' => [
132-
'name' => 'Delete all tokens',
133-
'description' => 'Delete all tokens',
134-
'path' => '/v1/tokens',
135-
'verb' => 'delete',
136-
],
137-
138-
/*
139-
* Interaction endpoints
151+
* User endpoints
140152
*/
141153
'v1-interaction' => [
142154
'name' => 'Add interaction',

Http/HttpResponsesToException.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ trait HttpResponsesToException
3434
*
3535
* @throw TransportableException
3636
*/
37-
protected function throwTransportableExceptionIfNeeded(array $response)
37+
protected static function throwTransportableExceptionIfNeeded(array $response)
3838
{
39+
if (!isset($response['code'])) {
40+
return;
41+
}
42+
3943
switch ($response['code']) {
4044
case ResourceNotAvailableException::getTransportableHTTPError():
4145
throw new ResourceNotAvailableException($response['body']['message']);

Log/HttpLogRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function query(
5757
]
5858
);
5959

60-
$this->throwTransportableExceptionIfNeeded($response);
60+
self::throwTransportableExceptionIfNeeded($response);
6161

6262
return Logs::createFromArray($response['body']);
6363
}

Repository/HttpRepository.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function flushItems(
9898
return;
9999
}
100100

101-
$this->throwTransportableExceptionIfNeeded($response);
101+
self::throwTransportableExceptionIfNeeded($response);
102102
}
103103

104104
/**
@@ -123,7 +123,7 @@ public function updateItems(
123123
]
124124
);
125125

126-
$this->throwTransportableExceptionIfNeeded($response);
126+
self::throwTransportableExceptionIfNeeded($response);
127127
}
128128

129129
/**
@@ -148,7 +148,7 @@ public function query(Query $query): Result
148148
]
149149
);
150150

151-
$this->throwTransportableExceptionIfNeeded($response);
151+
self::throwTransportableExceptionIfNeeded($response);
152152

153153
return Result::createFromArray($response['body']);
154154
}
@@ -173,7 +173,7 @@ public function createIndex(ImmutableConfig $config)
173173
]
174174
);
175175

176-
$this->throwTransportableExceptionIfNeeded($response);
176+
self::throwTransportableExceptionIfNeeded($response);
177177
}
178178

179179
/**
@@ -191,7 +191,7 @@ public function deleteIndex()
191191
Http::getQueryValues($this)
192192
);
193193

194-
$this->throwTransportableExceptionIfNeeded($response);
194+
self::throwTransportableExceptionIfNeeded($response);
195195
}
196196

197197
/**
@@ -209,7 +209,7 @@ public function resetIndex()
209209
Http::getQueryValues($this)
210210
);
211211

212-
$this->throwTransportableExceptionIfNeeded($response);
212+
self::throwTransportableExceptionIfNeeded($response);
213213
}
214214

215215
/**
@@ -259,6 +259,6 @@ public function configureIndex(Config $config)
259259
return;
260260
}
261261

262-
$this->throwTransportableExceptionIfNeeded($response);
262+
self::throwTransportableExceptionIfNeeded($response);
263263
}
264264
}

Tests/Http/EndpointsTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class EndpointsTest extends PHPUnit_Framework_TestCase
3131
'v1-index-create',
3232
'v1-index-delete',
3333
'v1-index-reset',
34-
'v1-config',
34+
'v1-index-config',
3535

3636
'v1-items-index',
3737
'v1-items-delete',
@@ -45,7 +45,7 @@ class EndpointsTest extends PHPUnit_Framework_TestCase
4545
'v1-token-add',
4646
'v1-token-delete',
4747
'v1-tokens-get',
48-
'v1-tokens-delete-all',
48+
'v1-tokens-delete',
4949

5050
'v1-interaction',
5151
'v1-interactions-delete',

User/HttpUserRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function addInteraction(Interaction $interaction)
4141
'interaction' => $interaction->toArray(),
4242
]);
4343

44-
$this->throwTransportableExceptionIfNeeded($response);
44+
self::throwTransportableExceptionIfNeeded($response);
4545
}
4646

4747
/**
@@ -57,6 +57,6 @@ public function deleteAllInteractions()
5757
Http::getQueryValues($this)
5858
);
5959

60-
$this->throwTransportableExceptionIfNeeded($response);
60+
self::throwTransportableExceptionIfNeeded($response);
6161
}
6262
}

0 commit comments

Comments
 (0)