Skip to content

Commit 88c4d6c

Browse files
authored
Merge pull request #28 from databox/improvements/php-example
Example
2 parents ca94422 + 050409f commit 88c4d6c

File tree

5 files changed

+99
-21
lines changed

5 files changed

+99
-21
lines changed

.github/workflows/generate_sdk_code.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
repository_dispatch:
44
types: [publish_sdk]
55
env:
6-
GENERATOR_VERISON: "7.6.0"
6+
GENERATOR_VERISON: "7.6.0"
77
CONFIG_FILE: "sdk-gen-config.json"
88
jobs:
99
sdk:
@@ -12,7 +12,7 @@ jobs:
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v4
15-
15+
1616
- name: Get Latest Release
1717
id: latest-version
1818
uses: pozetroninc/[email protected]
@@ -45,7 +45,7 @@ jobs:
4545
}
4646
const newVersion = parts.join('.');
4747
return newVersion;
48-
48+
4949
- name: Download OpenAPI Generator
5050
run: |
5151
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
@@ -78,9 +78,8 @@ jobs:
7878
run: |
7979
java --version
8080
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
81-
cp ./src/README.md ./README.md
82-
cp ./src/composer.json ./composer.json
8381
cp -r ./src/docs ./docs
82+
git checkout HEAD README.md composer.json
8483
8584
- name: Create Pull Request
8685
id: cpr

.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

README.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,49 @@ Please follow the [installation procedure](#installation--usage) and then run th
4545

4646
```php
4747
<?php
48-
require_once(__DIR__ . '/vendor/autoload.php');
4948

49+
require_once __DIR__ . '/../../../vendor/autoload.php';
5050

51+
use Databox\Api\DefaultApi;
52+
use Databox\ApiException;
53+
use Databox\Configuration;
54+
use Databox\Model\PushData as DataboxPushData;
55+
use GuzzleHttp\Client;
5156

52-
// Configure HTTP basic authorization: basicAuth
53-
$config = Databox\Configuration::getDefaultConfiguration()
54-
->setUsername('YOUR_USERNAME')
55-
->setPassword('YOUR_PASSWORD');
57+
execute();
5658

59+
function execute()
60+
{
61+
// Configure HTTP basic authorization: basicAuth
62+
$config = Configuration::getDefaultConfiguration()
63+
->setHost('https://push.databox.com')
64+
->setUsername('<CUSTOM_DATA_TOKEN>');
65+
66+
$headers = [
67+
'Content-Type' => 'application/json',
68+
'Accept' => 'application/vnd.databox.v2+json'
69+
];
5770

58-
$apiInstance = new Databox\Api\DefaultApi(
71+
$apiInstance = new DefaultApi(
5972
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
6073
// This is optional, `GuzzleHttp\Client` will be used as default.
61-
new GuzzleHttp\Client(),
62-
$config
63-
);
64-
65-
try {
66-
$apiInstance->dataDelete();
67-
} catch (Exception $e) {
68-
echo 'Exception when calling DefaultApi->dataDelete: ', $e->getMessage(), PHP_EOL;
74+
new Client(['headers' => $headers]),
75+
$config
76+
);
77+
78+
$pushData = (new DataboxPushData())
79+
->setKey('<METRIC_KEY_NAME>') // for e.g. sessions
80+
->setValue(125)
81+
->setDate('2017-01-01T00:00:00Z') // Date in ISO8601 format
82+
->setUnit('<UNIT>') // for e.g. $
83+
->setAttributes(['<DIMENSION_VALUE>']); // for e.g. ['US']
84+
85+
try {
86+
$apiInstance->dataPost([$pushData]);
87+
echo "Successfully pushed data to Databox";
88+
} catch (ApiException $e) {
89+
echo 'Exception when calling DefaultApi->dataPost: ' . $e->getMessage() . PHP_EOL . $e->getResponseBody() . PHP_EOL;
90+
}
6991
}
7092

7193
```

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
"friendsofphp/php-cs-fixer": "^3.5"
3333
},
3434
"autoload": {
35-
"psr-4": { "Databox\\" : "lib/" }
35+
"psr-4": { "Databox\\" : "src/lib" }
3636
},
3737
"autoload-dev": {
38-
"psr-4": { "Databox\\Test\\" : "test/" }
38+
"psr-4": { "Databox\\Test\\" : "src/test" }
3939
}
4040
}

src/examples/pushData/PushData.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
20+
$headers = [
21+
'Content-Type' => 'application/json',
22+
'Accept' => 'application/vnd.databox.v2+json'
23+
];
24+
25+
$apiInstance = new DefaultApi(
26+
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
27+
// This is optional, `GuzzleHttp\Client` will be used as default.
28+
new Client(['headers' => $headers]),
29+
$config
30+
);
31+
32+
$pushData = (new DataboxPushData())
33+
->setKey('<METRIC_KEY_NAME>') // for e.g. sessions
34+
->setValue(125)
35+
->setDate('2017-01-01T00:00:00Z') // Date in ISO8601 format
36+
->setUnit('<UNIT>') // for e.g. $
37+
->setAttributes(['<DIMENSION_VALUE>']); // for e.g. ['US']
38+
39+
try {
40+
$apiInstance->dataPost([$pushData]);
41+
echo "Successfully pushed data to Databox";
42+
} catch (ApiException $e) {
43+
echo 'Exception when calling DefaultApi->dataPost: ' . $e->getMessage() . PHP_EOL . $e->getResponseBody() . PHP_EOL;
44+
}
45+
}

0 commit comments

Comments
 (0)