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

Commit 93fad8f

Browse files
committed
Some unused endpoints have been removed as both indices will be autocreable
- Events create index - Events delete index - Logs create index - Logs delete index Http clients will work, until now, with application/json data
1 parent a5b9452 commit 93fad8f

20 files changed

+258
-361
lines changed

App/HttpAppRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function addToken(Token $token)
4040
'post',
4141
Http::getQueryValues($this),
4242
[
43-
Http::TOKEN_FIELD => json_encode($token->toArray()),
43+
Http::TOKEN_FIELD => $token->toArray(),
4444
]
4545
);
4646

@@ -61,7 +61,7 @@ public function deleteToken(TokenUUID $tokenUUID)
6161
'delete',
6262
Http::getQueryValues($this),
6363
[
64-
Http::TOKEN_FIELD => json_encode($tokenUUID->toArray()),
64+
Http::TOKEN_FIELD => $tokenUUID->toArray(),
6565
]
6666
);
6767

Event/EventRepository.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
namespace Apisearch\Event;
1818

19-
use Apisearch\Exception\ResourceExistsException;
2019
use Apisearch\Exception\ResourceNotAvailableException;
2120
use Apisearch\Query\Query;
2221
use Apisearch\Repository\WithRepositoryReference;
@@ -27,20 +26,6 @@
2726
*/
2827
interface EventRepository extends WithRepositoryReference
2928
{
30-
/**
31-
* Create index.
32-
*
33-
* @throws ResourceExistsException
34-
*/
35-
public function createIndex();
36-
37-
/**
38-
* Delete index.
39-
*
40-
* @throws ResourceNotAvailableException
41-
*/
42-
public function deleteIndex();
43-
4429
/**
4530
* Save event.
4631
*

Event/HttpEventRepository.php

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
namespace Apisearch\Event;
1818

1919
use Apisearch\Exception\EventException;
20-
use Apisearch\Exception\ResourceExistsException;
2120
use Apisearch\Exception\ResourceNotAvailableException;
2221
use Apisearch\Http\Http;
2322
use Apisearch\Http\HttpRepositoryWithCredentials;
@@ -29,44 +28,6 @@
2928
*/
3029
class HttpEventRepository extends HttpRepositoryWithCredentials implements EventRepository
3130
{
32-
/**
33-
* Create index.
34-
*
35-
* @throws EventException
36-
* @throws ResourceExistsException
37-
*/
38-
public function createIndex()
39-
{
40-
$response = $this
41-
->httpClient
42-
->get('/events', 'post', [
43-
'app_id' => $this->getAppId(),
44-
'index' => $this->getIndex(),
45-
'token' => $this->getToken(),
46-
]);
47-
48-
$this->throwTransportableExceptionIfNeeded($response);
49-
}
50-
51-
/**
52-
* Delete index.
53-
*
54-
* @throws EventException
55-
* @throws ResourceNotAvailableException
56-
*/
57-
public function deleteIndex()
58-
{
59-
$response = $this
60-
->httpClient
61-
->get('/events', 'delete', [
62-
'app_id' => $this->getAppId(),
63-
'index' => $this->getIndex(),
64-
'token' => $this->getToken(),
65-
]);
66-
67-
$this->throwTransportableExceptionIfNeeded($response);
68-
}
69-
7031
/**
7132
* Query over events.
7233
*
@@ -90,7 +51,7 @@ public function query(
9051
'get',
9152
Http::getQueryValues($this),
9253
[
93-
Http::QUERY_FIELD => json_encode($query->toArray()),
54+
Http::QUERY_FIELD => $query->toArray(),
9455
Http::FROM_FIELD => $from,
9556
Http::TO_FIELD => $to,
9657
]

Event/InMemoryEventRepository.php

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
namespace Apisearch\Event;
1818

19-
use Apisearch\Exception\ResourceExistsException;
2019
use Apisearch\Exception\ResourceNotAvailableException;
2120
use Apisearch\Query\Query;
2221
use Apisearch\Repository\RepositoryWithCredentials;
@@ -35,34 +34,6 @@ class InMemoryEventRepository extends RepositoryWithCredentials implements Event
3534
*/
3635
private $events = [];
3736

38-
/**
39-
* Create index.
40-
*
41-
* @throws ResourceExistsException
42-
*/
43-
public function createIndex()
44-
{
45-
if (array_key_exists($this->getIndexKey(), $this->events)) {
46-
throw ResourceExistsException::eventsIndexExists();
47-
}
48-
49-
$this->events[$this->getIndexKey()] = [];
50-
}
51-
52-
/**
53-
* Delete index.
54-
*
55-
* @throws ResourceNotAvailableException
56-
*/
57-
public function deleteIndex()
58-
{
59-
if (!array_key_exists($this->getIndexKey(), $this->events)) {
60-
throw ResourceNotAvailableException::eventsIndexNotAvailable('Index not found in InMemoryEventRepository');
61-
}
62-
63-
unset($this->events[$this->getIndexKey()]);
64-
}
65-
6637
/**
6738
* Query over events.
6839
*

Event/MockEventRepository.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
namespace Apisearch\Event;
1818

1919
use Apisearch\Exception\MockException;
20-
use Apisearch\Exception\ResourceExistsException;
2120
use Apisearch\Exception\ResourceNotAvailableException;
2221
use Apisearch\Http\HttpRepositoryWithCredentials;
2322
use Apisearch\Query\Query;
@@ -28,26 +27,6 @@
2827
*/
2928
class MockEventRepository extends HttpRepositoryWithCredentials implements EventRepository
3029
{
31-
/**
32-
* Create index.
33-
*
34-
* @throws ResourceExistsException
35-
*/
36-
public function createIndex()
37-
{
38-
$this->throwMockException();
39-
}
40-
41-
/**
42-
* Delete index.
43-
*
44-
* @throws ResourceNotAvailableException
45-
*/
46-
public function deleteIndex()
47-
{
48-
$this->throwMockException();
49-
}
50-
5130
/**
5231
* Save event.
5332
*

Exception/ForbiddenException.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 ForbiddenException.
21+
*/
22+
class ForbiddenException extends TransportableException
23+
{
24+
/**
25+
* Get http error code.
26+
*
27+
* @return int
28+
*/
29+
public static function getTransportableHTTPError(): int
30+
{
31+
return 403;
32+
}
33+
34+
/**
35+
* Create app Id should be defined.
36+
*
37+
* @return ForbiddenException
38+
*/
39+
public static function createAppIdIsRequiredException(): self
40+
{
41+
return new self('AppId query parameter MUST be defined with a valid value');
42+
}
43+
44+
/**
45+
* Create app Id should be defined.
46+
*
47+
* @return ForbiddenException
48+
*/
49+
public static function createIndexIsRequiredException(): self
50+
{
51+
return new self('Index query parameter MUST be defined with a valid value');
52+
}
53+
54+
/**
55+
* Create app Id should be defined.
56+
*
57+
* @return ForbiddenException
58+
*/
59+
public static function createTokenIsRequiredException(): self
60+
{
61+
return new self('Index query parameter MUST be defined with a valid value');
62+
}
63+
}

Exception/InvalidFormatException.php

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ public static function getTransportableHTTPError(): int
4040
*/
4141
public static function itemsRepresentationNotValid($itemsBeforeHydration): self
4242
{
43-
return new static(sprintf('Items representation not valid. Expecting Item array serialized but found "%s" before hydration', substr(
44-
(string) $itemsBeforeHydration,
45-
0,
46-
100
47-
)));
43+
return new static(sprintf('Items representation not valid. Expecting Item array serialized but found malformed data'));
4844
}
4945

5046
/**
@@ -56,11 +52,7 @@ public static function itemsRepresentationNotValid($itemsBeforeHydration): self
5652
*/
5753
public static function itemsUUIDRepresentationNotValid($itemsUUIDBeforeHydration): self
5854
{
59-
return new static(sprintf('Items UUID representation not valid. Expecting UUID array serialized but found "%s" before hydration', substr(
60-
(string) $itemsUUIDBeforeHydration,
61-
0,
62-
100
63-
)));
55+
return new static(sprintf('Items UUID representation not valid. Expecting UUID array serialized but found malformed data'));
6456
}
6557

6658
/**
@@ -72,11 +64,7 @@ public static function itemsUUIDRepresentationNotValid($itemsUUIDBeforeHydration
7264
*/
7365
public static function queryFormatNotValid($queryBeforeHydration): self
7466
{
75-
return new static(sprintf('Query Format not valid. Expecting a Query serialized but found "%s" before hydration', substr(
76-
(string) $queryBeforeHydration,
77-
0,
78-
100
79-
)));
67+
return new static(sprintf('Query Format not valid. Expecting a Query serialized but found malformed data'));
8068
}
8169

8270
/**
@@ -88,11 +76,7 @@ public static function queryFormatNotValid($queryBeforeHydration): self
8876
*/
8977
public static function configFormatNotValid($configBeforeHydration): self
9078
{
91-
return new static(sprintf('Config Format not valid. Expecting a Config serialized but found "%s" before hydration', substr(
92-
(string) $configBeforeHydration,
93-
0,
94-
100
95-
)));
79+
return new static(sprintf('Config Format not valid. Expecting a Config serialized but found malformed data'));
9680
}
9781

9882
/**
@@ -104,11 +88,7 @@ public static function configFormatNotValid($configBeforeHydration): self
10488
*/
10589
public static function tokenFormatNotValid($tokenBeforeHydration): self
10690
{
107-
return new static(sprintf('Token Format not valid. Expecting a Token serialized but found "%s" before hydration', substr(
108-
(string) $tokenBeforeHydration,
109-
0,
110-
100
111-
)));
91+
return new static(sprintf('Token Format not valid. Expecting a Token serialized but found malformed data'));
11292
}
11393

11494
/**
@@ -120,11 +100,7 @@ public static function tokenFormatNotValid($tokenBeforeHydration): self
120100
*/
121101
public static function campaignFormatNotValid($campaignBeforeHydration): self
122102
{
123-
return new static(sprintf('Campaign Format not valid. Expecting a Campaign serialized but found "%s" before hydration', substr(
124-
(string) $campaignBeforeHydration,
125-
0,
126-
100
127-
)));
103+
return new static(sprintf('Campaign Format not valid. Expecting a Campaign serialized but found malformed data'));
128104
}
129105

130106
/**
@@ -136,11 +112,7 @@ public static function campaignFormatNotValid($campaignBeforeHydration): self
136112
*/
137113
public static function changesFormatNotValid($changesBeforeHydration): self
138114
{
139-
return new static(sprintf('Changes Format not valid. Expecting a Changes serialized but found "%s" before hydration', substr(
140-
(string) $changesBeforeHydration,
141-
0,
142-
100
143-
)));
115+
return new static(sprintf('Changes Format not valid. Expecting a Changes serialized but found malformed data'));
144116
}
145117

146118
/**
@@ -152,11 +124,7 @@ public static function changesFormatNotValid($changesBeforeHydration): self
152124
*/
153125
public static function boostClauseFormatNotValid($boostClauseBeforeHydration): self
154126
{
155-
return new static(sprintf('Boost clause Format not valid. Expecting a Boost clause serialized but found "%s" before hydration', substr(
156-
(string) $boostClauseBeforeHydration,
157-
0,
158-
100
159-
)));
127+
return new static(sprintf('Boost clause Format not valid. Expecting a Boost clause serialized but found malformed data'));
160128
}
161129

162130
/**
@@ -168,10 +136,6 @@ public static function boostClauseFormatNotValid($boostClauseBeforeHydration): s
168136
*/
169137
public static function tokenUUIDFormatNotValid($tokenUUIDBeforeHydration): self
170138
{
171-
return new static(sprintf('Token UUID Format not valid. Expecting a TokenUUID serialized but found "%s" before hydration', substr(
172-
(string) $tokenUUIDBeforeHydration,
173-
0,
174-
100
175-
)));
139+
return new static(sprintf('Token UUID Format not valid. Expecting a TokenUUID serialized but found malformed data'));
176140
}
177141
}

Exception/MockException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ class MockException extends Exception
3030
*/
3131
public static function isAMock(): self
3232
{
33-
return new self('You\'re using a mock');
33+
return new self('You are using a mock');
3434
}
3535
}

0 commit comments

Comments
 (0)