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 3 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
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
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;
}
}