Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example #28

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/workflows/generate_sdk_code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
repository_dispatch:
types: [publish_sdk]
env:
GENERATOR_VERISON: "7.6.0"
GENERATOR_VERISON: "7.6.0"
CONFIG_FILE: "sdk-gen-config.json"
jobs:
sdk:
Expand All @@ -12,7 +12,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get Latest Release
id: latest-version
uses: pozetroninc/[email protected]
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
}
const newVersion = parts.join('.');
return newVersion;

- name: Download OpenAPI Generator
run: |
curl https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${{ env.GENERATOR_VERISON }}/openapi-generator-cli-${{ env.GENERATOR_VERISON }}.jar -o ${{ runner.temp }}/openapi-generator-cli.jar
Expand Down Expand Up @@ -78,9 +78,8 @@ jobs:
run: |
java --version
java -jar ${{ runner.temp }}/openapi-generator-cli.jar generate -i ${{ runner.temp }}/openapispec/openapi.yml -g php -o ./src -c ${{ runner.temp }}/${{ env.CONFIG_FILE }} --skip-validate-spec
cp ./src/README.md ./README.md
cp ./src/composer.json ./composer.json
cp -r ./src/docs ./docs
git checkout HEAD README.md composer.json

- name: Create Pull Request
id: cpr
Expand Down
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
./vendor/

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock

# php-cs-fixer cache
.php_cs.cache
.php-cs-fixer.cache

# PHPUnit cache
.phpunit.result.cache
50 changes: 36 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,49 @@ Please follow the [installation procedure](#installation--usage) and then run th

```php
<?php
require_once(__DIR__ . '/vendor/autoload.php');

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

use Databox\Api\DefaultApi;
use Databox\ApiException;
use Databox\Configuration;
use Databox\Model\PushData as DataboxPushData;
use GuzzleHttp\Client;

// Configure HTTP basic authorization: basicAuth
$config = Databox\Configuration::getDefaultConfiguration()
->setUsername('YOUR_USERNAME')
->setPassword('YOUR_PASSWORD');
execute();

function execute()
{
// Configure HTTP basic authorization: basicAuth
$config = Configuration::getDefaultConfiguration()
->setHost('https://push.databox.com')
->setUsername('<CUSTOM_DATA_TOKEN>');

$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/vnd.databox.v2+json'
];

$apiInstance = new Databox\Api\DefaultApi(
$apiInstance = new DefaultApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);

try {
$apiInstance->dataDelete();
} catch (Exception $e) {
echo 'Exception when calling DefaultApi->dataDelete: ', $e->getMessage(), PHP_EOL;
new Client(['headers' => $headers]),
$config
);

$pushData = (new DataboxPushData())
->setKey('<METRIC_KEY_NAME>') // for e.g. sessions
->setValue(125)
->setDate('2017-01-01T00:00:00Z') // Date in ISO8601 format
->setUnit('<UNIT>') // for e.g. $
->setAttributes(['<DIMENSION_VALUE>']); // for e.g. ['US']

try {
$apiInstance->dataPost([$pushData]);
echo "Successfully pushed data to Databox";
} catch (ApiException $e) {
echo 'Exception when calling DefaultApi->dataPost: ' . $e->getMessage() . PHP_EOL . $e->getResponseBody() . PHP_EOL;
}
}

```
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"friendsofphp/php-cs-fixer": "^3.5"
},
"autoload": {
"psr-4": { "Databox\\" : "lib/" }
"psr-4": { "Databox\\" : "src/lib" }
},
"autoload-dev": {
"psr-4": { "Databox\\Test\\" : "test/" }
"psr-4": { "Databox\\Test\\" : "src/test" }
}
}
45 changes: 45 additions & 0 deletions src/examples/pushData/PushData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

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

use Databox\Api\DefaultApi;
use Databox\ApiException;
use Databox\Configuration;
use Databox\Model\PushData as DataboxPushData;
use GuzzleHttp\Client;

execute();

function execute()
{
// Configure HTTP basic authorization: basicAuth
$config = Configuration::getDefaultConfiguration()
->setHost('https://push.databox.com')
->setUsername('<CUSTOM_DATA_TOKEN>');

$headers = [
'Content-Type' => 'application/json',
'Accept' => 'application/vnd.databox.v2+json'
];

$apiInstance = new DefaultApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new Client(['headers' => $headers]),
$config
);

$pushData = (new DataboxPushData())
->setKey('<METRIC_KEY_NAME>') // for e.g. sessions
->setValue(125)
->setDate('2017-01-01T00:00:00Z') // Date in ISO8601 format
->setUnit('<UNIT>') // for e.g. $
->setAttributes(['<DIMENSION_VALUE>']); // for e.g. ['US']

try {
$apiInstance->dataPost([$pushData]);
echo "Successfully pushed data to Databox";
} catch (ApiException $e) {
echo 'Exception when calling DefaultApi->dataPost: ' . $e->getMessage() . PHP_EOL . $e->getResponseBody() . PHP_EOL;
}
}