Skip to content

Commit

Permalink
Merge branch '1-0-0' into 'main'
Browse files Browse the repository at this point in the history
1-0-0

See merge request fluxlabs/flux-eco/open-api-client!3
  • Loading branch information
mstuder committed Apr 15, 2022
2 parents 26185ac + 0b5f7fe commit 63c9590
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 69 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

This component is supposed to assist in querying openapis.

## Functional Usage

```
fluxDotEnv\loadDotEnv(__DIR__);
$result = fluxOpenApiClient\query('/api/ilias/accounts', [], 'EXAMPLE_');
print_r($result); exit;
```

outputs:
```
Array
(
[firstname] => Emmett
[lastname] => Brown
[lastChanged] => 2021-01-15T05:30:10+01:00
)
```

## Contributing :purple_heart:

Please ...
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@
"swoole/ide-helper": ">=4.6"
},
"autoload": {
"files": [
"fn/query.php"
],
"psr-4": {
"FluxEco\\OpenApiClient\\": [
"src/"
],
"fluxOpenApiClient\\": [
"fn/"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 2 additions & 11 deletions examples/query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,7 @@

require_once __DIR__ . '/../vendor/autoload.php';

fluxy\loadDotEnv(__DIR__);
fluxDotEnv\loadDotEnv(__DIR__);

$client = FluxEco\OpenApiClient\OpenApiClientApi::new(
FluxEco\OpenApiClient\OpenApiClientConfig::new(
getenv('EXAMPLE_OPEN_API_CLIENT_ID'),
getenv('EXAMPLE_OPEN_API_SECRET'),
getenv('EXAMPLE_OPEN_API_SCOPE'),
getenv('EXAMPLE_OPEN_API_API_URL'),
getenv('EXAMPLE_OPEN_API_AUTHENTICATION_URL'),
)
);
$result = $client->query('/api/ilias/accounts');
$result = fluxOpenApiClient\query('/api/ilias/accounts', [], 'EXAMPLE_');
print_r($result); exit;
10 changes: 10 additions & 0 deletions fn/query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace fluxOpenApiClient;

use FluxEco\OpenApiClient;

function query(string $endpoint, array $filter = [], string $envPrefix = '') : array
{
return OpenApiClient\Api::newFromEnv($envPrefix)->query($endpoint, $filter);
}
25 changes: 0 additions & 25 deletions src/Adapters/Configs/OpenApiOutbounds.php

This file was deleted.

25 changes: 25 additions & 0 deletions src/Adapters/Outbounds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace FluxEco\OpenApiClient\Adapters;
use FluxEco\OpenApiClient\Core\Ports;

class Outbounds implements Ports\Outbounds
{
private Ports\Config $config;

private function __construct(Ports\Config $config)
{
$this->config = $config;
}

public static function new(Ports\Config $config): self
{
return new self($config);
}

final public function getConfig(): Ports\Config
{
return $this->config;
}

}
15 changes: 12 additions & 3 deletions src/OpenApiClientApi.php → src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace FluxEco\OpenApiClient;

class OpenApiClientApi
use FluxEco\OpenApiClient\Adapters\Outbounds;

class Api
{
private Core\Ports\OpenApiService $openApiService;

Expand All @@ -12,9 +14,16 @@ private function __construct(
$this->openApiService = $openApiService;
}

public static function new(OpenApiClientConfig $openApiConfig) : self
public static function new(Config $config) : self
{
$outbounds = Outbounds::new($config);
$openApiService = Core\Ports\OpenApiService::new($outbounds);
return new self($openApiService);
}

public static function newFromEnv(string $envPrefix) : self
{
$outbounds = Adapters\Configs\OpenApiOutbounds::new($openApiConfig);
$outbounds = Outbounds::new(Config::newFromEnv($envPrefix));
$openApiService = Core\Ports\OpenApiService::new($outbounds);
return new self($openApiService);
}
Expand Down
31 changes: 20 additions & 11 deletions src/OpenApiClientConfig.php → src/Config.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php


namespace FluxEco\OpenApiClient;

use FluxEco\OpenApiClient\Core\{Ports};

class OpenApiClientConfig implements Ports\Configs\OpenApiConfig
class Config implements Ports\Config
{
private string $clientId;
private string $secret;
Expand All @@ -19,8 +18,7 @@ private function __construct(
string $scope,
string $apiUrl,
string $authenticationUrl
)
{
) {
$this->clientId = $clientId;
$this->secret = $secret;
$this->scope = $scope;
Expand All @@ -34,8 +32,7 @@ public static function new(
string $scope,
string $apiUrl,
string $authenticationUrl
): self
{
) : self {
return new self(
$clientId,
$secret,
Expand All @@ -45,27 +42,39 @@ public static function new(
);
}

final public function getClientId(): string
public static function newFromEnv(string $envPrefix) : self
{
$apiEnv = Env::new($envPrefix);
return new self(
$apiEnv->getOpenApiClientId(),
$apiEnv->getOpenApiSecret(),
$apiEnv->getOpenApiScope(),
$apiEnv->getOpenApiUrl(),
$apiEnv->getOpenApiAuthenticationUrl()
);
}

final public function getClientId() : string
{
return $this->clientId;
}

final public function getSecret(): string
final public function getSecret() : string
{
return $this->secret;
}

final public function getScope(): string
final public function getScope() : string
{
return $this->scope;
}

final public function getApiUrl(): string
final public function getApiUrl() : string
{
return $this->apiUrl;
}

final public function getAuthenticationUrl(): string
final public function getAuthenticationUrl() : string
{
return $this->authenticationUrl;
}
Expand Down
2 changes: 0 additions & 2 deletions src/Core/Application/Handlers/AuthorizationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public function handle(AuthorizationCommand $command): Domain\Models\Authorizati

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status !== 200) {
print_r($content);
print_r($status);
throw new Exception($content, $status);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace FluxEco\OpenApiClient\Core\Ports\Configs;
namespace FluxEco\OpenApiClient\Core\Ports;

interface OpenApiConfig
interface Config
{
public function getClientId(): string;

Expand Down
8 changes: 0 additions & 8 deletions src/Core/Ports/Configs/OpenApiOutbounds.php

This file was deleted.

12 changes: 6 additions & 6 deletions src/Core/Ports/OpenApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@

class OpenApiService
{
private Ports\Configs\OpenApiConfig $openApiConfig;
private Ports\Config $config;

private function __construct(
Ports\Configs\OpenApiConfig $openApiConfig
Ports\Config $config
)
{
$this->openApiConfig = $openApiConfig;
$this->config = $config;
}

public static function new(
Ports\Configs\OpenApiOutbounds $openApiOutbounds
Ports\Outbounds $openApiOutbounds
): self
{
return new self(
$openApiOutbounds->getOpenApiConfig()
$openApiOutbounds->getConfig()
);
}

public function query(string $endpoint, array $filter): array
{
$openApiConfig = $this->openApiConfig;
$openApiConfig = $this->config;
$authorizationCommand = Application\Handlers\AuthorizationCommand::new(
$openApiConfig->getClientId(),
$openApiConfig->getSecret(),
Expand Down
8 changes: 8 additions & 0 deletions src/Core/Ports/Outbounds.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace FluxEco\OpenApiClient\Core\Ports;

interface Outbounds
{
public function getConfig(): Config;
}
45 changes: 45 additions & 0 deletions src/Env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php


namespace FluxEco\OpenApiClient;

use FluxEco\OpenApiClient\Core\{Ports};

class Env
{
public const OPEN_API_CLIENT_ID='OPEN_API_CLIENT_ID';
public const OPEN_API_SECRET='OPEN_API_SECRET';
public const OPEN_API_SCOPE='OPEN_API_SCOPE';
public const OPEN_API_API_URL='OPEN_API_API_URL';
public const OPEN_API_AUTHENTICATION_URL='OPEN_API_AUTHENTICATION_URL';

private string $envPrefix;

private function __construct(string $envPrefix) {
$this->envPrefix = $envPrefix;
}

public static function new(string $envPrefix = '') {
return new self($envPrefix);
}

public function getOpenApiClientId(): string {
return getenv($this->envPrefix.self::OPEN_API_CLIENT_ID);
}

public function getOpenApiSecret(): string {
return getenv($this->envPrefix.self::OPEN_API_SECRET);
}

public function getOpenApiScope(): string {
return getenv($this->envPrefix.self::OPEN_API_SCOPE);
}

public function getOpenApiUrl(): string {
return getenv($this->envPrefix.self::OPEN_API_API_URL);
}

public function getOpenApiAuthenticationUrl(): string {
return getenv($this->envPrefix.self::OPEN_API_AUTHENTICATION_URL);
}
}

0 comments on commit 63c9590

Please sign in to comment.