Skip to content

Commit

Permalink
feat: remove visus/cuid2
Browse files Browse the repository at this point in the history
  • Loading branch information
faustoq committed Jul 7, 2024
1 parent 0c41271 commit b21b574
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
},
"require": {
"php": ">=8.1",
"guzzlehttp/guzzle": "^7.8",
"visus/cuid2": "^3.0 || ^4.1"
"guzzlehttp/guzzle": "^7.8"
},
"scripts": {
"test": "vendor/bin/pest"
Expand Down
10 changes: 3 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
use GuzzleHttp\Client as HttpClient;
use OramaCloud\Client\Query;
use OramaCloud\Telemetry\Collector;
use OramaCloud\Traits\GeneratesUniqueId;
use OramaCloud\Traits\ValidatesParams;
use Visus\Cuid2\Cuid2;

class Client
{
use ValidatesParams;
use GeneratesUniqueId;

private $answersApiBaseURL;
private $apiKey;
Expand All @@ -28,7 +29,7 @@ public function __construct(array $params, HttpClient $http = null)
'answersApiBaseURL' => ['optional', 'string']
]);

$this->id = (new Cuid2())->toString();
$this->id = $this->generateUniqueId();
$this->http = !is_null($http) ? $http : new HttpClient();
$this->apiKey = $params['api_key'];
$this->endpoint = $params['endpoint'];
Expand Down Expand Up @@ -74,11 +75,6 @@ public function search(Query $query)
return $results;
}

public function getCollector(): Collector|null
{
return $this->collector;
}

private function init()
{
$response = $this->fetch('init', 'POST');
Expand Down
3 changes: 1 addition & 2 deletions src/Telemetry/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace OramaCloud\Telemetry;

use GuzzleHttp\Client;
use GuzzleHttp\Promise\PromiseInterface;

class Collector
{
Expand Down Expand Up @@ -78,7 +77,7 @@ private function start()
$this->flush();
}

private function sendBeacon($body): PromiseInterface|null
private function sendBeacon($body)
{
if ($this->params == null || !isset($this->params['endpoint'])) {
return null;
Expand Down
11 changes: 11 additions & 0 deletions src/Traits/GeneratesUniqueId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace OramaCloud\Traits;

trait GeneratesUniqueId
{
public function generateUniqueId($prefix = '')
{
return substr(str_replace('.', '', uniqid($prefix, true) . str_shuffle('abcdefghjkmnpqrstvwxyz0123456789')), 0, 24);
}
}

0 comments on commit b21b574

Please sign in to comment.