Skip to content

Commit

Permalink
Merge branch '1.0.0' into 'main'
Browse files Browse the repository at this point in the history
first release

See merge request fluxlabs/flux-eco/open-api-client!2
  • Loading branch information
mstuder committed Apr 4, 2022
2 parents c4a6838 + 616220f commit 26185ac
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 45 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## [1.0.0] - First Release
Features:
* Handle authentication
* Handle queries

## [0.0.2]
* added flux-publish-utils

Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "flux-eco/open-api-client",
"description": "Assists in querying openapis",
"version": "0.0.2",
"version": "1.0.0",
"type": "flux-app",
"keywords": [
"flux-eco",
Expand All @@ -26,10 +26,9 @@
"ext-curl": "*",
"ext-json": "*",
"ext-yaml": "*",
"composer-runtime-api": ">=2.1"
"flux-eco/dot-env": ">=0.0.1"
},
"require-dev": {
"composer/composer": ">=2.0",
"swoole/ide-helper": ">=4.6"
},
"autoload": {
Expand Down
123 changes: 123 additions & 0 deletions composer.lock

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

1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
5 changes: 5 additions & 0 deletions examples/EXAMPLE.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
EXAMPLE_OPEN_API_CLIENT_ID=ilias
EXAMPLE_OPEN_API_SECRET=1234
EXAMPLE_OPEN_API_SCOPE=ilias.read
EXAMPLE_OPEN_API_API_URL=https://example.org/
EXAMPLE_OPEN_API_AUTHENTICATION_URL=https://example.org/connect/token
17 changes: 17 additions & 0 deletions examples/query.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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

fluxy\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');
print_r($result); exit;
12 changes: 0 additions & 12 deletions src/Adapters/Configs/OpenApiEnv.php

This file was deleted.

14 changes: 7 additions & 7 deletions src/Core/Application/Handlers/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
class QueryCommand
{
private string $authorization;
private string $endpoint;
private string $endpointUrl;
private array $filter;

private function __construct(string $authorization, string $endpoint, array $filter)
private function __construct(string $authorization, string $endpointUrl, array $filter)
{
$this->authorization = $authorization;
$this->endpoint = $endpoint;
$this->endpointUrl = $endpointUrl;
$this->filter = $filter;
}

public static function new(string $authorization, string $endpoint, array $filter): self
public static function new(string $authorization, string $endpointUrl, array $filter): self
{
return new self(
$authorization,
$endpoint,
$endpointUrl,
$filter
);
}


public function getEndpoint(): string
public function getEndpointUrl(): string
{
return $this->endpoint;
return $this->endpointUrl;
}


Expand Down
4 changes: 2 additions & 2 deletions src/Core/Application/Handlers/QueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function new(): self {
public function handle(QueryCommand $queryCommand): array {
$curl = null;
try {
$curl = curl_init($queryCommand->getEndpoint());
$curl = curl_init($queryCommand->getEndpointUrl());
$headers = [
'Authorization' => $queryCommand->getAuthorization()
];
Expand All @@ -39,7 +39,7 @@ public function handle(QueryCommand $queryCommand): array {
if ($status !== 200) {
echo "Exception".PHP_EOL;
echo $status.PHP_EOL;
echo "curlInfo";
echo "curlInfo".PHP_EOL;
print_r(curl_getinfo($curl));
echo PHP_EOL."content".PHP_EOL;
print_r($content);
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Ports/Configs/OpenApiConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

public function getSecret(): string;

Expand Down
5 changes: 3 additions & 2 deletions src/Core/Ports/OpenApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function query(string $endpoint, array $filter): array
{
$openApiConfig = $this->openApiConfig;
$authorizationCommand = Application\Handlers\AuthorizationCommand::new(
$openApiConfig->getClient(),
$openApiConfig->getClientId(),
$openApiConfig->getSecret(),
$openApiConfig->getScope(),
$openApiConfig->getApiUrl(),
Expand All @@ -38,7 +38,8 @@ public function query(string $endpoint, array $filter): array

echo "authorization: ".$authorization->getAuthorization();

$queryCommand = Application\Handlers\QueryCommand::new($authorization->getAuthorization(), $endpoint, $filter);
$endpointUrl = $openApiConfig->getApiUrl().$endpoint;
$queryCommand = Application\Handlers\QueryCommand::new($authorization->getAuthorization(), $endpointUrl, $filter);
return Application\Handlers\QueryHandler::new()->handle($queryCommand);
}
}
18 changes: 8 additions & 10 deletions src/Adapters/Api/OpenApiClientApi.php → src/OpenApiClientApi.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
<?php


namespace FluxEco\OpenApiClient\Adapters\Api;
use FluxEco\OpenApiClient\{Core\Ports, Adapters};
namespace FluxEco\OpenApiClient;

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

private function __construct(
Ports\OpenApiService $openApiService
)
{
Core\Ports\OpenApiService $openApiService
) {
$this->openApiService = $openApiService;
}

public static function new(OpenApiClientConfig $openApiConfig): self
public static function new(OpenApiClientConfig $openApiConfig) : self
{
$outbounds = Adapters\Configs\OpenApiOutbounds::new($openApiConfig);
$openApiService = Ports\OpenApiService::new($outbounds);
$openApiService = Core\Ports\OpenApiService::new($outbounds);
return new self($openApiService);
}

public function query(string $endpoint, array $filter = []): array {
public function query(string $endpoint, array $filter = []) : array
{
return $this->openApiService->query($endpoint, $filter);
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
<?php


namespace FluxEco\OpenApiClient\Adapters\Api;
namespace FluxEco\OpenApiClient;

use FluxEco\OpenApiClient\Core\{Ports};

class OpenApiClientConfig implements Ports\Configs\OpenApiConfig
{
private string $client;
private string $clientId;
private string $secret;
private string $scope;
private string $apiUrl;
private string $authenticationUrl;

private function __construct(
string $client,
string $clientId,
string $secret,
string $scope,
string $apiUrl,
string $authenticationUrl
)
{
$this->client = $client;
$this->clientId = $clientId;
$this->secret = $secret;
$this->scope = $scope;
$this->apiUrl = $apiUrl;
$this->authenticationUrl = $authenticationUrl;
}

public static function new(
string $client,
string $clientId,
string $secret,
string $scope,
string $apiUrl,
string $authenticationUrl
): self
{
return new self(
$client,
$clientId,
$secret,
$scope,
$apiUrl,
$authenticationUrl
);
}

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

final public function getSecret(): string
Expand Down

0 comments on commit 26185ac

Please sign in to comment.