-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from databox/improvements/php-example
Example
- Loading branch information
Showing
5 changed files
with
99 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
|
@@ -12,7 +12,7 @@ jobs: | |
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get Latest Release | ||
id: latest-version | ||
uses: pozetroninc/[email protected] | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |