Skip to content

Commit fd4d033

Browse files
committed
Add example for PHP package
1 parent 23288b8 commit fd4d033

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
./vendor/
2+
3+
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
4+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
5+
# composer.lock
6+
7+
# php-cs-fixer cache
8+
.php_cs.cache
9+
.php-cs-fixer.cache
10+
11+
# PHPUnit cache
12+
.phpunit.result.cache

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"friendsofphp/php-cs-fixer": "^3.5"
3333
},
3434
"autoload": {
35-
"psr-4": { "Databox\\" : "src/" }
35+
"psr-4": { "Databox\\" : "src/lib" }
3636
},
3737
"autoload-dev": {
3838
"psr-4": { "Databox\\Test\\" : "src/test" }

src/examples/pushData/PushData.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
require_once __DIR__ . '/../../../vendor/autoload.php';
4+
5+
use Databox\Api\DefaultApi;
6+
use Databox\ApiException;
7+
use Databox\Configuration;
8+
use Databox\Model\PushData as DataboxPushData;
9+
use GuzzleHttp\Client;
10+
11+
execute();
12+
13+
function execute()
14+
{
15+
// Configure HTTP basic authorization: basicAuth
16+
$config = Configuration::getDefaultConfiguration()
17+
->setHost('https://push.databox.com')
18+
->setUsername('<CUSTOM_DATA_TOKEN>')
19+
->setUserAgent('databox-designer-pushdata/2.0');
20+
21+
$headers = [
22+
'Content-Type' => 'application/json',
23+
'Accept' => 'application/vnd.databox.v2+json'
24+
];
25+
26+
$apiInstance = new DefaultApi(
27+
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
28+
// This is optional, `GuzzleHttp\Client` will be used as default.
29+
new Client(['headers' => $headers]),
30+
$config
31+
);
32+
33+
$pushData = (new DataboxPushData())
34+
->setKey('<METRIC_KEY_NAME>') // for e.g. sessions
35+
->setValue(125)
36+
->setDate('2017-01-01T00:00:00Z') // Date in ISO8601 format
37+
->setUnit('<UNIT>') // for e.g. $
38+
->setAttributes(['<DIMENSION_VALUE>']); // for e.g. ['US']
39+
40+
try {
41+
$apiInstance->dataPost([$pushData]);
42+
echo "Successfully pushed data to Databox";
43+
} catch (ApiException $e) {
44+
echo 'Exception when calling DefaultApi->dataPost: ' . $e->getMessage() . PHP_EOL . $e->getResponseBody() . PHP_EOL;
45+
}
46+
}

0 commit comments

Comments
 (0)