Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ging-dev committed Jun 29, 2024
1 parent 0ce0755 commit 4ea36d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
7 changes: 2 additions & 5 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,14 @@ protected function post(string $uri, array $data = []): array
$uri,
[],
$this->configureFieldBuilder(
FieldBuilder::with($data)
FieldBuilder::from($data)
)->encrypt()
);

return Json::decode((string) $response->getBody(), true);
}

protected function configureFieldBuilder(FieldBuilder $builder): FieldBuilder
{
return $builder->withRequiredFields();
}
abstract protected function configureFieldBuilder(FieldBuilder $builder): FieldBuilder;

public function getObjectMapper(): ObjectMapper
{
Expand Down
5 changes: 5 additions & 0 deletions src/Api/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public function login(

return new Session($result['sessionId'], $this->client);
}

protected function configureFieldBuilder(FieldBuilder $builder): FieldBuilder
{
return $builder;
}
}
13 changes: 4 additions & 9 deletions src/Api/FieldBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@ private function __construct(array $data)
/**
* @param string[] $data
*/
public static function with(array $data): static
public static function from(array $data): static
{
return new static($data);
}

public function withRequiredFields(): self
{
$this['lang'] = 'en';
$this['requestId'] = Random::generate(12, '0-9A-Z').'|'.time();
$data['lang'] = 'en';
$data['requestId'] = Random::generate(12, '0-9A-Z').'|'.time();

return $this;
return new static($data);
}

public function build(): self
Expand Down

0 comments on commit 4ea36d3

Please sign in to comment.