From 38f42ffbff4d718df421d666a74f51fc8a53f320 Mon Sep 17 00:00:00 2001 From: LeoAdamek Date: Tue, 12 Oct 2021 15:17:51 +0100 Subject: [PATCH] Initial Revision --- .gitignore | 1 + .idea/php.xml | 65 +- .idea/tigerbay-php.iml | 5 +- composer.json | 15 +- composer.lock | 1277 +++++++++++++++++++++---- src/Client.php | 91 +- src/Config.php | 2 + src/Middleware/Authentication.php | 51 + src/Middleware/Logger.php | 59 ++ src/Models/Accommodation.php | 75 ++ src/Models/AuthenticationResponse.php | 57 ++ src/Models/Extra.php | 56 ++ src/Models/ExtraType.php | 75 ++ src/Models/InventorySummary.php | 214 +++++ src/Models/Location.php | 121 +++ src/Models/Price.php | 53 + src/Models/PriceSummary.php | 29 + src/Models/TourCacheSearchRequest.php | 72 ++ src/Models/TourCacheSearchResult.php | 583 +++++++++++ src/Models/TourCacheStats.php | 54 ++ src/Models/TravellerUnit.php | 216 +++++ src/TourCache.php | 37 + tests/ClientTest.php | 37 +- tests/ClientTestCase.php | 18 + 24 files changed, 3080 insertions(+), 183 deletions(-) create mode 100644 src/Middleware/Authentication.php create mode 100644 src/Middleware/Logger.php create mode 100644 src/Models/Accommodation.php create mode 100644 src/Models/AuthenticationResponse.php create mode 100644 src/Models/Extra.php create mode 100644 src/Models/ExtraType.php create mode 100644 src/Models/InventorySummary.php create mode 100644 src/Models/Location.php create mode 100644 src/Models/Price.php create mode 100644 src/Models/PriceSummary.php create mode 100644 src/Models/TourCacheSearchRequest.php create mode 100644 src/Models/TourCacheSearchResult.php create mode 100644 src/Models/TourCacheStats.php create mode 100644 src/Models/TravellerUnit.php create mode 100644 src/TourCache.php create mode 100644 tests/ClientTestCase.php diff --git a/.gitignore b/.gitignore index 48b8bf9..b7aceac 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ vendor/ +.phpunit.result.cache diff --git a/.idea/php.xml b/.idea/php.xml index 4f0611e..98379b9 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,4 +1,67 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/tigerbay-php.iml b/.idea/tigerbay-php.iml index c7f83bc..4d948d5 100644 --- a/.idea/tigerbay-php.iml +++ b/.idea/tigerbay-php.iml @@ -2,8 +2,9 @@ - - + + + diff --git a/composer.json b/composer.json index ea0069e..75688aa 100644 --- a/composer.json +++ b/composer.json @@ -8,6 +8,13 @@ "Mrzen\\Tigerbay\\": "src/" } }, + + "autoload-dev": { + "psr-4": { + "Mrzen\\Tigerbay\\Tests\\": "tests/" + } + }, + "authors": [ { "name": "Leo Adamek", @@ -15,9 +22,13 @@ } ], "require": { - "php": ">=7.0", + "php": ">=7.2.24", "ext-curl": "*", - "guzzlehttp/guzzle": "^7" + "guzzlehttp/guzzle": "^7", + "ext-json": "*", + "symfony/serializer": "^5.3", + "symfony/property-access": "^5.3", + "doctrine/annotations": "^1.13" }, "require-dev": { "phpunit/phpunit": "^9" diff --git a/composer.lock b/composer.lock index a20f194..4c90e8b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,160 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "423c7bccfd76c422fe3bf5be15766f3b", + "content-hash": "49a93463262f4af2fda709969b88f300", "packages": [ + { + "name": "doctrine/annotations", + "version": "1.13.2", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "5b668aef16090008790395c02c893b1ba13f7e08" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/5b668aef16090008790395c02c893b1ba13f7e08", + "reference": "5b668aef16090008790395c02c893b1ba13f7e08", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "ext-tokenizer": "*", + "php": "^7.1 || ^8.0", + "psr/cache": "^1 || ^2 || ^3" + }, + "require-dev": { + "doctrine/cache": "^1.11 || ^2.0", + "doctrine/coding-standard": "^6.0 || ^8.1", + "phpstan/phpstan": "^0.12.20", + "phpunit/phpunit": "^7.5 || ^8.0 || ^9.1.5", + "symfony/cache": "^4.4 || ^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "https://www.doctrine-project.org/projects/annotations.html", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "support": { + "issues": "https://github.com/doctrine/annotations/issues", + "source": "https://github.com/doctrine/annotations/tree/1.13.2" + }, + "time": "2021-08-05T19:00:23+00:00" + }, + { + "name": "doctrine/lexer", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/e864bbf5904cb8f5bb334f99209b48018522f042", + "reference": "e864bbf5904cb8f5bb334f99209b48018522f042", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "phpstan/phpstan": "^0.11.8", + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "https://www.doctrine-project.org/projects/lexer.html", + "keywords": [ + "annotations", + "docblock", + "lexer", + "parser", + "php" + ], + "support": { + "issues": "https://github.com/doctrine/lexer/issues", + "source": "https://github.com/doctrine/lexer/tree/1.2.1" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Flexer", + "type": "tidelift" + } + ], + "time": "2020-05-25T17:44:05+00:00" + }, { "name": "guzzlehttp/guzzle", "version": "7.3.0", @@ -308,6 +460,55 @@ ], "time": "2021-10-06T17:43:30+00:00" }, + { + "name": "psr/cache", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", + "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", + "shasum": "" + }, + "require": { + "php": ">=8.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "support": { + "source": "https://github.com/php-fig/cache/tree/3.0.0" + }, + "time": "2021-02-03T23:26:27+00:00" + }, { "name": "psr/http-client", "version": "1.0.1", @@ -347,47 +548,772 @@ "homepage": "http://www.php-fig.org/" } ], - "description": "Common interface for HTTP clients", - "homepage": "https://github.com/php-fig/http-client", + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/master" + }, + "time": "2020-06-29T06:28:15+00:00" + }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/master" + }, + "time": "2019-04-30T12:38:16+00:00" + }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/master" + }, + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v2.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627", + "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-03-23T23:28:01+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-02-19T12:13:01+00:00" + }, + { + "name": "symfony/polyfill-intl-grapheme", + "version": "v1.23.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-grapheme.git", + "reference": "16880ba9c5ebe3642d1995ab866db29270b36535" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/16880ba9c5ebe3642d1995ab866db29270b36535", + "reference": "16880ba9c5ebe3642d1995ab866db29270b36535", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Grapheme\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's grapheme_* functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "grapheme", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.23.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-05-27T12:26:48+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8590a5f561694770bdcd3f9b5c69dde6945028e8", + "reference": "8590a5f561694770bdcd3f9b5c69dde6945028e8", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.23.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-02-19T12:13:01+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.23.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6", + "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-05-27T12:26:48+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "v1.23.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", + "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-07-28T13:41:28+00:00" + }, + { + "name": "symfony/property-access", + "version": "v5.3.8", + "source": { + "type": "git", + "url": "https://github.com/symfony/property-access.git", + "reference": "2fbab5f95ddb6b8e85f38a6a8a04a17c0acc4d66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/property-access/zipball/2fbab5f95ddb6b8e85f38a6a8a04a17c0acc4d66", + "reference": "2fbab5f95ddb6b8e85f38a6a8a04a17c0acc4d66", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1", + "symfony/polyfill-php80": "^1.16", + "symfony/property-info": "^5.2" + }, + "require-dev": { + "symfony/cache": "^4.4|^5.0" + }, + "suggest": { + "psr/cache-implementation": "To cache access methods." + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\PropertyAccess\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides functions to read and write from/to an object or array using a simple string notation", + "homepage": "https://symfony.com", "keywords": [ - "http", - "http-client", - "psr", - "psr-18" + "access", + "array", + "extraction", + "index", + "injection", + "object", + "property", + "property path", + "reflection" ], "support": { - "source": "https://github.com/php-fig/http-client/tree/master" + "source": "https://github.com/symfony/property-access/tree/v5.3.8" }, - "time": "2020-06-29T06:28:15+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-09-10T11:55:24+00:00" }, { - "name": "psr/http-factory", - "version": "1.0.1", + "name": "symfony/property-info", + "version": "v5.3.8", "source": { "type": "git", - "url": "https://github.com/php-fig/http-factory.git", - "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + "url": "https://github.com/symfony/property-info.git", + "reference": "39de5bed8c036f76ec0457ec52908e45d5497947" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", - "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "url": "https://api.github.com/repos/symfony/property-info/zipball/39de5bed8c036f76ec0457ec52908e45d5497947", + "reference": "39de5bed8c036f76ec0457ec52908e45d5497947", "shasum": "" }, "require": { - "php": ">=7.0.0", - "psr/http-message": "^1.0" + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1", + "symfony/polyfill-php80": "^1.16", + "symfony/string": "^5.1" }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } + "conflict": { + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/dependency-injection": "<4.4" }, + "require-dev": { + "doctrine/annotations": "^1.10.4", + "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", + "symfony/cache": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/serializer": "^4.4|^5.0" + }, + "suggest": { + "phpdocumentor/reflection-docblock": "To use the PHPDoc", + "psr/cache-implementation": "To cache results", + "symfony/doctrine-bridge": "To use Doctrine metadata", + "symfony/serializer": "To use Serializer metadata" + }, + "type": "library", "autoload": { "psr-4": { - "Psr\\Http\\Message\\": "src/" - } + "Symfony\\Component\\PropertyInfo\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -395,53 +1321,109 @@ ], "authors": [ { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "name": "Kévin Dunglas", + "email": "dunglas@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Common interfaces for PSR-7 HTTP message factories", + "description": "Extracts information about PHP class' properties using metadata of popular sources", + "homepage": "https://symfony.com", "keywords": [ - "factory", - "http", - "message", - "psr", - "psr-17", - "psr-7", - "request", - "response" + "doctrine", + "phpdoc", + "property", + "symfony", + "type", + "validator" ], "support": { - "source": "https://github.com/php-fig/http-factory/tree/master" + "source": "https://github.com/symfony/property-info/tree/v5.3.8" }, - "time": "2019-04-30T12:38:16+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-09-07T07:41:40+00:00" }, { - "name": "psr/http-message", - "version": "1.0.1", + "name": "symfony/serializer", + "version": "v5.3.8", "source": { "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + "url": "https://github.com/symfony/serializer.git", + "reference": "a877799b1e94f792208bea68295f6675027c92be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", - "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "url": "https://api.github.com/repos/symfony/serializer/zipball/a877799b1e94f792208bea68295f6675027c92be", + "reference": "a877799b1e94f792208bea68295f6675027c92be", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-php80": "^1.16" }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } + "conflict": { + "doctrine/annotations": "<1.12", + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/dependency-injection": "<4.4", + "symfony/property-access": "<4.4", + "symfony/property-info": "<5.3", + "symfony/yaml": "<4.4" + }, + "require-dev": { + "doctrine/annotations": "^1.12", + "phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0", + "symfony/cache": "^4.4|^5.0", + "symfony/config": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/error-handler": "^4.4|^5.0", + "symfony/filesystem": "^4.4|^5.0", + "symfony/form": "^4.4|^5.0", + "symfony/http-foundation": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/mime": "^4.4|^5.0", + "symfony/property-access": "^4.4.9|^5.0.9", + "symfony/property-info": "^5.3", + "symfony/uid": "^5.1", + "symfony/validator": "^4.4|^5.0", + "symfony/var-dumper": "^4.4|^5.0", + "symfony/var-exporter": "^4.4|^5.0", + "symfony/yaml": "^4.4|^5.0" + }, + "suggest": { + "psr/cache-implementation": "For using the metadata cache.", + "symfony/config": "For using the XML mapping loader.", + "symfony/mime": "For using a MIME type guesser within the DataUriNormalizer.", + "symfony/property-access": "For using the ObjectNormalizer.", + "symfony/property-info": "To deserialize relations.", + "symfony/var-exporter": "For using the metadata compiler.", + "symfony/yaml": "For using the default YAML mapping loader." }, + "type": "library", "autoload": { "psr-4": { - "Psr\\Http\\Message\\": "src/" - } + "Symfony\\Component\\Serializer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -449,50 +1431,73 @@ ], "authors": [ { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], + "description": "Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.", + "homepage": "https://symfony.com", "support": { - "source": "https://github.com/php-fig/http-message/tree/master" + "source": "https://github.com/symfony/serializer/tree/v5.3.8" }, - "time": "2016-08-06T14:39:51+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-09-17T08:55:39+00:00" }, { - "name": "ralouphie/getallheaders", - "version": "3.0.3", + "name": "symfony/string", + "version": "v5.3.7", "source": { "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" + "url": "https://github.com/symfony/string.git", + "reference": "8d224396e28d30f81969f083a58763b8b9ceb0a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", + "url": "https://api.github.com/repos/symfony/string/zipball/8d224396e28d30f81969f083a58763b8b9ceb0a5", + "reference": "8d224396e28d30f81969f083a58763b8b9ceb0a5", "shasum": "" }, "require": { - "php": ">=5.6" + "php": ">=7.2.5", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-intl-grapheme": "~1.0", + "symfony/polyfill-intl-normalizer": "~1.0", + "symfony/polyfill-mbstring": "~1.0", + "symfony/polyfill-php80": "~1.15" }, "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" + "symfony/error-handler": "^4.4|^5.0", + "symfony/http-client": "^4.4|^5.0", + "symfony/translation-contracts": "^1.1|^2", + "symfony/var-exporter": "^4.4|^5.0" }, "type": "library", "autoload": { + "psr-4": { + "Symfony\\Component\\String\\": "" + }, "files": [ - "src/getallheaders.php" + "Resources/functions.php" + ], + "exclude-from-classmap": [ + "/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -501,16 +1506,42 @@ ], "authors": [ { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], - "description": "A polyfill for getallheaders.", + "description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way", + "homepage": "https://symfony.com", + "keywords": [ + "grapheme", + "i18n", + "string", + "unicode", + "utf-8", + "utf8" + ], "support": { - "issues": "https://github.com/ralouphie/getallheaders/issues", - "source": "https://github.com/ralouphie/getallheaders/tree/develop" + "source": "https://github.com/symfony/string/tree/v5.3.7" }, - "time": "2019-03-08T08:55:37+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-08-26T08:00:08+00:00" } ], "packages-dev": [ @@ -2419,85 +3450,6 @@ ], "time": "2020-09-28T06:39:44+00:00" }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.23.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.23.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-02-19T12:13:01+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.1", @@ -2613,8 +3565,9 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.0", - "ext-curl": "*" + "php": ">=7.2.24", + "ext-curl": "*", + "ext-json": "*" }, "platform-dev": [], "plugin-api-version": "2.1.0" diff --git a/src/Client.php b/src/Client.php index 88c95da..160fc6b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -1,6 +1,25 @@ config = $config; - $this->client = new GuzzleHttp\Client([ + + + $this->serializer = new Serializer( + [ + new DateTimeNormalizer(), + new ArrayDenormalizer(), + new ObjectNormalizer( + new ClassMetadataFactory( + new AnnotationLoader(new AnnotationReader() + ) + ), + null, + null, + new ReflectionExtractor() + ), + ], + [new JsonDecode(), new JsonEncode()] + ); + + $stack = HandlerStack::create(); + $stack->push(Logger::logger()); + + $tokenUrl = $config->getBaseURL() . '/auth/web/connect/token'; + $stack->push(Authentication::oauth2($tokenUrl, $config->getClientId(), $config->getSecret(), $this->serializer)); + + $this->client = new \GuzzleHttp\Client([ + 'handler' => $stack, 'timeout' => $config->getTimeout(), - 'base_uri' => $config->getBaseURL() + 'base_uri' => $config->getBaseURL() . '/nimble' ]); } @@ -34,19 +86,34 @@ public function __construct(Config $config) * * @param string $method Request Method * @param string $path Request Path - * @return Response HTTP Response + * @param ?array $options Request Options + * @return ResponseInterface HTTP Response + * @throws GuzzleException */ - public function request(string $method, string $path, array $query = null): Response + public function request(string $method, string $path, array $options = []): ResponseInterface { - $opts = []; - - if ($query) { - $opts['query'] = $query; - } + return $this->client->request($method, $path, $options); + } - $this->client->request($method, $path, $opts); + /** + * JSON Request + * + * @param string $method HTTP Method + * @param string $path Request Path + * @param string $t Return Type + * @param array $options Request options + * @return mixed + * @throws GuzzleException + */ + public function json(string $method, string $path, string $t, array $options = []) + { + $rsp = $this->request($method, $path, $options); + $content = $rsp->getBody()->getContents(); + return $this->serializer->deserialize($content, $t, 'json'); } + use TourCache; + /** * @return Config */ diff --git a/src/Config.php b/src/Config.php index 7f0bf38..de973be 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1,5 +1,7 @@ $tokenUrl, + ]); + + $token = ''; + $expires = 0; + + return function(callable $handler) use ($ac, $clientId, $secret, $token, $expires, $serializer) { + return function (RequestInterface $request, array $options) use ($handler, $ac, $clientId, $secret, $token, $expires, $serializer) { + + if ($expires <= time() || $token === '') { + $rsp = $ac->request('POST','', [ + 'form_params' => [ + 'client_id' => $clientId, + 'client_secret' => $secret, + 'grant_type' => 'client_credentials' + ] + ]); + + /** + * @var AuthenticationResponse $data + */ + $data = $serializer->deserialize($rsp->getBody(), AuthenticationResponse::class, 'json'); + + $token = $data->getAccessToken(); + $expires = time() + $data->getExpiresIn(); + } + + $request = $request->withHeader('Authorization', 'Bearer ' . $token); + return $handler($request, $options); + }; + }; + } +} diff --git a/src/Middleware/Logger.php b/src/Middleware/Logger.php new file mode 100644 index 0000000..1722f9a --- /dev/null +++ b/src/Middleware/Logger.php @@ -0,0 +1,59 @@ +then(function (ResponseInterface $response) { + return $response; + }); + }; + }; + } + + // Create a logger and start logging interactions + $logger = new ZenLogger('libraries/tigerbay'); + + return function(callable $handler) use ($logger) { + return function(RequestInterface $request, array $options) use ($handler, $logger) { + $start = microtime(true); + $promise = $handler($request, $options); + return $promise->then( + function (ResponseInterface $response) use ($logger, $request, $start) { + $end = microtime(true); + $delta = $end - $start; + + $level = $response->getStatusCode() >= 400 ? ZenLogger::ERROR : ZenLogger::INFO; + + $logger->log( + "Request: {$request->getMethod()} \"{$request->getUri()->getPath()}\" ". + $response->getStatusCode() . " " . number_format($delta*1000, 0) . 'ms', + [ + 'request' => $request, + 'response' => $response + ], + $level + ); + } + ); + }; + }; + } +} diff --git a/src/Models/Accommodation.php b/src/Models/Accommodation.php new file mode 100644 index 0000000..9b7d898 --- /dev/null +++ b/src/Models/Accommodation.php @@ -0,0 +1,75 @@ +setupId; + } + + /** + * @param int $setupId + * @return Accommodation + */ + public function setSetupId(int $setupId): Accommodation + { + $this->setupId = $setupId; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + * @return Accommodation + */ + public function setName(string $name): Accommodation + { + $this->name = $name; + return $this; + } + + /** + * @return Location + */ + public function getLocation(): Location + { + return $this->location; + } + + /** + * @param Location $location + * @return Accommodation + */ + public function setLocation(Location $location): Accommodation + { + $this->location = $location; + return $this; + } +} diff --git a/src/Models/AuthenticationResponse.php b/src/Models/AuthenticationResponse.php new file mode 100644 index 0000000..e7cab68 --- /dev/null +++ b/src/Models/AuthenticationResponse.php @@ -0,0 +1,57 @@ +accessToken; + } + + /** + * @param string $accessToken + * @return AuthenticationResponse + */ + public function setAccessToken(string $accessToken): AuthenticationResponse + { + $this->accessToken = $accessToken; + return $this; + } + + /** + * @return int + */ + public function getExpiresIn(): int + { + return $this->expiresIn; + } + + /** + * @param int $expiresIn + * @return AuthenticationResponse + */ + public function setExpiresIn(int $expiresIn): AuthenticationResponse + { + $this->expiresIn = $expiresIn; + return $this; + } +} diff --git a/src/Models/Extra.php b/src/Models/Extra.php new file mode 100644 index 0000000..6ea2e5e --- /dev/null +++ b/src/Models/Extra.php @@ -0,0 +1,56 @@ +id; + } + + /** + * @param int $id + * @return ExtraType + */ + public function setId(int $id): ExtraType + { + $this->id = $id; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + * @return ExtraType + */ + public function setName(string $name): ExtraType + { + $this->name = $name; + return $this; + } + + /** + * @return string[] + */ + public function getTags(): array + { + return $this->tags; + } + + /** + * @param string[] $tags + * @return ExtraType + */ + public function setTags(array $tags): ExtraType + { + $this->tags = $tags; + return $this; + } +} diff --git a/src/Models/InventorySummary.php b/src/Models/InventorySummary.php new file mode 100644 index 0000000..e16a309 --- /dev/null +++ b/src/Models/InventorySummary.php @@ -0,0 +1,214 @@ +allocation; + } + + /** + * @param int $allocation + * @return InventorySummary + */ + public function setAllocation(int $allocation): InventorySummary + { + $this->allocation = $allocation; + return $this; + } + + /** + * @return int + */ + public function getAvailable(): int + { + return $this->available; + } + + /** + * @param int $available + * @return InventorySummary + */ + public function setAvailable(int $available): InventorySummary + { + $this->available = $available; + return $this; + } + + /** + * @return int + */ + public function getConfirmed(): int + { + return $this->confirmed; + } + + /** + * @param int $confirmed + * @return InventorySummary + */ + public function setConfirmed(int $confirmed): InventorySummary + { + $this->confirmed = $confirmed; + return $this; + } + + /** + * @return int + */ + public function getOptioned(): int + { + return $this->optioned; + } + + /** + * @param int $optioned + * @return InventorySummary + */ + public function setOptioned(int $optioned): InventorySummary + { + $this->optioned = $optioned; + return $this; + } + + /** + * @return bool + */ + public function isOnRequest(): bool + { + return $this->isOnRequest; + } + + /** + * @param bool $isOnRequest + * @return InventorySummary + */ + public function setIsOnRequest(bool $isOnRequest): InventorySummary + { + $this->isOnRequest = $isOnRequest; + return $this; + } + + /** + * @return bool + */ + public function isSupplierStopSale(): bool + { + return $this->isSupplierStopSale; + } + + /** + * @param bool $isSupplierStopSale + * @return InventorySummary + */ + public function setIsSupplierStopSale(bool $isSupplierStopSale): InventorySummary + { + $this->isSupplierStopSale = $isSupplierStopSale; + return $this; + } + + /** + * @return bool + */ + public function isCompanyStopSale(): bool + { + return $this->isCompanyStopSale; + } + + /** + * @param bool $isCompanyStopSale + * @return InventorySummary + */ + public function setIsCompanyStopSale(bool $isCompanyStopSale): InventorySummary + { + $this->isCompanyStopSale = $isCompanyStopSale; + return $this; + } + + /** + * @return bool + */ + public function isClosed(): bool + { + return $this->isClosed; + } + + /** + * @param bool $isClosed + * @return InventorySummary + */ + public function setIsClosed(bool $isClosed): InventorySummary + { + $this->isClosed = $isClosed; + return $this; + } + + /** + * @return bool + */ + public function isFreeSell(): bool + { + return $this->isFreeSell; + } + + /** + * @param bool $isFreeSell + * @return InventorySummary + */ + public function setIsFreeSell(bool $isFreeSell): InventorySummary + { + $this->isFreeSell = $isFreeSell; + return $this; + } +} diff --git a/src/Models/Location.php b/src/Models/Location.php new file mode 100644 index 0000000..78b49f9 --- /dev/null +++ b/src/Models/Location.php @@ -0,0 +1,121 @@ +setupId; + } + + /** + * @param int $setupId + * @return Location + */ + public function setSetupId(int $setupId): Location + { + $this->setupId = $setupId; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + * @return Location + */ + public function setName(string $name): Location + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getReference(): string + { + return $this->reference; + } + + /** + * @param string $reference + * @return Location + */ + public function setReference(string $reference): Location + { + $this->reference = $reference; + return $this; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + * @return Location + */ + public function setType(string $type): Location + { + $this->type = $type; + return $this; + } + + /** + * @return bool + */ + public function isDomestic(): bool + { + return $this->isDomestic; + } + + /** + * @param bool $isDomestic + * @return Location + */ + public function setIsDomestic(bool $isDomestic): Location + { + $this->isDomestic = $isDomestic; + return $this; + } +} diff --git a/src/Models/Price.php b/src/Models/Price.php new file mode 100644 index 0000000..f3f8e92 --- /dev/null +++ b/src/Models/Price.php @@ -0,0 +1,53 @@ +value; + } + + /** + * @param float $value + * @return Price + */ + public function setValue(float $value): Price + { + $this->value = $value; + return $this; + } + + /** + * @return string + */ + public function getCurrencyCode(): string + { + return $this->currencyCode; + } + + /** + * @param string $currencyCode + * @return Price + */ + public function setCurrencyCode(string $currencyCode): Price + { + $this->currencyCode = $currencyCode; + return $this; + } +} diff --git a/src/Models/PriceSummary.php b/src/Models/PriceSummary.php new file mode 100644 index 0000000..0a61f2c --- /dev/null +++ b/src/Models/PriceSummary.php @@ -0,0 +1,29 @@ +adultPrice; + } + + /** + * @param Price $adultPrice + * @return PriceSummary + */ + public function setAdultPrice(Price $adultPrice): PriceSummary + { + $this->adultPrice = $adultPrice; + return $this; + } +} diff --git a/src/Models/TourCacheSearchRequest.php b/src/Models/TourCacheSearchRequest.php new file mode 100644 index 0000000..8368abc --- /dev/null +++ b/src/Models/TourCacheSearchRequest.php @@ -0,0 +1,72 @@ +startDate; + } + + /** + * @param DateTimeInterface|null $startDate + * @return TourCacheSearchRequest + */ + public function setStartDate(DateTimeInterface $startDate): TourCacheSearchRequest + { + $this->startDate = $startDate; + return $this; + } + + /** + * @return DateTimeInterface|null + */ + public function getEndDate(): DateTimeInterface + { + return $this->endDate; + } + + /** + * @param DateTimeInterface|null $endDate + * @return TourCacheSearchRequest + */ + public function setEndDate(DateTimeInterface $endDate): TourCacheSearchRequest + { + $this->endDate = $endDate; + return $this; + } + + public function toArray(): array + { + $v = []; + + if ($this->getStartDate() !== null) { + $v['searchQuery.serviceDateRange.from'] = $this->getStartDate()->format('y-m-d'); + } + + if ($this->getEndDate() !== null) { + $v['searchQuery.serviceDateRange.to'] = $this->getEndDate()->format('y-m-d'); + } + + return $v; + } + + +} diff --git a/src/Models/TourCacheSearchResult.php b/src/Models/TourCacheSearchResult.php new file mode 100644 index 0000000..876ce46 --- /dev/null +++ b/src/Models/TourCacheSearchResult.php @@ -0,0 +1,583 @@ +id; + } + + /** + * @param string $id + * @return TourCacheSearchResult + */ + public function setId(string $id): TourCacheSearchResult + { + $this->id = $id; + return $this; + } + + /** + * @return int + */ + public function getDepartureSetupId(): int + { + return $this->departureSetupId; + } + + /** + * @param int $departureSetupId + * @return TourCacheSearchResult + */ + public function setDepartureSetupId(int $departureSetupId): TourCacheSearchResult + { + $this->departureSetupId = $departureSetupId; + return $this; + } + + /** + * @return int + */ + public function getPriceSetId(): int + { + return $this->priceSetId; + } + + /** + * @param int $priceSetId + * @return TourCacheSearchResult + */ + public function setPriceSetId(int $priceSetId): TourCacheSearchResult + { + $this->priceSetId = $priceSetId; + return $this; + } + + /** + * @return int + */ + public function getTourId(): int + { + return $this->tourId; + } + + /** + * @param int $tourId + * @return TourCacheSearchResult + */ + public function setTourId(int $tourId): TourCacheSearchResult + { + $this->tourId = $tourId; + return $this; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @param string $name + * @return TourCacheSearchResult + */ + public function setName(string $name): TourCacheSearchResult + { + $this->name = $name; + return $this; + } + + /** + * @return string + */ + public function getCode(): string + { + return $this->code; + } + + /** + * @param string $code + * @return TourCacheSearchResult + */ + public function setCode(string $code): TourCacheSearchResult + { + $this->code = $code; + return $this; + } + + /** + * @return DateTimeInterface + */ + public function getStartDate(): DateTimeInterface + { + return $this->startDate; + } + + /** + * @param DateTimeInterface $startDate + * @return TourCacheSearchResult + */ + public function setStartDate(DateTimeInterface $startDate): TourCacheSearchResult + { + $this->startDate = $startDate; + return $this; + } + + /** + * @return DateTimeInterface + */ + public function getEndData(): DateTimeInterface + { + return $this->endDate; + } + + /** + * @param DateTimeInterface $endDate + * @return TourCacheSearchResult + */ + public function setEndDate(DateTimeInterface $endDate): TourCacheSearchResult + { + $this->endDate = $endDate; + return $this; + } + + /** + * @return int + */ + public function getDuration(): int + { + return $this->duration; + } + + /** + * @param int $duration + * @return TourCacheSearchResult + */ + public function setDuration(int $duration): TourCacheSearchResult + { + $this->duration = $duration; + return $this; + } + + /** + * @return InventorySummary + */ + public function getInventorySummary(): InventorySummary + { + return $this->inventorySummary; + } + + /** + * @param InventorySummary $inventorySummary + * @return TourCacheSearchResult + */ + public function setInventorySummary(InventorySummary $inventorySummary): TourCacheSearchResult + { + $this->inventorySummary = $inventorySummary; + return $this; + } + + /** + * @return DateTimeInterface + */ + public function getGenerated(): DateTimeInterface + { + return $this->generated; + } + + /** + * @param DateTimeInterface $generated + * @return TourCacheSearchResult + */ + public function setGenerated(DateTimeInterface $generated): TourCacheSearchResult + { + $this->generated = $generated; + return $this; + } + + /** + * @return TravellerUnit[] + */ + public function getSingleTravellerUnits(): array + { + return $this->singleTravellerUnits; + } + + /** + * @param TravellerUnit[] $singleTravellerUnits + * @return TourCacheSearchResult + */ + public function setSingleTravellerUnits(array $singleTravellerUnits): TourCacheSearchResult + { + $this->singleTravellerUnits = $singleTravellerUnits; + return $this; + } + + /** + * @return TravellerUnit[] + */ + public function getGroupTravellerUnits(): array + { + return $this->groupTravellerUnits; + } + + /** + * @param TravellerUnit[] $groupTravellerUnits + * @return TourCacheSearchResult + */ + public function setGroupTravellerUnits(array $groupTravellerUnits): TourCacheSearchResult + { + $this->groupTravellerUnits = $groupTravellerUnits; + return $this; + } + + /** + * @return Extra[] + */ + public function getExtras(): array + { + return $this->extras; + } + + /** + * @param Extra[] $extras + * @return TourCacheSearchResult + */ + public function setExtras(array $extras): TourCacheSearchResult + { + $this->extras = $extras; + return $this; + } + + /** + * @return Location[]|null + */ + public function getLocations(): ?array + { + return $this->locations; + } + + /** + * @param Location[]|null $locations + * @return TourCacheSearchResult + */ + public function setLocations(?array $locations): TourCacheSearchResult + { + $this->locations = $locations; + return $this; + } + + /** + * @return Price + */ + public function getTourPrice(): Price + { + return $this->tourPrice; + } + + /** + * @param Price $tourPrice + * @return TourCacheSearchResult + */ + public function setTourPrice(Price $tourPrice): TourCacheSearchResult + { + $this->tourPrice = $tourPrice; + return $this; + } + + /** + * @return Price + */ + public function getPerPersonSingleTravellerTotalPrice(): Price + { + return $this->perPersonSingleTravellerTotalPrice; + } + + /** + * @param Price $perPersonSingleTravellerTotalPrice + * @return TourCacheSearchResult + */ + public function setPerPersonSingleTravellerTotalPrice(Price $perPersonSingleTravellerTotalPrice): TourCacheSearchResult + { + $this->perPersonSingleTravellerTotalPrice = $perPersonSingleTravellerTotalPrice; + return $this; + } + + /** + * @return Price + */ + public function getPerPersonGroupTravellerTotalPrice(): Price + { + return $this->perPersonGroupTravellerTotalPrice; + } + + /** + * @param Price $perPersonGroupTravellerTotalPrice + * @return TourCacheSearchResult + */ + public function setPerPersonGroupTravellerTotalPrice(Price $perPersonGroupTravellerTotalPrice): TourCacheSearchResult + { + $this->perPersonGroupTravellerTotalPrice = $perPersonGroupTravellerTotalPrice; + return $this; + } + + /** + * @return Price + */ + public function getPerPersonSingleTravellerTotalDiscount(): Price + { + return $this->perPersonSingleTravellerTotalDiscount; + } + + /** + * @param Price $perPersonSingleTravellerTotalDiscount + * @return TourCacheSearchResult + */ + public function setPerPersonSingleTravellerTotalDiscount(Price $perPersonSingleTravellerTotalDiscount): TourCacheSearchResult + { + $this->perPersonSingleTravellerTotalDiscount = $perPersonSingleTravellerTotalDiscount; + return $this; + } + + /** + * @return Price + */ + public function getPerPersonGroupTravellerTotalDiscount(): Price + { + return $this->perPersonGroupTravellerTotalDiscount; + } + + /** + * @param Price $perPersonGroupTravellerTotalDiscount + * @return TourCacheSearchResult + */ + public function setPerPersonGroupTravellerTotalDiscount(Price $perPersonGroupTravellerTotalDiscount): TourCacheSearchResult + { + $this->perPersonGroupTravellerTotalDiscount = $perPersonGroupTravellerTotalDiscount; + return $this; + } + + /** + * @return string + */ + public function getRefreshId(): string + { + return $this->refreshId; + } + + /** + * @param string $refreshId + * @return TourCacheSearchResult + */ + public function setRefreshId(string $refreshId): TourCacheSearchResult + { + $this->refreshId = $refreshId; + return $this; + } + + /** + * @return int + */ + public function getMinimumSingleRooms(): int + { + return $this->minimumSingleRooms; + } + + /** + * @param int $minimumSingleRooms + * @return TourCacheSearchResult + */ + public function setMinimumSingleRooms(int $minimumSingleRooms): TourCacheSearchResult + { + $this->minimumSingleRooms = $minimumSingleRooms; + return $this; + } + + /** + * @return int + */ + public function getMinimumTwinRooms(): int + { + return $this->minimumTwinRooms; + } + + /** + * @param int $minimumTwinRooms + * @return TourCacheSearchResult + */ + public function setMinimumTwinRooms(int $minimumTwinRooms): TourCacheSearchResult + { + $this->minimumTwinRooms = $minimumTwinRooms; + return $this; + } + + /** + * @return int + */ + public function getMinimumTripleRooms(): int + { + return $this->minimumTripleRooms; + } + + /** + * @param int $minimumTripleRooms + * @return TourCacheSearchResult + */ + public function setMinimumTripleRooms(int $minimumTripleRooms): TourCacheSearchResult + { + $this->minimumTripleRooms = $minimumTripleRooms; + return $this; + } + + /** + * @return string[] + */ + public function getTags(): array + { + return $this->tags; + } + + /** + * @param string[] $tags + * @return TourCacheSearchResult + */ + public function setTags(array $tags): TourCacheSearchResult + { + $this->tags = $tags; + return $this; + } +} diff --git a/src/Models/TourCacheStats.php b/src/Models/TourCacheStats.php new file mode 100644 index 0000000..a64deae --- /dev/null +++ b/src/Models/TourCacheStats.php @@ -0,0 +1,54 @@ +itemCount; + } + + /** + * @param int $itemCount + * @return TourCacheStats + */ + public function setItemCount(int $itemCount): TourCacheStats + { + $this->itemCount = $itemCount; + return $this; + } + + /** + * @return int + */ + public function getAverageAgeSeconds(): int + { + return $this->averageAgeSeconds; + } + + /** + * @param int $averageAgeSeconds + * @return TourCacheStats + */ + public function setAverageAgeSeconds(int $averageAgeSeconds): TourCacheStats + { + $this->averageAgeSeconds = $averageAgeSeconds; + return $this; + } +} diff --git a/src/Models/TravellerUnit.php b/src/Models/TravellerUnit.php new file mode 100644 index 0000000..645960a --- /dev/null +++ b/src/Models/TravellerUnit.php @@ -0,0 +1,216 @@ +name; + } + + /** + * @param string $name + * @return TravellerUnit + */ + public function setName(string $name): TravellerUnit + { + $this->name = $name; + return $this; + } + + /** + * @return int + */ + public function getSetupId(): int + { + return $this->setupId; + } + + /** + * @param int $setupId + * @return TravellerUnit + */ + public function setSetupId(int $setupId): TravellerUnit + { + $this->setupId = $setupId; + return $this; + } + + /** + * @return DateTimeInterface + */ + public function getStartDate(): DateTimeInterface + { + return $this->startDate; + } + + /** + * @param DateTimeInterface $startDate + * @return TravellerUnit + */ + public function setStartDate(DateTimeInterface $startDate): TravellerUnit + { + $this->startDate = $startDate; + return $this; + } + + /** + * @return Accommodation + */ + public function getAccommodation(): Accommodation + { + return $this->accommodation; + } + + /** + * @param Accommodation $accommodation + * @return TravellerUnit + */ + public function setAccommodation(Accommodation $accommodation): TravellerUnit + { + $this->accommodation = $accommodation; + return $this; + } + + /** + * @return PriceSummary + */ + public function getPriceSummary(): PriceSummary + { + return $this->priceSummary; + } + + /** + * @param PriceSummary $priceSummary + * @return TravellerUnit + */ + public function setPriceSummary(PriceSummary $priceSummary): TravellerUnit + { + $this->priceSummary = $priceSummary; + return $this; + } + + /** + * @return InventorySummary + */ + public function getInventorySummary(): InventorySummary + { + return $this->inventorySummary; + } + + /** + * @param InventorySummary $inventorySummary + * @return TravellerUnit + */ + public function setInventorySummary(InventorySummary $inventorySummary): TravellerUnit + { + $this->inventorySummary = $inventorySummary; + return $this; + } + + /** + * @return bool + */ + public function isDefault(): bool + { + return $this->isDefault; + } + + /** + * @param bool $isDefault + * @return TravellerUnit + */ + public function setIsDefault(bool $isDefault): TravellerUnit + { + $this->isDefault = $isDefault; + return $this; + } + + /** + * @return bool + */ + public function isMandatory(): bool + { + return $this->isMandatory; + } + + /** + * @param bool $isMandatory + * @return TravellerUnit + */ + public function setIsMandatory(bool $isMandatory): TravellerUnit + { + $this->isMandatory = $isMandatory; + return $this; + } + + /** + * @return string + */ + public function getTravellerType(): string + { + return $this->travellerType; + } + + /** + * @param string $travellerType + * @return TravellerUnit + */ + public function setTravellerType(string $travellerType): TravellerUnit + { + $this->travellerType = $travellerType; + return $this; + } +} diff --git a/src/TourCache.php b/src/TourCache.php new file mode 100644 index 0000000..3b12067 --- /dev/null +++ b/src/TourCache.php @@ -0,0 +1,37 @@ +json('GET', 'nimble/toursearch/cache/status', TourCacheStats::class); + } + + /** + * @param TourCacheSearchRequest $params + * @return TourCacheSearchResult[] Results + * @throws GuzzleException + */ + public function tourSearch(TourCacheSearchRequest $params): array + { + return $this->json( + 'GET', + 'nimble/toursearch/departures', + TourCacheSearchResult::class . '[]', + ['query' => $params->toArray()] + ); + } +} diff --git a/tests/ClientTest.php b/tests/ClientTest.php index bbb0d9b..2616db2 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -1,11 +1,40 @@ getTestClient(); + + /** + * @var TourCacheStats $stats + */ + $stats = $client->stats(); + + static::assertInstanceOf(TourCacheStats::class, $stats); + static::assertGreaterThan(0, $stats->getItemCount()); + static::assertGreaterThan(0, $stats->getAverageAgeSeconds()); + } + + public function testTourSearch() + { + $client = $this->getTestClient(); + + $start = new \DateTimeImmutable(); + $end = $start->add(new \DateInterval('P1M')); + $request = (new TourCacheSearchRequest())->setStartDate($start)->setEndDate($end); + + $results = $client->tourSearch($request); + + static::assertIsArray($results); + + $first = current($results); + + static::assertIsString($first->getId()); + static::assertIsInt($first->getInventorySummary()->getAllocation()); } } diff --git a/tests/ClientTestCase.php b/tests/ClientTestCase.php new file mode 100644 index 0000000..d73ad11 --- /dev/null +++ b/tests/ClientTestCase.php @@ -0,0 +1,18 @@ +setClientId('website') + ->setSecret('Secret') + ->setTimeout(10.0) + ->setBaseURL('https://hfholidays-preview.ontigerbay.co.uk'); + + return new \Mrzen\Tigerbay\Client($config); + } +}