-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from phiHero/feat/conversations
Add support for conversations
- Loading branch information
Showing
13 changed files
with
565 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Typesense; | ||
|
||
use Http\Client\Exception as HttpClientException; | ||
use Typesense\Exceptions\TypesenseClientError; | ||
|
||
/** | ||
* Class Conversation | ||
* | ||
* @package \Typesense | ||
*/ | ||
class Conversation | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private string $id; | ||
|
||
/** | ||
* @var ApiCall | ||
*/ | ||
private ApiCall $apiCall; | ||
|
||
/** | ||
* Conversation constructor. | ||
* | ||
* @param string $id | ||
* @param ApiCall $apiCall | ||
*/ | ||
public function __construct(string $id, ApiCall $apiCall) | ||
{ | ||
$this->id = $id; | ||
$this->apiCall = $apiCall; | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* | ||
* @return array | ||
* @throws TypesenseClientError|HttpClientException | ||
*/ | ||
public function update(array $params): array | ||
{ | ||
return $this->apiCall->put($this->endPointPath(), $params); | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws TypesenseClientError|HttpClientException | ||
*/ | ||
public function retrieve(): array | ||
{ | ||
return $this->apiCall->get($this->endPointPath(), []); | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws TypesenseClientError|HttpClientException | ||
*/ | ||
public function delete(): array | ||
{ | ||
return $this->apiCall->delete($this->endPointPath()); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function endPointPath(): string | ||
{ | ||
return sprintf('%s/%s', Conversations::RESOURCE_PATH, $this->id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Typesense; | ||
|
||
use Http\Client\Exception as HttpClientException; | ||
use Typesense\Exceptions\TypesenseClientError; | ||
|
||
/** | ||
* Class ConversationModel | ||
* | ||
* @package \Typesense | ||
*/ | ||
class ConversationModel | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private string $id; | ||
|
||
/** | ||
* @var ApiCall | ||
*/ | ||
private ApiCall $apiCall; | ||
|
||
/** | ||
* ConversationModel constructor. | ||
* | ||
* @param string $id | ||
* @param ApiCall $apiCall | ||
*/ | ||
public function __construct(string $id, ApiCall $apiCall) | ||
{ | ||
$this->id = $id; | ||
$this->apiCall = $apiCall; | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* | ||
* @return array | ||
* @throws TypesenseClientError|HttpClientException | ||
*/ | ||
public function update(array $params): array | ||
{ | ||
return $this->apiCall->put($this->endPointPath(), $params); | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws TypesenseClientError|HttpClientException | ||
*/ | ||
public function retrieve(): array | ||
{ | ||
return $this->apiCall->get($this->endPointPath(), []); | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws TypesenseClientError|HttpClientException | ||
*/ | ||
public function delete(): array | ||
{ | ||
return $this->apiCall->delete($this->endPointPath()); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function endPointPath(): string | ||
{ | ||
return sprintf('%s/%s', ConversationModels::RESOURCE_PATH, $this->id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace Typesense; | ||
|
||
use Http\Client\Exception as HttpClientException; | ||
use Typesense\Exceptions\TypesenseClientError; | ||
|
||
/** | ||
* Class ConversationModels | ||
* | ||
* @package \Typesense | ||
*/ | ||
class ConversationModels implements \ArrayAccess | ||
{ | ||
public const RESOURCE_PATH = '/conversations/models'; | ||
|
||
/** | ||
* @var ApiCall | ||
*/ | ||
private ApiCall $apiCall; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private array $models = []; | ||
|
||
/** | ||
* ConversationModels constructor. | ||
* | ||
* @param ApiCall $apiCall | ||
*/ | ||
public function __construct(ApiCall $apiCall) | ||
{ | ||
$this->apiCall = $apiCall; | ||
} | ||
|
||
/** | ||
* @param $id | ||
* | ||
* @return mixed | ||
*/ | ||
public function __get($id) | ||
{ | ||
if (isset($this->{$id})) { | ||
return $this->{$id}; | ||
} | ||
if (!isset($this->models[$id])) { | ||
$this->models[$id] = new ConversationModel($id, $this->apiCall); | ||
} | ||
|
||
return $this->models[$id]; | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* | ||
* @return array | ||
* @throws TypesenseClientError|HttpClientException | ||
*/ | ||
public function create(array $params): array | ||
{ | ||
return $this->apiCall->post(static::RESOURCE_PATH, $params); | ||
} | ||
|
||
/** | ||
* @return array | ||
* @throws TypesenseClientError|HttpClientException | ||
*/ | ||
public function retrieve(): array | ||
{ | ||
return $this->apiCall->get(static::RESOURCE_PATH, []); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function offsetExists($offset): bool | ||
{ | ||
return isset($this->models[$offset]); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function offsetGet($offset): ConversationModel | ||
{ | ||
if (!isset($this->models[$offset])) { | ||
$this->models[$offset] = new ConversationModel($offset, $this->apiCall); | ||
} | ||
|
||
return $this->models[$offset]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function offsetSet($offset, $value): void | ||
{ | ||
$this->models[$offset] = $value; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function offsetUnset($offset): void | ||
{ | ||
unset($this->models[$offset]); | ||
} | ||
} |
Oops, something went wrong.