From 4841ea74cd819642e9706d6730ad3eb633db8753 Mon Sep 17 00:00:00 2001 From: Carsten Karbach <c.karbach@fz-juelich.de> Date: Mon, 22 Jan 2018 14:28:04 +0100 Subject: [PATCH] Include client for accessing central GCS-JARDS Api, add example script --- composer.json | 5 +++ composer.lock | 51 ++++++++++++++++++++++++- configs/gcsjardsapi.conf | 10 +++++ examples/gcsjards_api_files.php | 66 +++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 configs/gcsjardsapi.conf create mode 100644 examples/gcsjards_api_files.php diff --git a/composer.json b/composer.json index a249370..9c4e162 100644 --- a/composer.json +++ b/composer.json @@ -4,11 +4,16 @@ { "type": "vcs", "url": "https://gitlab.version.fz-juelich.de/jards/EventsAPIClient.git" + }, + { + "type": "vcs", + "url": "https://gitlab.version.fz-juelich.de/jards/GCSJARDSAPIClient.git" } ], "require": { "silex/silex": ">=2.0", "jards/eventsapiclient": "=3.0", + "jards/gcsjardsapiclient": "=2.0", "phpmailer/phpmailer": ">=6.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 10498c8..bfd1678 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "ab1d79ed4ca1b45fe369574aed53a416", + "content-hash": "cdf21b69798ca5f38caf3b3006641ccb", "packages": [ { "name": "jards/eventsapiclient", @@ -55,6 +55,55 @@ ], "time": "2018-01-16T07:04:14+00:00" }, + { + "name": "jards/gcsjardsapiclient", + "version": "v2.0", + "source": { + "type": "git", + "url": "https://gitlab.version.fz-juelich.de/jards/GCSJARDSAPIClient.git", + "reference": "8cd17ed33e447f6af8adcda2e6bb3269e2587ee8" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=5.4" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "~1.12", + "phpunit/phpunit": "~4.8", + "satooshi/php-coveralls": "~1.0", + "squizlabs/php_codesniffer": "~2.6" + }, + "type": "library", + "autoload": { + "psr-4": { + "jards\\gcsjardsapiclient\\Swagger\\Client\\": "lib/" + } + }, + "autoload-dev": { + "psr-4": { + "jards\\gcsjardsapiclient\\Swagger\\Client\\": "test/" + } + }, + "license": [ + "proprietary" + ], + "authors": [ + { + "name": "Swagger and contributors", + "homepage": "https://github.com/swagger-api/swagger-codegen" + } + ], + "homepage": "http://swagger.io", + "keywords": [ + "api", + "php", + "sdk", + "swagger" + ], + "time": "2018-01-22T12:20:35+00:00" + }, { "name": "phpmailer/phpmailer", "version": "v6.0.1", diff --git a/configs/gcsjardsapi.conf b/configs/gcsjardsapi.conf new file mode 100644 index 0000000..dbbf6fa --- /dev/null +++ b/configs/gcsjardsapi.conf @@ -0,0 +1,10 @@ +; +; Configuration parameters for accessing the GCS-JARDS API as a client +; +; + + +CERTFILE = '/path/to/certificate.crt' +CERTKEY = '/path/to/certificate.key' +CERTPASSPHRASE = '--secret--' +BASEURL = 'https://host/basepath/for/gcsjards/api'; \ No newline at end of file diff --git a/examples/gcsjards_api_files.php b/examples/gcsjards_api_files.php new file mode 100644 index 0000000..a8e7aee --- /dev/null +++ b/examples/gcsjards_api_files.php @@ -0,0 +1,66 @@ +<?php +/* + * Copyright (c) 2018, Forschungszentrum Juelich GmbH, Federal Republic of Germany. + * All rights reserved. + * + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +require_once __DIR__ . '/../vendor/autoload.php'; + +$conf = parse_ini_file(__DIR__.'/../configs/gcsjardsapi.conf'); + +$certFile = $conf['CERTFILE']; +$certKey = $conf['CERTKEY']; +$certPassphrase = $conf['CERTPASSPHRASE']; +$baseURL = $conf['BASEURL']; + +date_default_timezone_set ( 'Europe/Amsterdam' ); +$apiClient = new \jards\gcsjardsapiclient\Swagger\Client\ApiClient (); +$apiClient->getConfig ()->setHost ( $baseURL ); + +if (! empty ( $certFile )) { + $apiClient->getConfig ()->setCertificate ( $certFile ); +} +if (! empty ( $certKey )) { + $apiClient->getConfig ()->setCertificateKey ( $certKey ); +} +if (! empty ( $certPassphrase )) { + $apiClient->getConfig ()->setCertificatePassphrase ( $certPassphrase ); +} + +$gcsjardsAPI = new \jards\gcsjardsapiclient\Swagger\Client\Api\FilesApi( $apiClient ); + +$appid = 20394; + +try { + $files = $gcsjardsAPI->filesAppidGet($appid); + + var_dump($files); + + foreach($files as $filetype){ + /** + * @var SplFileObject $fileObject + */ + $fileObject = $gcsjardsAPI->filesAppidFileGet($appid, $filetype); + $tmpFile = $fileObject->getPathname(); + $targetfilename = __DIR__.'/'.$filetype.'_'.$appid.'.pdf'; + copy($tmpFile, $targetfilename); + + echo "Downloaded $filetype to $targetfilename \n"; + } + +} catch ( \jards\gcsjardsapiclient\Swagger\Client\ApiException $e ) { + var_dump($e); + return false; +} + +?> \ No newline at end of file -- GitLab