From 27f28e3505a5261dca01d1a797764d72b6614c54 Mon Sep 17 00:00:00 2001 From: Daen Rebel Date: Fri, 4 Aug 2017 14:08:34 +0200 Subject: [PATCH] Release of version 1.0.90 --- autoload.php | 54 - docs/Api/BlockApi.md | 10 +- docs/Api/BroadcastApi.md | 24 +- docs/Api/CampaignApi.md | 12 +- docs/Api/ContactApi.md | 12 +- docs/Api/ExternalMessageApi.md | 4 +- docs/Api/GenreApi.md | 6 +- docs/Api/ItemApi.md | 20 +- docs/Api/ModelTypeApi.md | 6 +- docs/Api/PresenterApi.md | 12 +- docs/Api/ProgramApi.md | 12 +- docs/Api/StoryApi.md | 12 +- docs/Api/StringApi.md | 4 +- docs/Api/TagApi.md | 12 +- docs/Api/UserApi.md | 10 +- docs/Api/VisualSlideApi.md | 4 +- docs/Model/Broadcast.md | 2 +- docs/Model/BroadcastDataInput.md | 2 +- docs/Model/BroadcastResult.md | 2 +- docs/Model/StoryDataInput.md | 1 + docs/Model/StoryInputOnly.md | 10 + lib/Api/BlockApi.php | 1008 ++++++++-- lib/Api/BroadcastApi.php | 2768 +++++++++++++++++++++------ lib/Api/CampaignApi.php | 1266 +++++++++--- lib/Api/ContactApi.php | 1261 +++++++++--- lib/Api/ExternalMessageApi.php | 297 ++- lib/Api/GenreApi.php | 556 ++++-- lib/Api/ItemApi.php | 2359 ++++++++++++++++++----- lib/Api/ModelTypeApi.php | 576 ++++-- lib/Api/PresenterApi.php | 1261 +++++++++--- lib/Api/ProgramApi.php | 1281 ++++++++++--- lib/Api/StoryApi.php | 1257 +++++++++--- lib/Api/StringApi.php | 298 ++- lib/Api/TagApi.php | 1266 +++++++++--- lib/Api/UserApi.php | 998 ++++++++-- lib/Api/VisualSlideApi.php | 280 ++- lib/ApiClient.php | 371 ---- lib/ApiException.php | 12 +- lib/Configuration.php | 356 +--- lib/HeaderSelector.php | 110 ++ lib/Model/Broadcast.php | 6 +- lib/Model/BroadcastDataInput.php | 6 +- lib/Model/BroadcastResult.php | 6 +- lib/Model/StoryDataInput.php | 37 +- lib/Model/StoryInputOnly.php | 242 +++ lib/ObjectSerializer.php | 37 +- test/Api/BlockApiTest.php | 1 - test/Api/BroadcastApiTest.php | 1 - test/Api/CampaignApiTest.php | 1 - test/Api/ContactApiTest.php | 1 - test/Api/ExternalMessageApiTest.php | 1 - test/Api/GenreApiTest.php | 1 - test/Api/ItemApiTest.php | 1 - test/Api/ModelTypeApiTest.php | 1 - test/Api/PresenterApiTest.php | 1 - test/Api/ProgramApiTest.php | 1 - test/Api/StoryApiTest.php | 1 - test/Api/StringApiTest.php | 1 - test/Api/TagApiTest.php | 1 - test/Api/UserApiTest.php | 1 - test/Api/VisualSlideApiTest.php | 1 - test/Model/StoryDataInputTest.php | 7 + test/Model/StoryInputOnlyTest.php | 86 + 63 files changed, 13784 insertions(+), 4470 deletions(-) delete mode 100644 autoload.php create mode 100644 docs/Model/StoryInputOnly.md delete mode 100644 lib/ApiClient.php create mode 100644 lib/HeaderSelector.php create mode 100644 lib/Model/StoryInputOnly.php create mode 100644 test/Model/StoryInputOnlyTest.php diff --git a/autoload.php b/autoload.php deleted file mode 100644 index b10ef87..0000000 --- a/autoload.php +++ /dev/null @@ -1,54 +0,0 @@ -setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BlockApi(); +$api_instance = new RadioManager\Api\BlockApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Block **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -79,7 +79,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BlockApi(); +$api_instance = new RadioManager\Api\BlockApi(new \Http\Adapter\Guzzle6\Client()); try { $result = $api_instance->getCurrentBlock(); @@ -125,7 +125,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BlockApi(); +$api_instance = new RadioManager\Api\BlockApi(new \Http\Adapter\Guzzle6\Client()); try { $result = $api_instance->getNextBlock(); @@ -171,7 +171,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BlockApi(); +$api_instance = new RadioManager\Api\BlockApi(new \Http\Adapter\Guzzle6\Client()); $page = 1; // int | Current page *(Optional)* $start_min = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | Minimum start date *(Optional)* $start_max = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | Maximum start date *(Optional)* diff --git a/docs/Api/BroadcastApi.md b/docs/Api/BroadcastApi.md index 44ac071..967856b 100644 --- a/docs/Api/BroadcastApi.md +++ b/docs/Api/BroadcastApi.md @@ -1,6 +1,6 @@ # RadioManager\BroadcastApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -34,7 +34,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\BroadcastDataInput(); // \RadioManager\Model\BroadcastDataInput | Data **(Required)** try { @@ -84,7 +84,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Broadcast **(Required)** try { @@ -134,7 +134,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Broadcast **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -186,7 +186,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); try { $result = $api_instance->getCurrentBroadcast(); @@ -232,7 +232,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $date = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | Date *(Optional)* try { @@ -282,7 +282,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $date = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | Date *(Optional)* try { @@ -332,7 +332,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); try { $result = $api_instance->getNextBroadcast(); @@ -378,7 +378,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $date = "date_example"; // string | Date *(Optional)* try { @@ -428,7 +428,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $page = 1; // int | Current page *(Optional)* $start_min = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | Minimum start date *(Optional)* $start_max = new \DateTime("2013-10-20T19:20:30+01:00"); // \DateTime | Maximum start date *(Optional)* @@ -498,7 +498,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Broadcast **(Required)** $program_id = 789; // int | Search on Program ID *(Optional)* `(Relation)` $presenter_id = 789; // int | Search on Presenter ID *(Optional)* `(Relation)` @@ -554,7 +554,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\BroadcastApi(); +$api_instance = new RadioManager\Api\BroadcastApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Broadcast **(Required)** $data = new \RadioManager\Model\BroadcastDataInput(); // \RadioManager\Model\BroadcastDataInput | Data *(Optional)* diff --git a/docs/Api/CampaignApi.md b/docs/Api/CampaignApi.md index c1778b9..720e7c3 100644 --- a/docs/Api/CampaignApi.md +++ b/docs/Api/CampaignApi.md @@ -1,6 +1,6 @@ # RadioManager\CampaignApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -28,7 +28,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\CampaignApi(); +$api_instance = new RadioManager\Api\CampaignApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\CampaignDataInput(); // \RadioManager\Model\CampaignDataInput | Data **(Required)** try { @@ -78,7 +78,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\CampaignApi(); +$api_instance = new RadioManager\Api\CampaignApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Campaign **(Required)** try { @@ -128,7 +128,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\CampaignApi(); +$api_instance = new RadioManager\Api\CampaignApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Campaign **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -180,7 +180,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\CampaignApi(); +$api_instance = new RadioManager\Api\CampaignApi(new \Http\Adapter\Guzzle6\Client()); $page = 789; // int | Current page *(Optional)* $model_type_id = 789; // int | Search on ModelType ID *(Optional)* $item_id = 789; // int | Search on Item ID *(Optional)* `(Relation)` @@ -240,7 +240,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\CampaignApi(); +$api_instance = new RadioManager\Api\CampaignApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Campaign **(Required)** $data = new \RadioManager\Model\CampaignDataInput(); // \RadioManager\Model\CampaignDataInput | Data *(Optional)* diff --git a/docs/Api/ContactApi.md b/docs/Api/ContactApi.md index 6608599..f709b9c 100644 --- a/docs/Api/ContactApi.md +++ b/docs/Api/ContactApi.md @@ -1,6 +1,6 @@ # RadioManager\ContactApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -28,7 +28,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ContactApi(); +$api_instance = new RadioManager\Api\ContactApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\ContactDataInput(); // \RadioManager\Model\ContactDataInput | Data **(Required)** try { @@ -78,7 +78,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ContactApi(); +$api_instance = new RadioManager\Api\ContactApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Contact **(Required)** try { @@ -128,7 +128,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ContactApi(); +$api_instance = new RadioManager\Api\ContactApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Contact **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -180,7 +180,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ContactApi(); +$api_instance = new RadioManager\Api\ContactApi(new \Http\Adapter\Guzzle6\Client()); $page = 1; // int | Current page *(Optional)* $model_type_id = 789; // int | Search on ModelType ID *(Optional)* $tag_id = 789; // int | Search on Tag ID *(Optional)* `(Relation)` @@ -238,7 +238,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ContactApi(); +$api_instance = new RadioManager\Api\ContactApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Contact **(Required)** $data = new \RadioManager\Model\ContactDataInput(); // \RadioManager\Model\ContactDataInput | Data *(Optional)* diff --git a/docs/Api/ExternalMessageApi.md b/docs/Api/ExternalMessageApi.md index 6d731f1..1f49b9b 100644 --- a/docs/Api/ExternalMessageApi.md +++ b/docs/Api/ExternalMessageApi.md @@ -1,6 +1,6 @@ # RadioManager\ExternalMessageApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -24,7 +24,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ExternalMessageApi(); +$api_instance = new RadioManager\Api\ExternalMessageApi(new \Http\Adapter\Guzzle6\Client()); $message = new \RadioManager\Model\ExternalMessageQueueData(); // \RadioManager\Model\ExternalMessageQueueData | Data **(Required)** try { diff --git a/docs/Api/GenreApi.md b/docs/Api/GenreApi.md index 468b4d7..ed2d1e3 100644 --- a/docs/Api/GenreApi.md +++ b/docs/Api/GenreApi.md @@ -1,6 +1,6 @@ # RadioManager\GenreApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -25,7 +25,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\GenreApi(); +$api_instance = new RadioManager\Api\GenreApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Genre **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -77,7 +77,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\GenreApi(); +$api_instance = new RadioManager\Api\GenreApi(new \Http\Adapter\Guzzle6\Client()); $page = 789; // int | Current page *(Optional)* $parent_id = 789; // int | Search on Parent ID of Genre *(Optional)* $program_id = 789; // int | Search on Program ID *(Optional)* `(Relation)` diff --git a/docs/Api/ItemApi.md b/docs/Api/ItemApi.md index a71c728..5c78dc7 100644 --- a/docs/Api/ItemApi.md +++ b/docs/Api/ItemApi.md @@ -1,6 +1,6 @@ # RadioManager\ItemApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -32,7 +32,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\ItemDataInput(); // \RadioManager\Model\ItemDataInput | Data *(Optional)* try { @@ -82,7 +82,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\ImportItem(); // \RadioManager\Model\ImportItem | Data *(Optional)* try { @@ -132,7 +132,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\ImportItem(); // \RadioManager\Model\ImportItem | Data *(Optional)* try { @@ -182,7 +182,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Item **(Required)** try { @@ -232,7 +232,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Item **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -284,7 +284,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $page = 789; // int | Current page *(Optional)* $order_by = "order_by_example"; // string | Field to order the results *(Optional)* $order_direction = "order_direction_example"; // string | Direction of ordering *(Optional)* @@ -370,7 +370,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\Data1(); // \RadioManager\Model\Data1 | Data *(Optional)* try { @@ -420,7 +420,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\Data(); // \RadioManager\Model\Data | Data *(Optional)* try { @@ -470,7 +470,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ItemApi(); +$api_instance = new RadioManager\Api\ItemApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Item **(Required)** $data = new \RadioManager\Model\Item(); // \RadioManager\Model\Item | Data *(Optional)* diff --git a/docs/Api/ModelTypeApi.md b/docs/Api/ModelTypeApi.md index e406770..6f82afd 100644 --- a/docs/Api/ModelTypeApi.md +++ b/docs/Api/ModelTypeApi.md @@ -1,6 +1,6 @@ # RadioManager\ModelTypeApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -25,7 +25,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ModelTypeApi(); +$api_instance = new RadioManager\Api\ModelTypeApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of ModelType **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -77,7 +77,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ModelTypeApi(); +$api_instance = new RadioManager\Api\ModelTypeApi(new \Http\Adapter\Guzzle6\Client()); $page = 789; // int | Current page *(Optional)* $model = "model_example"; // string | $program_id = 789; // int | Search on Program ID *(Optional)* diff --git a/docs/Api/PresenterApi.md b/docs/Api/PresenterApi.md index 8542c65..2cd4d5a 100644 --- a/docs/Api/PresenterApi.md +++ b/docs/Api/PresenterApi.md @@ -1,6 +1,6 @@ # RadioManager\PresenterApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -28,7 +28,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\PresenterApi(); +$api_instance = new RadioManager\Api\PresenterApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\PresenterDataInput(); // \RadioManager\Model\PresenterDataInput | Data **(Required)** try { @@ -78,7 +78,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\PresenterApi(); +$api_instance = new RadioManager\Api\PresenterApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | id of presenter try { @@ -128,7 +128,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\PresenterApi(); +$api_instance = new RadioManager\Api\PresenterApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | id of Presenter $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -180,7 +180,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\PresenterApi(); +$api_instance = new RadioManager\Api\PresenterApi(new \Http\Adapter\Guzzle6\Client()); $page = 789; // int | Current page *(Optional)* $model_type_id = 789; // int | Search on ModelType ID (Optional) $program_id = 789; // int | Search on Program ID *(Optional)* `(Relation)` @@ -238,7 +238,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\PresenterApi(); +$api_instance = new RadioManager\Api\PresenterApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | id of Presenter $data = new \RadioManager\Model\PresenterDataInput(); // \RadioManager\Model\PresenterDataInput | Data *(Optional)* diff --git a/docs/Api/ProgramApi.md b/docs/Api/ProgramApi.md index 4479169..e445067 100644 --- a/docs/Api/ProgramApi.md +++ b/docs/Api/ProgramApi.md @@ -1,6 +1,6 @@ # RadioManager\ProgramApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -28,7 +28,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ProgramApi(); +$api_instance = new RadioManager\Api\ProgramApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\ProgramDataInput(); // \RadioManager\Model\ProgramDataInput | Data **(Required)** try { @@ -78,7 +78,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ProgramApi(); +$api_instance = new RadioManager\Api\ProgramApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of program **(Required)** try { @@ -128,7 +128,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ProgramApi(); +$api_instance = new RadioManager\Api\ProgramApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Program **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -180,7 +180,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ProgramApi(); +$api_instance = new RadioManager\Api\ProgramApi(new \Http\Adapter\Guzzle6\Client()); $page = 789; // int | Current page *(Optional)* $genre_id = 789; // int | Search on Genre ID *(Optional)* $model_type_id = 789; // int | Search on ModelType ID *(Optional)* @@ -246,7 +246,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\ProgramApi(); +$api_instance = new RadioManager\Api\ProgramApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Program **(Required)** $data = new \RadioManager\Model\ProgramDataInput(); // \RadioManager\Model\ProgramDataInput | Data *(Optional)* diff --git a/docs/Api/StoryApi.md b/docs/Api/StoryApi.md index bd85876..ac11591 100644 --- a/docs/Api/StoryApi.md +++ b/docs/Api/StoryApi.md @@ -1,6 +1,6 @@ # RadioManager\StoryApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -28,7 +28,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\StoryApi(); +$api_instance = new RadioManager\Api\StoryApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\StoryDataInput(); // \RadioManager\Model\StoryDataInput | Data **(Required)** try { @@ -78,7 +78,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\StoryApi(); +$api_instance = new RadioManager\Api\StoryApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Story **(Required)** try { @@ -128,7 +128,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\StoryApi(); +$api_instance = new RadioManager\Api\StoryApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Story **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -180,7 +180,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\StoryApi(); +$api_instance = new RadioManager\Api\StoryApi(new \Http\Adapter\Guzzle6\Client()); $page = 1; // int | Current page *(Optional)* $model_type_id = 789; // int | Search on ModelType ID *(Optional)* $tag_id = 789; // int | Search on Tag ID *(Optional)* `(Relation)` @@ -238,7 +238,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\StoryApi(); +$api_instance = new RadioManager\Api\StoryApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Story **(Required)** $data = new \RadioManager\Model\StoryDataInput(); // \RadioManager\Model\StoryDataInput | Data *(Optional)* diff --git a/docs/Api/StringApi.md b/docs/Api/StringApi.md index c3c1465..e369451 100644 --- a/docs/Api/StringApi.md +++ b/docs/Api/StringApi.md @@ -1,6 +1,6 @@ # RadioManager\StringApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -24,7 +24,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\StringApi(); +$api_instance = new RadioManager\Api\StringApi(new \Http\Adapter\Guzzle6\Client()); $name = "name_example"; // string | Name of Strings **(Required)** $full_model = true; // bool | Full model or content only **(Required)** diff --git a/docs/Api/TagApi.md b/docs/Api/TagApi.md index dc752e1..44cfa13 100644 --- a/docs/Api/TagApi.md +++ b/docs/Api/TagApi.md @@ -1,6 +1,6 @@ # RadioManager\TagApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -28,7 +28,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\TagApi(); +$api_instance = new RadioManager\Api\TagApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\TagDataInput(); // \RadioManager\Model\TagDataInput | Data **(Required)** try { @@ -78,7 +78,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\TagApi(); +$api_instance = new RadioManager\Api\TagApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Tag **(Required)** try { @@ -128,7 +128,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\TagApi(); +$api_instance = new RadioManager\Api\TagApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Tag **(Required)** $_external_station_id = 789; // int | Query on a different (content providing) station *(Optional)* @@ -180,7 +180,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\TagApi(); +$api_instance = new RadioManager\Api\TagApi(new \Http\Adapter\Guzzle6\Client()); $page = 789; // int | Current page *(Optional)* $program_id = 789; // int | Search on Program ID *(Optional)* `(Relation)` $item_id = 789; // int | Search on Item ID *(Optional)* `(Relation)` @@ -240,7 +240,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\TagApi(); +$api_instance = new RadioManager\Api\TagApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | ID of Tag **(Required)** $data = new \RadioManager\Model\TagDataInput(); // \RadioManager\Model\TagDataInput | Data *(Optional)* diff --git a/docs/Api/UserApi.md b/docs/Api/UserApi.md index 5f58824..a96f854 100644 --- a/docs/Api/UserApi.md +++ b/docs/Api/UserApi.md @@ -1,6 +1,6 @@ # RadioManager\UserApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -27,7 +27,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\UserApi(); +$api_instance = new RadioManager\Api\UserApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | id of User try { @@ -77,7 +77,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\UserApi(); +$api_instance = new RadioManager\Api\UserApi(new \Http\Adapter\Guzzle6\Client()); $id = 789; // int | id of User try { @@ -127,7 +127,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\UserApi(); +$api_instance = new RadioManager\Api\UserApi(new \Http\Adapter\Guzzle6\Client()); $data = new \RadioManager\Model\InviteUserData(); // \RadioManager\Model\InviteUserData | Data **(Required)** try { @@ -177,7 +177,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\UserApi(); +$api_instance = new RadioManager\Api\UserApi(new \Http\Adapter\Guzzle6\Client()); $page = 1; // int | Current page *(Optional)* $role_id = 789; // int | Search on Role ID *(Optional)* diff --git a/docs/Api/VisualSlideApi.md b/docs/Api/VisualSlideApi.md index 4481e22..054c8be 100644 --- a/docs/Api/VisualSlideApi.md +++ b/docs/Api/VisualSlideApi.md @@ -1,6 +1,6 @@ # RadioManager\VisualSlideApi -All URIs are relative to *https://staging.radiomanager.pluxbox.com/api/v2* +All URIs are relative to *http://radiomanager.pb/api/v2* Method | HTTP request | Description ------------- | ------------- | ------------- @@ -24,7 +24,7 @@ RadioManager\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOU // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed // RadioManager\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer'); -$api_instance = new RadioManager\Api\VisualSlideApi(); +$api_instance = new RadioManager\Api\VisualSlideApi(new \Http\Adapter\Guzzle6\Client()); try { $result = $api_instance->getVisualSlide(); diff --git a/docs/Model/Broadcast.md b/docs/Model/Broadcast.md index 29ddcc4..cc4851b 100644 --- a/docs/Model/Broadcast.md +++ b/docs/Model/Broadcast.md @@ -23,7 +23,7 @@ Name | Type | Description | Notes **repetition_type** | **string** | | [optional] **repetition_end** | [**\DateTime**](\DateTime.md) | | [optional] **repetition_start** | [**\DateTime**](\DateTime.md) | | [optional] -**repetition_days** | **bool[]** | | [optional] +**repetition_days** | **string** | | [optional] **pty_code_id** | **int** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/docs/Model/BroadcastDataInput.md b/docs/Model/BroadcastDataInput.md index 5c8fd11..08ca35f 100644 --- a/docs/Model/BroadcastDataInput.md +++ b/docs/Model/BroadcastDataInput.md @@ -23,7 +23,7 @@ Name | Type | Description | Notes **repetition_type** | **string** | | [optional] **repetition_end** | [**\DateTime**](\DateTime.md) | | [optional] **repetition_start** | [**\DateTime**](\DateTime.md) | | [optional] -**repetition_days** | **bool[]** | | [optional] +**repetition_days** | **string** | | [optional] **pty_code_id** | **int** | | [optional] **tags** | **int[]** | | [optional] **presenters** | **int[]** | | [optional] diff --git a/docs/Model/BroadcastResult.md b/docs/Model/BroadcastResult.md index 911dacb..ee9fb18 100644 --- a/docs/Model/BroadcastResult.md +++ b/docs/Model/BroadcastResult.md @@ -28,7 +28,7 @@ Name | Type | Description | Notes **repetition_type** | **string** | | [optional] **repetition_end** | [**\DateTime**](\DateTime.md) | | [optional] **repetition_start** | [**\DateTime**](\DateTime.md) | | [optional] -**repetition_days** | **bool[]** | | [optional] +**repetition_days** | **string** | | [optional] **pty_code_id** | **int** | | [optional] **items** | [**\RadioManager\Model\BroadcastRelationsItems**](BroadcastRelationsItems.md) | | [optional] **blocks** | [**\RadioManager\Model\BroadcastRelationsBlocks**](BroadcastRelationsBlocks.md) | | [optional] diff --git a/docs/Model/StoryDataInput.md b/docs/Model/StoryDataInput.md index fcbb910..89eecdf 100644 --- a/docs/Model/StoryDataInput.md +++ b/docs/Model/StoryDataInput.md @@ -8,6 +8,7 @@ Name | Type | Description | Notes **field_values** | **object** | | [optional] **name** | **string** | | **description** | **string** | | [optional] +**tags** | **int[]** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/docs/Model/StoryInputOnly.md b/docs/Model/StoryInputOnly.md new file mode 100644 index 0000000..e75751b --- /dev/null +++ b/docs/Model/StoryInputOnly.md @@ -0,0 +1,10 @@ +# StoryInputOnly + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**tags** | **int[]** | | [optional] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/lib/Api/BlockApi.php b/lib/Api/BlockApi.php index 178c76c..3c570a7 100644 --- a/lib/Api/BlockApi.php +++ b/lib/Api/BlockApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * BlockApi Class Doc Comment @@ -44,47 +49,36 @@ class BlockApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return BlockApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -95,6 +89,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * @param int $id ID of Block **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\BlockResult */ public function getBlockById($id, $_external_station_id = null) @@ -111,263 +106,798 @@ public function getBlockById($id, $_external_station_id = null) * @param int $id ID of Block **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\BlockResult, HTTP status code, HTTP response headers (array of strings) */ public function getBlockByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\BlockResult'; + $request = $this->getBlockByIdRequest($id, $_external_station_id); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\BlockResult', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getBlockByIdAsync + * + * Get block by id + * + * @param int $id ID of Block **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getBlockByIdAsync($id, $_external_station_id = null) + { + return $this->getBlockByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getBlockByIdAsyncWithHttpInfo + * + * Get block by id + * + * @param int $id ID of Block **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getBlockByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\BlockResult'; + $request = $this->getBlockByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getBlockById' + * + * @param int $id ID of Block **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getBlockByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getBlockById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling BlockApi.getBlockById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/blocks/{id}"; - $httpBody = ''; + + $resourcePath = '/blocks/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getCurrentBlock + * + * Get current Block + * + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\BlockResult + */ + public function getCurrentBlock() + { + list($response) = $this->getCurrentBlockWithHttpInfo(); + return $response; + } + + /** + * Operation getCurrentBlockWithHttpInfo + * + * Get current Block + * + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\BlockResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getCurrentBlockWithHttpInfo() + { + $returnType = '\RadioManager\Model\BlockResult'; + $request = $this->getCurrentBlockRequest(); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\BlockResult', - '/blocks/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\BlockResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\BlockResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\BlockResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getCurrentBlock + * Operation getCurrentBlockAsync * * Get current Block * - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\BlockResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getCurrentBlock() + public function getCurrentBlockAsync() { - list($response) = $this->getCurrentBlockWithHttpInfo(); - return $response; + return $this->getCurrentBlockAsyncWithHttpInfo()->then(function ($response) { + return $response[0]; + }); } /** - * Operation getCurrentBlockWithHttpInfo + * Operation getCurrentBlockAsyncWithHttpInfo * * Get current Block * - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\BlockResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getCurrentBlockWithHttpInfo() + public function getCurrentBlockAsyncWithHttpInfo() { - // parse inputs - $resourcePath = "/blocks/current"; - $httpBody = ''; + $returnType = '\RadioManager\Model\BlockResult'; + $request = $this->getCurrentBlockRequest(); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getCurrentBlock' + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getCurrentBlockRequest() + { + + $resourcePath = '/blocks/current'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getNextBlock + * + * Get next Block + * + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\BlockResult + */ + public function getNextBlock() + { + list($response) = $this->getNextBlockWithHttpInfo(); + return $response; + } + + /** + * Operation getNextBlockWithHttpInfo + * + * Get next Block + * + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\BlockResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getNextBlockWithHttpInfo() + { + $returnType = '\RadioManager\Model\BlockResult'; + $request = $this->getNextBlockRequest(); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\BlockResult', - '/blocks/current' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\BlockResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\BlockResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\BlockResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getNextBlock + * Operation getNextBlockAsync * * Get next Block * - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\BlockResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getNextBlock() + public function getNextBlockAsync() { - list($response) = $this->getNextBlockWithHttpInfo(); - return $response; + return $this->getNextBlockAsyncWithHttpInfo()->then(function ($response) { + return $response[0]; + }); } /** - * Operation getNextBlockWithHttpInfo + * Operation getNextBlockAsyncWithHttpInfo * * Get next Block * - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\BlockResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getNextBlockWithHttpInfo() + public function getNextBlockAsyncWithHttpInfo() { - // parse inputs - $resourcePath = "/blocks/next"; - $httpBody = ''; + $returnType = '\RadioManager\Model\BlockResult'; + $request = $this->getNextBlockRequest(); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getNextBlock' + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getNextBlockRequest() + { + + $resourcePath = '/blocks/next'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listBlocks + * + * Get a list of all blocks currently in your station. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\BlockResults + */ + public function listBlocks($page = '1', $start_min = null, $start_max = null, $broadcast_id = null, $program_id = null, $item_id = null, $_external_station_id = null) + { + list($response) = $this->listBlocksWithHttpInfo($page, $start_min, $start_max, $broadcast_id, $program_id, $item_id, $_external_station_id); + return $response; + } + + /** + * Operation listBlocksWithHttpInfo + * + * Get a list of all blocks currently in your station. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\BlockResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listBlocksWithHttpInfo($page = '1', $start_min = null, $start_max = null, $broadcast_id = null, $program_id = null, $item_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\BlockResults'; + $request = $this->listBlocksRequest($page, $start_min, $start_max, $broadcast_id, $program_id, $item_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\BlockResult', - '/blocks/next' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\BlockResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\BlockResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\BlockResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listBlocks + * Operation listBlocksAsync * * Get a list of all blocks currently in your station. * @@ -378,17 +908,18 @@ public function getNextBlockWithHttpInfo() * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\BlockResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listBlocks($page = '1', $start_min = null, $start_max = null, $broadcast_id = null, $program_id = null, $item_id = null, $_external_station_id = null) + public function listBlocksAsync($page = '1', $start_min = null, $start_max = null, $broadcast_id = null, $program_id = null, $item_id = null, $_external_station_id = null) { - list($response) = $this->listBlocksWithHttpInfo($page, $start_min, $start_max, $broadcast_id, $program_id, $item_id, $_external_station_id); - return $response; + return $this->listBlocksAsyncWithHttpInfo($page, $start_min, $start_max, $broadcast_id, $program_id, $item_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listBlocksWithHttpInfo + * Operation listBlocksAsyncWithHttpInfo * * Get a list of all blocks currently in your station. * @@ -399,101 +930,160 @@ public function listBlocks($page = '1', $start_min = null, $start_max = null, $b * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\BlockResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listBlocksWithHttpInfo($page = '1', $start_min = null, $start_max = null, $broadcast_id = null, $program_id = null, $item_id = null, $_external_station_id = null) + public function listBlocksAsyncWithHttpInfo($page = '1', $start_min = null, $start_max = null, $broadcast_id = null, $program_id = null, $item_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + $returnType = '\RadioManager\Model\BlockResults'; + $request = $this->listBlocksRequest($page, $start_min, $start_max, $broadcast_id, $program_id, $item_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listBlocks' + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listBlocksRequest($page = '1', $start_min = null, $start_max = null, $broadcast_id = null, $program_id = null, $item_id = null, $_external_station_id = null) + { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling BlockApi.listBlocks, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/blocks"; - $httpBody = ''; + + $resourcePath = '/blocks'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($start_min !== null) { - $queryParams['start-min'] = $this->apiClient->getSerializer()->toQueryValue($start_min); + $queryParams['start-min'] = ObjectSerializer::toQueryValue($start_min); } // query params if ($start_max !== null) { - $queryParams['start-max'] = $this->apiClient->getSerializer()->toQueryValue($start_max); + $queryParams['start-max'] = ObjectSerializer::toQueryValue($start_max); } // query params if ($broadcast_id !== null) { - $queryParams['broadcast_id'] = $this->apiClient->getSerializer()->toQueryValue($broadcast_id); + $queryParams['broadcast_id'] = ObjectSerializer::toQueryValue($broadcast_id); } // query params if ($program_id !== null) { - $queryParams['program_id'] = $this->apiClient->getSerializer()->toQueryValue($program_id); + $queryParams['program_id'] = ObjectSerializer::toQueryValue($program_id); } // query params if ($item_id !== null) { - $queryParams['item_id'] = $this->apiClient->getSerializer()->toQueryValue($item_id); + $queryParams['item_id'] = ObjectSerializer::toQueryValue($item_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\BlockResults', - '/blocks' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\BlockResults', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\BlockResults', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/BroadcastApi.php b/lib/Api/BroadcastApi.php index 9a9ca25..971863a 100644 --- a/lib/Api/BroadcastApi.php +++ b/lib/Api/BroadcastApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * BroadcastApi Class Doc Comment @@ -44,47 +49,36 @@ class BroadcastApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return BroadcastApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\BroadcastDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\PostSuccess */ public function createBroadcast($data) @@ -109,388 +104,964 @@ public function createBroadcast($data) * * @param \RadioManager\Model\BroadcastDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\PostSuccess, HTTP status code, HTTP response headers (array of strings) */ public function createBroadcastWithHttpInfo($data) { - // verify the required parameter 'data' is set - if ($data === null) { - throw new \InvalidArgumentException('Missing the required parameter $data when calling createBroadcast'); - } - // parse inputs - $resourcePath = "/broadcasts"; - $httpBody = ''; - $queryParams = []; - $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); - - // body params - $_tempBody = null; - if (isset($data)) { - $_tempBody = $data; - } + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createBroadcastRequest($data); - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) - } - // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; - } - // make the API Call try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PostSuccess', - '/broadcasts' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PostSuccess', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation deleteBroadcastById + * Operation createBroadcastAsync * - * Delete broadcast by id + * Create broadcast. * - * @param int $id ID of Broadcast **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @param \RadioManager\Model\BroadcastDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteBroadcastById($id) + public function createBroadcastAsync($data) { - list($response) = $this->deleteBroadcastByIdWithHttpInfo($id); - return $response; + return $this->createBroadcastAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation deleteBroadcastByIdWithHttpInfo + * Operation createBroadcastAsyncWithHttpInfo * - * Delete broadcast by id + * Create broadcast. * - * @param int $id ID of Broadcast **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @param \RadioManager\Model\BroadcastDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteBroadcastByIdWithHttpInfo($id) + public function createBroadcastAsyncWithHttpInfo($data) { - // verify the required parameter 'id' is set - if ($id === null) { - throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteBroadcastById'); - } - if (($id < 0)) { - throw new \InvalidArgumentException('invalid value for "$id" when calling BroadcastApi.deleteBroadcastById, must be bigger than or equal to 0.'); + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createBroadcastRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'createBroadcast' + * + * @param \RadioManager\Model\BroadcastDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createBroadcastRequest($data) + { + // verify the required parameter 'data' is set + if ($data === null) { + throw new \InvalidArgumentException('Missing the required parameter $data when calling createBroadcast'); } - // parse inputs - $resourcePath = "/broadcasts/{id}"; - $httpBody = ''; + $resourcePath = '/broadcasts'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; + $httpBody = ''; + $multipart = false; + + + + // body params + $_tempBody = null; + if (isset($data)) { + $_tempBody = $data; } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); - // path params - if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation deleteBroadcastById + * + * Delete broadcast by id + * + * @param int $id ID of Broadcast **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function deleteBroadcastById($id) + { + list($response) = $this->deleteBroadcastByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation deleteBroadcastByIdWithHttpInfo + * + * Delete broadcast by id + * + * @param int $id ID of Broadcast **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteBroadcastByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteBroadcastByIdRequest($id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/broadcasts/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getBroadcastById + * Operation deleteBroadcastByIdAsync * - * Get broadcast by id + * Delete broadcast by id * * @param int $id ID of Broadcast **(Required)** (required) - * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\BroadcastResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getBroadcastById($id, $_external_station_id = null) + public function deleteBroadcastByIdAsync($id) { - list($response) = $this->getBroadcastByIdWithHttpInfo($id, $_external_station_id); - return $response; + return $this->deleteBroadcastByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getBroadcastByIdWithHttpInfo + * Operation deleteBroadcastByIdAsyncWithHttpInfo * - * Get broadcast by id + * Delete broadcast by id * * @param int $id ID of Broadcast **(Required)** (required) - * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\BroadcastResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getBroadcastByIdWithHttpInfo($id, $_external_station_id = null) + public function deleteBroadcastByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteBroadcastByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deleteBroadcastById' + * + * @param int $id ID of Broadcast **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteBroadcastByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { - throw new \InvalidArgumentException('Missing the required parameter $id when calling getBroadcastById'); + throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteBroadcastById'); } - if (($id < 0)) { - throw new \InvalidArgumentException('invalid value for "$id" when calling BroadcastApi.getBroadcastById, must be bigger than or equal to 0.'); + if ($id < 0) { + throw new \InvalidArgumentException('invalid value for "$id" when calling BroadcastApi.deleteBroadcastById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/broadcasts/{id}"; - $httpBody = ''; + + $resourcePath = '/broadcasts/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + - // query params - if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); - } // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\BroadcastResult', - '/broadcasts/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\BroadcastResult', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\BroadcastResult', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); } /** - * Operation getCurrentBroadcast + * Operation getBroadcastById * - * Get current Broadcast + * Get broadcast by id * + * @param int $id ID of Broadcast **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Broadcast + * @throws \InvalidArgumentException + * @return \RadioManager\Model\BroadcastResult */ - public function getCurrentBroadcast() + public function getBroadcastById($id, $_external_station_id = null) { - list($response) = $this->getCurrentBroadcastWithHttpInfo(); + list($response) = $this->getBroadcastByIdWithHttpInfo($id, $_external_station_id); return $response; } /** - * Operation getCurrentBroadcastWithHttpInfo + * Operation getBroadcastByIdWithHttpInfo * - * Get current Broadcast + * Get broadcast by id * + * @param int $id ID of Broadcast **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Broadcast, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\BroadcastResult, HTTP status code, HTTP response headers (array of strings) */ - public function getCurrentBroadcastWithHttpInfo() + public function getBroadcastByIdWithHttpInfo($id, $_external_station_id = null) { - // parse inputs - $resourcePath = "/broadcasts/current"; - $httpBody = ''; - $queryParams = []; - $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); - + $returnType = '\RadioManager\Model\BroadcastResult'; + $request = $this->getBroadcastByIdRequest($id, $_external_station_id); - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) - } - // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; - } - // make the API Call try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Broadcast', - '/broadcasts/current' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Broadcast', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Broadcast', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\BroadcastResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getDailyEPG + * Operation getBroadcastByIdAsync * - * Get daily EPG + * Get broadcast by id * - * @param \DateTime $date Date *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response + * @param int $id ID of Broadcast **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getBroadcastByIdAsync($id, $_external_station_id = null) + { + return $this->getBroadcastByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getBroadcastByIdAsyncWithHttpInfo + * + * Get broadcast by id + * + * @param int $id ID of Broadcast **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getBroadcastByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\BroadcastResult'; + $request = $this->getBroadcastByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getBroadcastById' + * + * @param int $id ID of Broadcast **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getBroadcastByIdRequest($id, $_external_station_id = null) + { + // verify the required parameter 'id' is set + if ($id === null) { + throw new \InvalidArgumentException('Missing the required parameter $id when calling getBroadcastById'); + } + if ($id < 0) { + throw new \InvalidArgumentException('invalid value for "$id" when calling BroadcastApi.getBroadcastById, must be bigger than or equal to 0.'); + } + + + $resourcePath = '/broadcasts/{id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($_external_station_id !== null) { + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + // path params + if ($id !== null) { + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getCurrentBroadcast + * + * Get current Broadcast + * + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Broadcast + */ + public function getCurrentBroadcast() + { + list($response) = $this->getCurrentBroadcastWithHttpInfo(); + return $response; + } + + /** + * Operation getCurrentBroadcastWithHttpInfo + * + * Get current Broadcast + * + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Broadcast, HTTP status code, HTTP response headers (array of strings) + */ + public function getCurrentBroadcastWithHttpInfo() + { + $returnType = '\RadioManager\Model\Broadcast'; + $request = $this->getCurrentBroadcastRequest(); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Broadcast', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getCurrentBroadcastAsync + * + * Get current Broadcast + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCurrentBroadcastAsync() + { + return $this->getCurrentBroadcastAsyncWithHttpInfo()->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getCurrentBroadcastAsyncWithHttpInfo + * + * Get current Broadcast + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCurrentBroadcastAsyncWithHttpInfo() + { + $returnType = '\RadioManager\Model\Broadcast'; + $request = $this->getCurrentBroadcastRequest(); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getCurrentBroadcast' + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getCurrentBroadcastRequest() + { + + $resourcePath = '/broadcasts/current'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getDailyEPG + * + * Get daily EPG + * + * @param \DateTime $date Date *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\EPGBroadcast */ public function getDailyEPG($date = null) @@ -506,340 +1077,1033 @@ public function getDailyEPG($date = null) * * @param \DateTime $date Date *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\EPGBroadcast, HTTP status code, HTTP response headers (array of strings) */ public function getDailyEPGWithHttpInfo($date = null) { - // parse inputs - $resourcePath = "/broadcasts/epg/daily"; - $httpBody = ''; + $returnType = '\RadioManager\Model\EPGBroadcast'; + $request = $this->getDailyEPGRequest($date); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\EPGBroadcast', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getDailyEPGAsync + * + * Get daily EPG + * + * @param \DateTime $date Date *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getDailyEPGAsync($date = null) + { + return $this->getDailyEPGAsyncWithHttpInfo($date)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getDailyEPGAsyncWithHttpInfo + * + * Get daily EPG + * + * @param \DateTime $date Date *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getDailyEPGAsyncWithHttpInfo($date = null) + { + $returnType = '\RadioManager\Model\EPGBroadcast'; + $request = $this->getDailyEPGRequest($date); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getDailyEPG' + * + * @param \DateTime $date Date *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getDailyEPGRequest($date = null) + { + + $resourcePath = '/broadcasts/epg/daily'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($date !== null) { - $queryParams['date'] = $this->apiClient->getSerializer()->toQueryValue($date); + $queryParams['date'] = ObjectSerializer::toQueryValue($date); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getEPGByDate + * + * Get EPG by date + * + * @param \DateTime $date Date *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\EPGBroadcast + */ + public function getEPGByDate($date = null) + { + list($response) = $this->getEPGByDateWithHttpInfo($date); + return $response; + } + + /** + * Operation getEPGByDateWithHttpInfo + * + * Get EPG by date + * + * @param \DateTime $date Date *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\EPGBroadcast, HTTP status code, HTTP response headers (array of strings) + */ + public function getEPGByDateWithHttpInfo($date = null) + { + $returnType = '\RadioManager\Model\EPGBroadcast'; + $request = $this->getEPGByDateRequest($date); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\EPGBroadcast', - '/broadcasts/epg/daily' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\EPGBroadcast', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\EPGBroadcast', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\EPGBroadcast', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getEPGByDate + * Operation getEPGByDateAsync * * Get EPG by date * * @param \DateTime $date Date *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\EPGBroadcast + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getEPGByDate($date = null) + public function getEPGByDateAsync($date = null) { - list($response) = $this->getEPGByDateWithHttpInfo($date); - return $response; + return $this->getEPGByDateAsyncWithHttpInfo($date)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getEPGByDateWithHttpInfo + * Operation getEPGByDateAsyncWithHttpInfo * * Get EPG by date * * @param \DateTime $date Date *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\EPGBroadcast, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getEPGByDateWithHttpInfo($date = null) + public function getEPGByDateAsyncWithHttpInfo($date = null) { - // parse inputs - $resourcePath = "/broadcasts/epg"; - $httpBody = ''; + $returnType = '\RadioManager\Model\EPGBroadcast'; + $request = $this->getEPGByDateRequest($date); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getEPGByDate' + * + * @param \DateTime $date Date *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getEPGByDateRequest($date = null) + { + + $resourcePath = '/broadcasts/epg'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($date !== null) { - $queryParams['date'] = $this->apiClient->getSerializer()->toQueryValue($date); + $queryParams['date'] = ObjectSerializer::toQueryValue($date); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getNextBroadcast + * + * Get next Broadcast + * + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Broadcast + */ + public function getNextBroadcast() + { + list($response) = $this->getNextBroadcastWithHttpInfo(); + return $response; + } + + /** + * Operation getNextBroadcastWithHttpInfo + * + * Get next Broadcast + * + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Broadcast, HTTP status code, HTTP response headers (array of strings) + */ + public function getNextBroadcastWithHttpInfo() + { + $returnType = '\RadioManager\Model\Broadcast'; + $request = $this->getNextBroadcastRequest(); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\EPGBroadcast', - '/broadcasts/epg' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\EPGBroadcast', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\EPGBroadcast', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Broadcast', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getNextBroadcast + * Operation getNextBroadcastAsync * * Get next Broadcast * - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Broadcast + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getNextBroadcast() + public function getNextBroadcastAsync() { - list($response) = $this->getNextBroadcastWithHttpInfo(); - return $response; + return $this->getNextBroadcastAsyncWithHttpInfo()->then(function ($response) { + return $response[0]; + }); } /** - * Operation getNextBroadcastWithHttpInfo + * Operation getNextBroadcastAsyncWithHttpInfo * * Get next Broadcast * - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Broadcast, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getNextBroadcastWithHttpInfo() + public function getNextBroadcastAsyncWithHttpInfo() { - // parse inputs - $resourcePath = "/broadcasts/next"; - $httpBody = ''; + $returnType = '\RadioManager\Model\Broadcast'; + $request = $this->getNextBroadcastRequest(); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getNextBroadcast' + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getNextBroadcastRequest() + { + + $resourcePath = '/broadcasts/next'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getWeeklyEPG + * + * Get weekly EPG + * + * @param string $date Date *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\EPGBroadcast + */ + public function getWeeklyEPG($date = null) + { + list($response) = $this->getWeeklyEPGWithHttpInfo($date); + return $response; + } + + /** + * Operation getWeeklyEPGWithHttpInfo + * + * Get weekly EPG + * + * @param string $date Date *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\EPGBroadcast, HTTP status code, HTTP response headers (array of strings) + */ + public function getWeeklyEPGWithHttpInfo($date = null) + { + $returnType = '\RadioManager\Model\EPGBroadcast'; + $request = $this->getWeeklyEPGRequest($date); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Broadcast', - '/broadcasts/next' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Broadcast', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Broadcast', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\EPGBroadcast', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getWeeklyEPG + * Operation getWeeklyEPGAsync * * Get weekly EPG * * @param string $date Date *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\EPGBroadcast + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getWeeklyEPG($date = null) + public function getWeeklyEPGAsync($date = null) { - list($response) = $this->getWeeklyEPGWithHttpInfo($date); - return $response; + return $this->getWeeklyEPGAsyncWithHttpInfo($date)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getWeeklyEPGWithHttpInfo + * Operation getWeeklyEPGAsyncWithHttpInfo * * Get weekly EPG * * @param string $date Date *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\EPGBroadcast, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getWeeklyEPGWithHttpInfo($date = null) + public function getWeeklyEPGAsyncWithHttpInfo($date = null) { - // parse inputs - $resourcePath = "/broadcasts/epg/weekly"; - $httpBody = ''; + $returnType = '\RadioManager\Model\EPGBroadcast'; + $request = $this->getWeeklyEPGRequest($date); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getWeeklyEPG' + * + * @param string $date Date *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getWeeklyEPGRequest($date = null) + { + + $resourcePath = '/broadcasts/epg/weekly'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($date !== null) { - $queryParams['date'] = $this->apiClient->getSerializer()->toQueryValue($date); + $queryParams['date'] = ObjectSerializer::toQueryValue($date); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listBroadcasts + * + * Get all broadcasts. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $genre_id Search on Genre ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\BroadcastResults + */ + public function listBroadcasts($page = '1', $start_min = null, $start_max = null, $model_type_id = null, $tag_id = null, $presenter_id = null, $item_id = null, $block_id = null, $genre_id = null, $program_id = null, $_external_station_id = null) + { + list($response) = $this->listBroadcastsWithHttpInfo($page, $start_min, $start_max, $model_type_id, $tag_id, $presenter_id, $item_id, $block_id, $genre_id, $program_id, $_external_station_id); + return $response; + } + + /** + * Operation listBroadcastsWithHttpInfo + * + * Get all broadcasts. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $genre_id Search on Genre ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\BroadcastResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listBroadcastsWithHttpInfo($page = '1', $start_min = null, $start_max = null, $model_type_id = null, $tag_id = null, $presenter_id = null, $item_id = null, $block_id = null, $genre_id = null, $program_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\BroadcastResults'; + $request = $this->listBroadcastsRequest($page, $start_min, $start_max, $model_type_id, $tag_id, $presenter_id, $item_id, $block_id, $genre_id, $program_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\EPGBroadcast', - '/broadcasts/epg/weekly' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\EPGBroadcast', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\EPGBroadcast', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\BroadcastResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listBroadcasts + * Operation listBroadcastsAsync * * Get all broadcasts. * @@ -854,17 +2118,18 @@ public function getWeeklyEPGWithHttpInfo($date = null) * @param int $genre_id Search on Genre ID *(Optional)* `(Relation)` (optional) * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\BroadcastResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listBroadcasts($page = '1', $start_min = null, $start_max = null, $model_type_id = null, $tag_id = null, $presenter_id = null, $item_id = null, $block_id = null, $genre_id = null, $program_id = null, $_external_station_id = null) + public function listBroadcastsAsync($page = '1', $start_min = null, $start_max = null, $model_type_id = null, $tag_id = null, $presenter_id = null, $item_id = null, $block_id = null, $genre_id = null, $program_id = null, $_external_station_id = null) { - list($response) = $this->listBroadcastsWithHttpInfo($page, $start_min, $start_max, $model_type_id, $tag_id, $presenter_id, $item_id, $block_id, $genre_id, $program_id, $_external_station_id); - return $response; + return $this->listBroadcastsAsyncWithHttpInfo($page, $start_min, $start_max, $model_type_id, $tag_id, $presenter_id, $item_id, $block_id, $genre_id, $program_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listBroadcastsWithHttpInfo + * Operation listBroadcastsAsyncWithHttpInfo * * Get all broadcasts. * @@ -879,122 +2144,283 @@ public function listBroadcasts($page = '1', $start_min = null, $start_max = null * @param int $genre_id Search on Genre ID *(Optional)* `(Relation)` (optional) * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\BroadcastResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listBroadcastsWithHttpInfo($page = '1', $start_min = null, $start_max = null, $model_type_id = null, $tag_id = null, $presenter_id = null, $item_id = null, $block_id = null, $genre_id = null, $program_id = null, $_external_station_id = null) + public function listBroadcastsAsyncWithHttpInfo($page = '1', $start_min = null, $start_max = null, $model_type_id = null, $tag_id = null, $presenter_id = null, $item_id = null, $block_id = null, $genre_id = null, $program_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\BroadcastResults'; + $request = $this->listBroadcastsRequest($page, $start_min, $start_max, $model_type_id, $tag_id, $presenter_id, $item_id, $block_id, $genre_id, $program_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listBroadcasts' + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $genre_id Search on Genre ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listBroadcastsRequest($page = '1', $start_min = null, $start_max = null, $model_type_id = null, $tag_id = null, $presenter_id = null, $item_id = null, $block_id = null, $genre_id = null, $program_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling BroadcastApi.listBroadcasts, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/broadcasts"; - $httpBody = ''; + + $resourcePath = '/broadcasts'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($start_min !== null) { - $queryParams['start-min'] = $this->apiClient->getSerializer()->toQueryValue($start_min); + $queryParams['start-min'] = ObjectSerializer::toQueryValue($start_min); } // query params if ($start_max !== null) { - $queryParams['start-max'] = $this->apiClient->getSerializer()->toQueryValue($start_max); + $queryParams['start-max'] = ObjectSerializer::toQueryValue($start_max); } // query params if ($model_type_id !== null) { - $queryParams['model_type_id'] = $this->apiClient->getSerializer()->toQueryValue($model_type_id); + $queryParams['model_type_id'] = ObjectSerializer::toQueryValue($model_type_id); } // query params if ($tag_id !== null) { - $queryParams['tag_id'] = $this->apiClient->getSerializer()->toQueryValue($tag_id); + $queryParams['tag_id'] = ObjectSerializer::toQueryValue($tag_id); } // query params if ($presenter_id !== null) { - $queryParams['presenter_id'] = $this->apiClient->getSerializer()->toQueryValue($presenter_id); + $queryParams['presenter_id'] = ObjectSerializer::toQueryValue($presenter_id); } // query params if ($item_id !== null) { - $queryParams['item_id'] = $this->apiClient->getSerializer()->toQueryValue($item_id); + $queryParams['item_id'] = ObjectSerializer::toQueryValue($item_id); } // query params if ($block_id !== null) { - $queryParams['block_id'] = $this->apiClient->getSerializer()->toQueryValue($block_id); + $queryParams['block_id'] = ObjectSerializer::toQueryValue($block_id); } // query params if ($genre_id !== null) { - $queryParams['genre_id'] = $this->apiClient->getSerializer()->toQueryValue($genre_id); + $queryParams['genre_id'] = ObjectSerializer::toQueryValue($genre_id); } // query params if ($program_id !== null) { - $queryParams['program_id'] = $this->apiClient->getSerializer()->toQueryValue($program_id); + $queryParams['program_id'] = ObjectSerializer::toQueryValue($program_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation printBroadcastById + * + * Print Broadcast by id + * + * @param int $id ID of Broadcast **(Required)** (required) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\EPGBroadcast + */ + public function printBroadcastById($id, $program_id = null, $presenter_id = null, $tag_id = null) + { + list($response) = $this->printBroadcastByIdWithHttpInfo($id, $program_id, $presenter_id, $tag_id); + return $response; + } + + /** + * Operation printBroadcastByIdWithHttpInfo + * + * Print Broadcast by id + * + * @param int $id ID of Broadcast **(Required)** (required) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\EPGBroadcast, HTTP status code, HTTP response headers (array of strings) + */ + public function printBroadcastByIdWithHttpInfo($id, $program_id = null, $presenter_id = null, $tag_id = null) + { + $returnType = '\RadioManager\Model\EPGBroadcast'; + $request = $this->printBroadcastByIdRequest($id, $program_id, $presenter_id, $tag_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\BroadcastResults', - '/broadcasts' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\BroadcastResults', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\BroadcastResults', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\EPGBroadcast', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation printBroadcastById + * Operation printBroadcastByIdAsync * * Print Broadcast by id * @@ -1002,17 +2428,18 @@ public function listBroadcastsWithHttpInfo($page = '1', $start_min = null, $star * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\EPGBroadcast + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function printBroadcastById($id, $program_id = null, $presenter_id = null, $tag_id = null) + public function printBroadcastByIdAsync($id, $program_id = null, $presenter_id = null, $tag_id = null) { - list($response) = $this->printBroadcastByIdWithHttpInfo($id, $program_id, $presenter_id, $tag_id); - return $response; + return $this->printBroadcastByIdAsyncWithHttpInfo($id, $program_id, $presenter_id, $tag_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation printBroadcastByIdWithHttpInfo + * Operation printBroadcastByIdAsyncWithHttpInfo * * Print Broadcast by id * @@ -1020,211 +2447,408 @@ public function printBroadcastById($id, $program_id = null, $presenter_id = null * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\EPGBroadcast, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function printBroadcastByIdWithHttpInfo($id, $program_id = null, $presenter_id = null, $tag_id = null) + public function printBroadcastByIdAsyncWithHttpInfo($id, $program_id = null, $presenter_id = null, $tag_id = null) + { + $returnType = '\RadioManager\Model\EPGBroadcast'; + $request = $this->printBroadcastByIdRequest($id, $program_id, $presenter_id, $tag_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'printBroadcastById' + * + * @param int $id ID of Broadcast **(Required)** (required) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function printBroadcastByIdRequest($id, $program_id = null, $presenter_id = null, $tag_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling printBroadcastById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling BroadcastApi.printBroadcastById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/broadcasts/print/{id}"; - $httpBody = ''; + + $resourcePath = '/broadcasts/print/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($program_id !== null) { - $queryParams['program_id'] = $this->apiClient->getSerializer()->toQueryValue($program_id); + $queryParams['program_id'] = ObjectSerializer::toQueryValue($program_id); } // query params if ($presenter_id !== null) { - $queryParams['presenter_id'] = $this->apiClient->getSerializer()->toQueryValue($presenter_id); + $queryParams['presenter_id'] = ObjectSerializer::toQueryValue($presenter_id); } // query params if ($tag_id !== null) { - $queryParams['tag_id'] = $this->apiClient->getSerializer()->toQueryValue($tag_id); + $queryParams['tag_id'] = ObjectSerializer::toQueryValue($tag_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation updateBroadcastByID + * + * Update broadcast by id + * + * @param int $id ID of Broadcast **(Required)** (required) + * @param \RadioManager\Model\BroadcastDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function updateBroadcastByID($id, $data = null) + { + list($response) = $this->updateBroadcastByIDWithHttpInfo($id, $data); + return $response; + } + + /** + * Operation updateBroadcastByIDWithHttpInfo + * + * Update broadcast by id + * + * @param int $id ID of Broadcast **(Required)** (required) + * @param \RadioManager\Model\BroadcastDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function updateBroadcastByIDWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateBroadcastByIDRequest($id, $data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\EPGBroadcast', - '/broadcasts/print/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\EPGBroadcast', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\EPGBroadcast', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation updateBroadcastByID + * Operation updateBroadcastByIDAsync * * Update broadcast by id * * @param int $id ID of Broadcast **(Required)** (required) * @param \RadioManager\Model\BroadcastDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateBroadcastByID($id, $data = null) + public function updateBroadcastByIDAsync($id, $data = null) { - list($response) = $this->updateBroadcastByIDWithHttpInfo($id, $data); - return $response; + return $this->updateBroadcastByIDAsyncWithHttpInfo($id, $data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation updateBroadcastByIDWithHttpInfo + * Operation updateBroadcastByIDAsyncWithHttpInfo * * Update broadcast by id * * @param int $id ID of Broadcast **(Required)** (required) * @param \RadioManager\Model\BroadcastDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateBroadcastByIDWithHttpInfo($id, $data = null) + public function updateBroadcastByIDAsyncWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateBroadcastByIDRequest($id, $data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'updateBroadcastByID' + * + * @param int $id ID of Broadcast **(Required)** (required) + * @param \RadioManager\Model\BroadcastDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updateBroadcastByIDRequest($id, $data = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling updateBroadcastByID'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling BroadcastApi.updateBroadcastByID, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/broadcasts/{id}"; - $httpBody = ''; + + $resourcePath = '/broadcasts/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); } + // body params $_tempBody = null; if (isset($data)) { $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'PATCH', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/broadcasts/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'PATCH', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/CampaignApi.php b/lib/Api/CampaignApi.php index d56cf9c..7221c5d 100644 --- a/lib/Api/CampaignApi.php +++ b/lib/Api/CampaignApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * CampaignApi Class Doc Comment @@ -44,47 +49,36 @@ class CampaignApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return CampaignApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\CampaignDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\PostSuccess */ public function createCampaign($data) @@ -109,25 +104,160 @@ public function createCampaign($data) * * @param \RadioManager\Model\CampaignDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\PostSuccess, HTTP status code, HTTP response headers (array of strings) */ public function createCampaignWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createCampaignRequest($data); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createCampaignAsync + * + * Create campaign. + * + * @param \RadioManager\Model\CampaignDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createCampaignAsync($data) + { + return $this->createCampaignAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createCampaignAsyncWithHttpInfo + * + * Create campaign. + * + * @param \RadioManager\Model\CampaignDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createCampaignAsyncWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createCampaignRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'createCampaign' + * + * @param \RadioManager\Model\CampaignDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createCampaignRequest($data) { // verify the required parameter 'data' is set if ($data === null) { throw new \InvalidArgumentException('Missing the required parameter $data when calling createCampaign'); } - // parse inputs - $resourcePath = "/campaigns"; - $httpBody = ''; + + $resourcePath = '/campaigns'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -135,272 +265,672 @@ public function createCampaignWithHttpInfo($data) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation deleteCampaignById + * + * Delete campaign by id + * + * @param int $id ID of Campaign **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function deleteCampaignById($id) + { + list($response) = $this->deleteCampaignByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation deleteCampaignByIdWithHttpInfo + * + * Delete campaign by id + * + * @param int $id ID of Campaign **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteCampaignByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteCampaignByIdRequest($id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PostSuccess', - '/campaigns' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PostSuccess', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation deleteCampaignById + * Operation deleteCampaignByIdAsync * * Delete campaign by id * * @param int $id ID of Campaign **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteCampaignById($id) + public function deleteCampaignByIdAsync($id) { - list($response) = $this->deleteCampaignByIdWithHttpInfo($id); - return $response; + return $this->deleteCampaignByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation deleteCampaignByIdWithHttpInfo + * Operation deleteCampaignByIdAsyncWithHttpInfo * * Delete campaign by id * * @param int $id ID of Campaign **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteCampaignByIdWithHttpInfo($id) + public function deleteCampaignByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteCampaignByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deleteCampaignById' + * + * @param int $id ID of Campaign **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteCampaignByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteCampaignById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling CampaignApi.deleteCampaignById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/campaigns/{id}"; - $httpBody = ''; + + $resourcePath = '/campaigns/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getCampaignById + * + * Get campaign by id + * + * @param int $id ID of Campaign **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\CampaignResult + */ + public function getCampaignById($id, $_external_station_id = null) + { + list($response) = $this->getCampaignByIdWithHttpInfo($id, $_external_station_id); + return $response; + } + + /** + * Operation getCampaignByIdWithHttpInfo + * + * Get campaign by id + * + * @param int $id ID of Campaign **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\CampaignResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getCampaignByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\CampaignResult'; + $request = $this->getCampaignByIdRequest($id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/campaigns/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\CampaignResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getCampaignById + * Operation getCampaignByIdAsync * * Get campaign by id * * @param int $id ID of Campaign **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\CampaignResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getCampaignById($id, $_external_station_id = null) + public function getCampaignByIdAsync($id, $_external_station_id = null) { - list($response) = $this->getCampaignByIdWithHttpInfo($id, $_external_station_id); - return $response; + return $this->getCampaignByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getCampaignByIdWithHttpInfo + * Operation getCampaignByIdAsyncWithHttpInfo * * Get campaign by id * * @param int $id ID of Campaign **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\CampaignResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getCampaignByIdWithHttpInfo($id, $_external_station_id = null) + public function getCampaignByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\CampaignResult'; + $request = $this->getCampaignByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getCampaignById' + * + * @param int $id ID of Campaign **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getCampaignByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getCampaignById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling CampaignApi.getCampaignById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/campaigns/{id}"; - $httpBody = ''; + + $resourcePath = '/campaigns/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listCampaigns + * + * Get all campaigns. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\CampaignResults + */ + public function listCampaigns($page = null, $model_type_id = null, $item_id = null, $start_min = null, $start_max = null, $_external_station_id = null) + { + list($response) = $this->listCampaignsWithHttpInfo($page, $model_type_id, $item_id, $start_min, $start_max, $_external_station_id); + return $response; + } + + /** + * Operation listCampaignsWithHttpInfo + * + * Get all campaigns. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\CampaignResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listCampaignsWithHttpInfo($page = null, $model_type_id = null, $item_id = null, $start_min = null, $start_max = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\CampaignResults'; + $request = $this->listCampaignsRequest($page, $model_type_id, $item_id, $start_min, $start_max, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\CampaignResult', - '/campaigns/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\CampaignResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\CampaignResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\CampaignResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listCampaigns + * Operation listCampaignsAsync * * Get all campaigns. * @@ -410,17 +940,18 @@ public function getCampaignByIdWithHttpInfo($id, $_external_station_id = null) * @param \DateTime $start_min Minimum start date *(Optional)* (optional) * @param \DateTime $start_max Maximum start date *(Optional)* (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\CampaignResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listCampaigns($page = null, $model_type_id = null, $item_id = null, $start_min = null, $start_max = null, $_external_station_id = null) + public function listCampaignsAsync($page = null, $model_type_id = null, $item_id = null, $start_min = null, $start_max = null, $_external_station_id = null) { - list($response) = $this->listCampaignsWithHttpInfo($page, $model_type_id, $item_id, $start_min, $start_max, $_external_station_id); - return $response; + return $this->listCampaignsAsyncWithHttpInfo($page, $model_type_id, $item_id, $start_min, $start_max, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listCampaignsWithHttpInfo + * Operation listCampaignsAsyncWithHttpInfo * * Get all campaigns. * @@ -430,211 +961,414 @@ public function listCampaigns($page = null, $model_type_id = null, $item_id = nu * @param \DateTime $start_min Minimum start date *(Optional)* (optional) * @param \DateTime $start_max Maximum start date *(Optional)* (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\CampaignResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listCampaignsWithHttpInfo($page = null, $model_type_id = null, $item_id = null, $start_min = null, $start_max = null, $_external_station_id = null) + public function listCampaignsAsyncWithHttpInfo($page = null, $model_type_id = null, $item_id = null, $start_min = null, $start_max = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\CampaignResults'; + $request = $this->listCampaignsRequest($page, $model_type_id, $item_id, $start_min, $start_max, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listCampaigns' + * + * @param int $page Current page *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listCampaignsRequest($page = null, $model_type_id = null, $item_id = null, $start_min = null, $start_max = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling CampaignApi.listCampaigns, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/campaigns"; - $httpBody = ''; + + $resourcePath = '/campaigns'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($model_type_id !== null) { - $queryParams['model_type_id'] = $this->apiClient->getSerializer()->toQueryValue($model_type_id); + $queryParams['model_type_id'] = ObjectSerializer::toQueryValue($model_type_id); } // query params if ($item_id !== null) { - $queryParams['item_id'] = $this->apiClient->getSerializer()->toQueryValue($item_id); + $queryParams['item_id'] = ObjectSerializer::toQueryValue($item_id); } // query params if ($start_min !== null) { - $queryParams['start-min'] = $this->apiClient->getSerializer()->toQueryValue($start_min); + $queryParams['start-min'] = ObjectSerializer::toQueryValue($start_min); } // query params if ($start_max !== null) { - $queryParams['start-max'] = $this->apiClient->getSerializer()->toQueryValue($start_max); + $queryParams['start-max'] = ObjectSerializer::toQueryValue($start_max); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation updateCampaignByID + * + * Update campaign by id + * + * @param int $id ID of Campaign **(Required)** (required) + * @param \RadioManager\Model\CampaignDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function updateCampaignByID($id, $data = null) + { + list($response) = $this->updateCampaignByIDWithHttpInfo($id, $data); + return $response; + } + + /** + * Operation updateCampaignByIDWithHttpInfo + * + * Update campaign by id + * + * @param int $id ID of Campaign **(Required)** (required) + * @param \RadioManager\Model\CampaignDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function updateCampaignByIDWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateCampaignByIDRequest($id, $data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\CampaignResults', - '/campaigns' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\CampaignResults', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\CampaignResults', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation updateCampaignByID + * Operation updateCampaignByIDAsync * * Update campaign by id * * @param int $id ID of Campaign **(Required)** (required) * @param \RadioManager\Model\CampaignDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateCampaignByID($id, $data = null) + public function updateCampaignByIDAsync($id, $data = null) { - list($response) = $this->updateCampaignByIDWithHttpInfo($id, $data); - return $response; + return $this->updateCampaignByIDAsyncWithHttpInfo($id, $data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation updateCampaignByIDWithHttpInfo + * Operation updateCampaignByIDAsyncWithHttpInfo * * Update campaign by id * * @param int $id ID of Campaign **(Required)** (required) * @param \RadioManager\Model\CampaignDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateCampaignByIDWithHttpInfo($id, $data = null) + public function updateCampaignByIDAsyncWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateCampaignByIDRequest($id, $data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'updateCampaignByID' + * + * @param int $id ID of Campaign **(Required)** (required) + * @param \RadioManager\Model\CampaignDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updateCampaignByIDRequest($id, $data = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling updateCampaignByID'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling CampaignApi.updateCampaignByID, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/campaigns/{id}"; - $httpBody = ''; + + $resourcePath = '/campaigns/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); } + // body params $_tempBody = null; if (isset($data)) { $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'PATCH', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/campaigns/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'PATCH', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/ContactApi.php b/lib/Api/ContactApi.php index a05dd2d..83ef6fe 100644 --- a/lib/Api/ContactApi.php +++ b/lib/Api/ContactApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * ContactApi Class Doc Comment @@ -44,47 +49,36 @@ class ContactApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return ContactApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\ContactDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\PostSuccess */ public function createContact($data) @@ -109,25 +104,160 @@ public function createContact($data) * * @param \RadioManager\Model\ContactDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\PostSuccess, HTTP status code, HTTP response headers (array of strings) */ public function createContactWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createContactRequest($data); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createContactAsync + * + * Create contact. + * + * @param \RadioManager\Model\ContactDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createContactAsync($data) + { + return $this->createContactAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createContactAsyncWithHttpInfo + * + * Create contact. + * + * @param \RadioManager\Model\ContactDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createContactAsyncWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createContactRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'createContact' + * + * @param \RadioManager\Model\ContactDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createContactRequest($data) { // verify the required parameter 'data' is set if ($data === null) { throw new \InvalidArgumentException('Missing the required parameter $data when calling createContact'); } - // parse inputs - $resourcePath = "/contacts"; - $httpBody = ''; + + $resourcePath = '/contacts'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -135,272 +265,670 @@ public function createContactWithHttpInfo($data) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation deleteContactById + * + * Delete contact by id + * + * @param int $id ID of Contact **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function deleteContactById($id) + { + list($response) = $this->deleteContactByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation deleteContactByIdWithHttpInfo + * + * Delete contact by id + * + * @param int $id ID of Contact **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteContactByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteContactByIdRequest($id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PostSuccess', - '/contacts' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PostSuccess', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation deleteContactById + * Operation deleteContactByIdAsync * * Delete contact by id * * @param int $id ID of Contact **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteContactById($id) + public function deleteContactByIdAsync($id) { - list($response) = $this->deleteContactByIdWithHttpInfo($id); - return $response; + return $this->deleteContactByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation deleteContactByIdWithHttpInfo + * Operation deleteContactByIdAsyncWithHttpInfo * * Delete contact by id * * @param int $id ID of Contact **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteContactByIdWithHttpInfo($id) + public function deleteContactByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteContactByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deleteContactById' + * + * @param int $id ID of Contact **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteContactByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteContactById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling ContactApi.deleteContactById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/contacts/{id}"; - $httpBody = ''; + + $resourcePath = '/contacts/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getContactById + * + * Get contact by id + * + * @param int $id ID of Contact **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\ContactResult + */ + public function getContactById($id, $_external_station_id = null) + { + list($response) = $this->getContactByIdWithHttpInfo($id, $_external_station_id); + return $response; + } + + /** + * Operation getContactByIdWithHttpInfo + * + * Get contact by id + * + * @param int $id ID of Contact **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\ContactResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getContactByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ContactResult'; + $request = $this->getContactByIdRequest($id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/contacts/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\ContactResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getContactById + * Operation getContactByIdAsync * * Get contact by id * * @param int $id ID of Contact **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\ContactResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getContactById($id, $_external_station_id = null) + public function getContactByIdAsync($id, $_external_station_id = null) { - list($response) = $this->getContactByIdWithHttpInfo($id, $_external_station_id); - return $response; + return $this->getContactByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getContactByIdWithHttpInfo + * Operation getContactByIdAsyncWithHttpInfo * * Get contact by id * * @param int $id ID of Contact **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\ContactResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getContactByIdWithHttpInfo($id, $_external_station_id = null) + public function getContactByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ContactResult'; + $request = $this->getContactByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getContactById' + * + * @param int $id ID of Contact **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getContactByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getContactById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling ContactApi.getContactById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/contacts/{id}"; - $httpBody = ''; + + $resourcePath = '/contacts/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listContacts + * + * Get all contacts. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\ContactResults + */ + public function listContacts($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + { + list($response) = $this->listContactsWithHttpInfo($page, $model_type_id, $tag_id, $item_id, $_external_station_id); + return $response; + } + + /** + * Operation listContactsWithHttpInfo + * + * Get all contacts. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\ContactResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listContactsWithHttpInfo($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ContactResults'; + $request = $this->listContactsRequest($page, $model_type_id, $tag_id, $item_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\ContactResult', - '/contacts/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\ContactResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\ContactResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\ContactResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listContacts + * Operation listContactsAsync * * Get all contacts. * @@ -409,17 +937,18 @@ public function getContactByIdWithHttpInfo($id, $_external_station_id = null) * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\ContactResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listContacts($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + public function listContactsAsync($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) { - list($response) = $this->listContactsWithHttpInfo($page, $model_type_id, $tag_id, $item_id, $_external_station_id); - return $response; + return $this->listContactsAsyncWithHttpInfo($page, $model_type_id, $tag_id, $item_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listContactsWithHttpInfo + * Operation listContactsAsyncWithHttpInfo * * Get all contacts. * @@ -428,207 +957,409 @@ public function listContacts($page = '1', $model_type_id = null, $tag_id = null, * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\ContactResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listContactsWithHttpInfo($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + public function listContactsAsyncWithHttpInfo($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ContactResults'; + $request = $this->listContactsRequest($page, $model_type_id, $tag_id, $item_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listContacts' + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listContactsRequest($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling ContactApi.listContacts, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/contacts"; - $httpBody = ''; + + $resourcePath = '/contacts'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($model_type_id !== null) { - $queryParams['model_type_id'] = $this->apiClient->getSerializer()->toQueryValue($model_type_id); + $queryParams['model_type_id'] = ObjectSerializer::toQueryValue($model_type_id); } // query params if ($tag_id !== null) { - $queryParams['tag_id'] = $this->apiClient->getSerializer()->toQueryValue($tag_id); + $queryParams['tag_id'] = ObjectSerializer::toQueryValue($tag_id); } // query params if ($item_id !== null) { - $queryParams['item_id'] = $this->apiClient->getSerializer()->toQueryValue($item_id); + $queryParams['item_id'] = ObjectSerializer::toQueryValue($item_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation updateContactByID + * + * Update contact by id + * + * @param int $id ID of Contact **(Required)** (required) + * @param \RadioManager\Model\ContactDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function updateContactByID($id, $data = null) + { + list($response) = $this->updateContactByIDWithHttpInfo($id, $data); + return $response; + } + + /** + * Operation updateContactByIDWithHttpInfo + * + * Update contact by id + * + * @param int $id ID of Contact **(Required)** (required) + * @param \RadioManager\Model\ContactDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function updateContactByIDWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateContactByIDRequest($id, $data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\ContactResults', - '/contacts' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\ContactResults', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\ContactResults', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation updateContactByID + * Operation updateContactByIDAsync * * Update contact by id * * @param int $id ID of Contact **(Required)** (required) * @param \RadioManager\Model\ContactDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateContactByID($id, $data = null) + public function updateContactByIDAsync($id, $data = null) { - list($response) = $this->updateContactByIDWithHttpInfo($id, $data); - return $response; + return $this->updateContactByIDAsyncWithHttpInfo($id, $data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation updateContactByIDWithHttpInfo + * Operation updateContactByIDAsyncWithHttpInfo * * Update contact by id * * @param int $id ID of Contact **(Required)** (required) * @param \RadioManager\Model\ContactDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateContactByIDWithHttpInfo($id, $data = null) + public function updateContactByIDAsyncWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateContactByIDRequest($id, $data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'updateContactByID' + * + * @param int $id ID of Contact **(Required)** (required) + * @param \RadioManager\Model\ContactDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updateContactByIDRequest($id, $data = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling updateContactByID'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling ContactApi.updateContactByID, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/contacts/{id}"; - $httpBody = ''; + + $resourcePath = '/contacts/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); } + // body params $_tempBody = null; if (isset($data)) { $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'PATCH', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/contacts/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'PATCH', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/ExternalMessageApi.php b/lib/Api/ExternalMessageApi.php index 70632a1..e288ed7 100644 --- a/lib/Api/ExternalMessageApi.php +++ b/lib/Api/ExternalMessageApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * ExternalMessageApi Class Doc Comment @@ -44,47 +49,36 @@ class ExternalMessageApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return ExternalMessageApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\ExternalMessageQueueData $message Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return object */ public function queueExternalMessage($message) @@ -109,25 +104,156 @@ public function queueExternalMessage($message) * * @param \RadioManager\Model\ExternalMessageQueueData $message Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of object, HTTP status code, HTTP response headers (array of strings) */ public function queueExternalMessageWithHttpInfo($message) + { + $returnType = 'object'; + $request = $this->queueExternalMessageRequest($message); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), 'object', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation queueExternalMessageAsync + * + * Queue External Message. + * + * @param \RadioManager\Model\ExternalMessageQueueData $message Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function queueExternalMessageAsync($message) + { + return $this->queueExternalMessageAsyncWithHttpInfo($message)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation queueExternalMessageAsyncWithHttpInfo + * + * Queue External Message. + * + * @param \RadioManager\Model\ExternalMessageQueueData $message Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function queueExternalMessageAsyncWithHttpInfo($message) + { + $returnType = 'object'; + $request = $this->queueExternalMessageRequest($message); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'queueExternalMessage' + * + * @param \RadioManager\Model\ExternalMessageQueueData $message Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function queueExternalMessageRequest($message) { // verify the required parameter 'message' is set if ($message === null) { throw new \InvalidArgumentException('Missing the required parameter $message when calling queueExternalMessage'); } - // parse inputs - $resourcePath = "/externalmessagequeue"; - $httpBody = ''; + + $resourcePath = '/externalmessagequeue'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -135,51 +261,66 @@ public function queueExternalMessageWithHttpInfo($message) $_tempBody = $message; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - 'object', - '/externalmessagequeue' - ); - return [$this->apiClient->getSerializer()->deserialize($response, 'object', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'object', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/GenreApi.php b/lib/Api/GenreApi.php index e1d361f..0e41cc1 100644 --- a/lib/Api/GenreApi.php +++ b/lib/Api/GenreApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * GenreApi Class Doc Comment @@ -44,47 +49,36 @@ class GenreApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return GenreApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -95,6 +89,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * @param int $id ID of Genre **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\GenreResult */ public function getGenreById($id, $_external_station_id = null) @@ -111,93 +106,338 @@ public function getGenreById($id, $_external_station_id = null) * @param int $id ID of Genre **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\GenreResult, HTTP status code, HTTP response headers (array of strings) */ public function getGenreByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\GenreResult'; + $request = $this->getGenreByIdRequest($id, $_external_station_id); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\GenreResult', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getGenreByIdAsync + * + * Get genre by id + * + * @param int $id ID of Genre **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getGenreByIdAsync($id, $_external_station_id = null) + { + return $this->getGenreByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getGenreByIdAsyncWithHttpInfo + * + * Get genre by id + * + * @param int $id ID of Genre **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getGenreByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\GenreResult'; + $request = $this->getGenreByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getGenreById' + * + * @param int $id ID of Genre **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getGenreByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getGenreById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling GenreApi.getGenreById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/genres/{id}"; - $httpBody = ''; + + $resourcePath = '/genres/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listGenres + * + * List all genres. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $parent_id Search on Parent ID of Genre *(Optional)* (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\GenreResults + */ + public function listGenres($page = null, $parent_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + { + list($response) = $this->listGenresWithHttpInfo($page, $parent_id, $program_id, $broadcast_id, $_external_station_id); + return $response; + } + + /** + * Operation listGenresWithHttpInfo + * + * List all genres. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $parent_id Search on Parent ID of Genre *(Optional)* (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\GenreResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listGenresWithHttpInfo($page = null, $parent_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\GenreResults'; + $request = $this->listGenresRequest($page, $parent_id, $program_id, $broadcast_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\GenreResult', - '/genres/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\GenreResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\GenreResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\GenreResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listGenres + * Operation listGenresAsync * * List all genres. * @@ -206,17 +446,18 @@ public function getGenreByIdWithHttpInfo($id, $_external_station_id = null) * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\GenreResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listGenres($page = null, $parent_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + public function listGenresAsync($page = null, $parent_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) { - list($response) = $this->listGenresWithHttpInfo($page, $parent_id, $program_id, $broadcast_id, $_external_station_id); - return $response; + return $this->listGenresAsyncWithHttpInfo($page, $parent_id, $program_id, $broadcast_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listGenresWithHttpInfo + * Operation listGenresAsyncWithHttpInfo * * List all genres. * @@ -225,93 +466,150 @@ public function listGenres($page = null, $parent_id = null, $program_id = null, * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\GenreResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listGenresWithHttpInfo($page = null, $parent_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + public function listGenresAsyncWithHttpInfo($page = null, $parent_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\GenreResults'; + $request = $this->listGenresRequest($page, $parent_id, $program_id, $broadcast_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listGenres' + * + * @param int $page Current page *(Optional)* (optional) + * @param int $parent_id Search on Parent ID of Genre *(Optional)* (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listGenresRequest($page = null, $parent_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling GenreApi.listGenres, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/genres"; - $httpBody = ''; + + $resourcePath = '/genres'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($parent_id !== null) { - $queryParams['parent_id'] = $this->apiClient->getSerializer()->toQueryValue($parent_id); + $queryParams['parent_id'] = ObjectSerializer::toQueryValue($parent_id); } // query params if ($program_id !== null) { - $queryParams['program_id'] = $this->apiClient->getSerializer()->toQueryValue($program_id); + $queryParams['program_id'] = ObjectSerializer::toQueryValue($program_id); } // query params if ($broadcast_id !== null) { - $queryParams['broadcast_id'] = $this->apiClient->getSerializer()->toQueryValue($broadcast_id); + $queryParams['broadcast_id'] = ObjectSerializer::toQueryValue($broadcast_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\GenreResults', - '/genres' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\GenreResults', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\GenreResults', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/ItemApi.php b/lib/Api/ItemApi.php index 2314a35..dd0778e 100644 --- a/lib/Api/ItemApi.php +++ b/lib/Api/ItemApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * ItemApi Class Doc Comment @@ -44,47 +49,36 @@ class ItemApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return ItemApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\ItemDataInput $data Data *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\PostSuccess */ public function createItem($data = null) @@ -109,21 +104,148 @@ public function createItem($data = null) * * @param \RadioManager\Model\ItemDataInput $data Data *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\PostSuccess, HTTP status code, HTTP response headers (array of strings) */ public function createItemWithHttpInfo($data = null) { - // parse inputs - $resourcePath = "/items"; - $httpBody = ''; + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createItemRequest($data); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createItemAsync + * + * Create an new item. + * + * @param \RadioManager\Model\ItemDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createItemAsync($data = null) + { + return $this->createItemAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createItemAsyncWithHttpInfo + * + * Create an new item. + * + * @param \RadioManager\Model\ItemDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createItemAsyncWithHttpInfo($data = null) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createItemRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'createItem' + * + * @param \RadioManager\Model\ItemDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createItemRequest($data = null) + { + + $resourcePath = '/items'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -131,48 +253,66 @@ public function createItemWithHttpInfo($data = null) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PostSuccess', - '/items' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PostSuccess', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); } /** @@ -182,6 +322,7 @@ public function createItemWithHttpInfo($data = null) * * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\Success */ public function currentItemPostStructure($data = null) @@ -197,113 +338,152 @@ public function currentItemPostStructure($data = null) * * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) */ public function currentItemPostStructureWithHttpInfo($data = null) { - // parse inputs - $resourcePath = "/items/current/structure"; - $httpBody = ''; - $queryParams = []; - $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); - - // body params - $_tempBody = null; - if (isset($data)) { - $_tempBody = $data; - } + $returnType = '\RadioManager\Model\Success'; + $request = $this->currentItemPostStructureRequest($data); - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) - } - // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; - } - // make the API Call try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/items/current/structure' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation currentItemPostTiming + * Operation currentItemPostStructureAsync * - * Post a current playing item + * Post a current playing item, keep structure * * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function currentItemPostTiming($data = null) + public function currentItemPostStructureAsync($data = null) { - list($response) = $this->currentItemPostTimingWithHttpInfo($data); - return $response; + return $this->currentItemPostStructureAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation currentItemPostTimingWithHttpInfo + * Operation currentItemPostStructureAsyncWithHttpInfo * - * Post a current playing item + * Post a current playing item, keep structure * * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function currentItemPostTimingWithHttpInfo($data = null) + public function currentItemPostStructureAsyncWithHttpInfo($data = null) { - // parse inputs - $resourcePath = "/items/current/timing"; - $httpBody = ''; + $returnType = '\RadioManager\Model\Success'; + $request = $this->currentItemPostStructureRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'currentItemPostStructure' + * + * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function currentItemPostStructureRequest($data = null) + { + + $resourcePath = '/items/current/structure'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -311,262 +491,801 @@ public function currentItemPostTimingWithHttpInfo($data = null) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/items/current/timing' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); } /** - * Operation deleteItemById + * Operation currentItemPostTiming * - * Delete item by ID. + * Post a current playing item * - * @param int $id ID of Item **(Required)** (required) + * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\Success */ - public function deleteItemById($id) + public function currentItemPostTiming($data = null) { - list($response) = $this->deleteItemByIdWithHttpInfo($id); + list($response) = $this->currentItemPostTimingWithHttpInfo($data); return $response; } /** - * Operation deleteItemByIdWithHttpInfo + * Operation currentItemPostTimingWithHttpInfo * - * Delete item by ID. + * Post a current playing item * - * @param int $id ID of Item **(Required)** (required) + * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) */ - public function deleteItemByIdWithHttpInfo($id) + public function currentItemPostTimingWithHttpInfo($data = null) { - // verify the required parameter 'id' is set - if ($id === null) { - throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteItemById'); - } - if (($id < 0)) { - throw new \InvalidArgumentException('invalid value for "$id" when calling ItemApi.deleteItemById, must be bigger than or equal to 0.'); - } + $returnType = '\RadioManager\Model\Success'; + $request = $this->currentItemPostTimingRequest($data); - // parse inputs - $resourcePath = "/items/{id}"; - $httpBody = ''; - $queryParams = []; - $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + try { - // path params - if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); - } + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) - } - // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; - } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/items/{id}' - ); + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; } catch (ApiException $e) { switch ($e->getCode()) { - case 202: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getItemById + * Operation currentItemPostTimingAsync * - * Get extended item details by ID. + * Post a current playing item * - * @param int $id ID of Item **(Required)** (required) - * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\ItemResult + * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getItemById($id, $_external_station_id = null) + public function currentItemPostTimingAsync($data = null) { - list($response) = $this->getItemByIdWithHttpInfo($id, $_external_station_id); - return $response; + return $this->currentItemPostTimingAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getItemByIdWithHttpInfo + * Operation currentItemPostTimingAsyncWithHttpInfo * - * Get extended item details by ID. + * Post a current playing item * - * @param int $id ID of Item **(Required)** (required) - * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\ItemResult, HTTP status code, HTTP response headers (array of strings) + * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getItemByIdWithHttpInfo($id, $_external_station_id = null) + public function currentItemPostTimingAsyncWithHttpInfo($data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->currentItemPostTimingRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'currentItemPostTiming' + * + * @param \RadioManager\Model\ImportItem $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function currentItemPostTimingRequest($data = null) + { + + $resourcePath = '/items/current/timing'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // body params + $_tempBody = null; + if (isset($data)) { + $_tempBody = $data; + } + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation deleteItemById + * + * Delete item by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function deleteItemById($id) + { + list($response) = $this->deleteItemByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation deleteItemByIdWithHttpInfo + * + * Delete item by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteItemByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteItemByIdRequest($id); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 202: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation deleteItemByIdAsync + * + * Delete item by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteItemByIdAsync($id) + { + return $this->deleteItemByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation deleteItemByIdAsyncWithHttpInfo + * + * Delete item by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteItemByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteItemByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deleteItemById' + * + * @param int $id ID of Item **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteItemByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { - throw new \InvalidArgumentException('Missing the required parameter $id when calling getItemById'); + throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteItemById'); } - if (($id < 0)) { - throw new \InvalidArgumentException('invalid value for "$id" when calling ItemApi.getItemById, must be bigger than or equal to 0.'); + if ($id < 0) { + throw new \InvalidArgumentException('invalid value for "$id" when calling ItemApi.deleteItemById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/items/{id}"; - $httpBody = ''; + + $resourcePath = '/items/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + - // query params - if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); - } // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getItemById + * + * Get extended item details by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\ItemResult + */ + public function getItemById($id, $_external_station_id = null) + { + list($response) = $this->getItemByIdWithHttpInfo($id, $_external_station_id); + return $response; + } + + /** + * Operation getItemByIdWithHttpInfo + * + * Get extended item details by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\ItemResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getItemByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ItemResult'; + $request = $this->getItemByIdRequest($id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\ItemResult', - '/items/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\ItemResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\ItemResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\ItemResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } + /** + * Operation getItemByIdAsync + * + * Get extended item details by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getItemByIdAsync($id, $_external_station_id = null) + { + return $this->getItemByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getItemByIdAsyncWithHttpInfo + * + * Get extended item details by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getItemByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ItemResult'; + $request = $this->getItemByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getItemById' + * + * @param int $id ID of Item **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getItemByIdRequest($id, $_external_station_id = null) + { + // verify the required parameter 'id' is set + if ($id === null) { + throw new \InvalidArgumentException('Missing the required parameter $id when calling getItemById'); + } + if ($id < 0) { + throw new \InvalidArgumentException('invalid value for "$id" when calling ItemApi.getItemById, must be bigger than or equal to 0.'); + } + + + $resourcePath = '/items/{id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($_external_station_id !== null) { + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + // path params + if ($id !== null) { + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + /** * Operation listItems * @@ -592,6 +1311,7 @@ public function getItemByIdWithHttpInfo($id, $_external_station_id = null) * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\ItemResults */ public function listItems($page = null, $order_by = null, $order_direction = null, $start_min = null, $start_max = null, $duration_min = null, $duration_max = null, $status = null, $model_type_id = null, $program_draft_id = null, $user_draft_id = null, $station_draft_id = null, $block_id = null, $broadcast_id = null, $campaign_id = null, $contact_id = null, $program_id = null, $tag_id = null, $_external_station_id = null) @@ -625,192 +1345,519 @@ public function listItems($page = null, $order_by = null, $order_direction = nul * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\ItemResults, HTTP status code, HTTP response headers (array of strings) */ public function listItemsWithHttpInfo($page = null, $order_by = null, $order_direction = null, $start_min = null, $start_max = null, $duration_min = null, $duration_max = null, $status = null, $model_type_id = null, $program_draft_id = null, $user_draft_id = null, $station_draft_id = null, $block_id = null, $broadcast_id = null, $campaign_id = null, $contact_id = null, $program_id = null, $tag_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 1)) { + $returnType = '\RadioManager\Model\ItemResults'; + $request = $this->listItemsRequest($page, $order_by, $order_direction, $start_min, $start_max, $duration_min, $duration_max, $status, $model_type_id, $program_draft_id, $user_draft_id, $station_draft_id, $block_id, $broadcast_id, $campaign_id, $contact_id, $program_id, $tag_id, $_external_station_id); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\ItemResults', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation listItemsAsync + * + * Get a list of all the items currently in your station. + * + * @param int $page Current page *(Optional)* (optional) + * @param string $order_by Field to order the results *(Optional)* (optional) + * @param string $order_direction Direction of ordering *(Optional)* (optional) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $duration_min Minimum duration (seconds) *(Optional)* (optional) + * @param int $duration_max Maximum duration (seconds) *(Optional)* (optional) + * @param string $status Play Status of item *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $program_draft_id Search on Program Draft ID *(Optional)* (optional) + * @param int $user_draft_id Search on User Draft ID *(Optional)* (optional) + * @param int $station_draft_id Search on Station Draft ID *(Optional)* (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $campaign_id Search on Campaign ID *(Optional)* `(Relation)` (optional) + * @param int $contact_id Search on Contact ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function listItemsAsync($page = null, $order_by = null, $order_direction = null, $start_min = null, $start_max = null, $duration_min = null, $duration_max = null, $status = null, $model_type_id = null, $program_draft_id = null, $user_draft_id = null, $station_draft_id = null, $block_id = null, $broadcast_id = null, $campaign_id = null, $contact_id = null, $program_id = null, $tag_id = null, $_external_station_id = null) + { + return $this->listItemsAsyncWithHttpInfo($page, $order_by, $order_direction, $start_min, $start_max, $duration_min, $duration_max, $status, $model_type_id, $program_draft_id, $user_draft_id, $station_draft_id, $block_id, $broadcast_id, $campaign_id, $contact_id, $program_id, $tag_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation listItemsAsyncWithHttpInfo + * + * Get a list of all the items currently in your station. + * + * @param int $page Current page *(Optional)* (optional) + * @param string $order_by Field to order the results *(Optional)* (optional) + * @param string $order_direction Direction of ordering *(Optional)* (optional) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $duration_min Minimum duration (seconds) *(Optional)* (optional) + * @param int $duration_max Maximum duration (seconds) *(Optional)* (optional) + * @param string $status Play Status of item *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $program_draft_id Search on Program Draft ID *(Optional)* (optional) + * @param int $user_draft_id Search on User Draft ID *(Optional)* (optional) + * @param int $station_draft_id Search on Station Draft ID *(Optional)* (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $campaign_id Search on Campaign ID *(Optional)* `(Relation)` (optional) + * @param int $contact_id Search on Contact ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function listItemsAsyncWithHttpInfo($page = null, $order_by = null, $order_direction = null, $start_min = null, $start_max = null, $duration_min = null, $duration_max = null, $status = null, $model_type_id = null, $program_draft_id = null, $user_draft_id = null, $station_draft_id = null, $block_id = null, $broadcast_id = null, $campaign_id = null, $contact_id = null, $program_id = null, $tag_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ItemResults'; + $request = $this->listItemsRequest($page, $order_by, $order_direction, $start_min, $start_max, $duration_min, $duration_max, $status, $model_type_id, $program_draft_id, $user_draft_id, $station_draft_id, $block_id, $broadcast_id, $campaign_id, $contact_id, $program_id, $tag_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listItems' + * + * @param int $page Current page *(Optional)* (optional) + * @param string $order_by Field to order the results *(Optional)* (optional) + * @param string $order_direction Direction of ordering *(Optional)* (optional) + * @param \DateTime $start_min Minimum start date *(Optional)* (optional) + * @param \DateTime $start_max Maximum start date *(Optional)* (optional) + * @param int $duration_min Minimum duration (seconds) *(Optional)* (optional) + * @param int $duration_max Maximum duration (seconds) *(Optional)* (optional) + * @param string $status Play Status of item *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $program_draft_id Search on Program Draft ID *(Optional)* (optional) + * @param int $user_draft_id Search on User Draft ID *(Optional)* (optional) + * @param int $station_draft_id Search on Station Draft ID *(Optional)* (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $campaign_id Search on Campaign ID *(Optional)* `(Relation)` (optional) + * @param int $contact_id Search on Contact ID *(Optional)* `(Relation)` (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listItemsRequest($page = null, $order_by = null, $order_direction = null, $start_min = null, $start_max = null, $duration_min = null, $duration_max = null, $status = null, $model_type_id = null, $program_draft_id = null, $user_draft_id = null, $station_draft_id = null, $block_id = null, $broadcast_id = null, $campaign_id = null, $contact_id = null, $program_id = null, $tag_id = null, $_external_station_id = null) + { + if ($page !== null && $page < 1) { throw new \InvalidArgumentException('invalid value for "$page" when calling ItemApi.listItems, must be bigger than or equal to 1.'); } - // parse inputs - $resourcePath = "/items"; - $httpBody = ''; + + $resourcePath = '/items'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($order_by !== null) { - $queryParams['order-by'] = $this->apiClient->getSerializer()->toQueryValue($order_by); + $queryParams['order-by'] = ObjectSerializer::toQueryValue($order_by); } // query params if ($order_direction !== null) { - $queryParams['order-direction'] = $this->apiClient->getSerializer()->toQueryValue($order_direction); + $queryParams['order-direction'] = ObjectSerializer::toQueryValue($order_direction); } // query params if ($start_min !== null) { - $queryParams['start-min'] = $this->apiClient->getSerializer()->toQueryValue($start_min); + $queryParams['start-min'] = ObjectSerializer::toQueryValue($start_min); } // query params if ($start_max !== null) { - $queryParams['start-max'] = $this->apiClient->getSerializer()->toQueryValue($start_max); + $queryParams['start-max'] = ObjectSerializer::toQueryValue($start_max); } // query params if ($duration_min !== null) { - $queryParams['duration-min'] = $this->apiClient->getSerializer()->toQueryValue($duration_min); + $queryParams['duration-min'] = ObjectSerializer::toQueryValue($duration_min); } // query params if ($duration_max !== null) { - $queryParams['duration-max'] = $this->apiClient->getSerializer()->toQueryValue($duration_max); + $queryParams['duration-max'] = ObjectSerializer::toQueryValue($duration_max); } // query params if ($status !== null) { - $queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status); + $queryParams['status'] = ObjectSerializer::toQueryValue($status); } // query params if ($model_type_id !== null) { - $queryParams['model_type_id'] = $this->apiClient->getSerializer()->toQueryValue($model_type_id); + $queryParams['model_type_id'] = ObjectSerializer::toQueryValue($model_type_id); } // query params if ($program_draft_id !== null) { - $queryParams['program_draft_id'] = $this->apiClient->getSerializer()->toQueryValue($program_draft_id); + $queryParams['program_draft_id'] = ObjectSerializer::toQueryValue($program_draft_id); } // query params if ($user_draft_id !== null) { - $queryParams['user_draft_id'] = $this->apiClient->getSerializer()->toQueryValue($user_draft_id); + $queryParams['user_draft_id'] = ObjectSerializer::toQueryValue($user_draft_id); } // query params if ($station_draft_id !== null) { - $queryParams['station_draft_id'] = $this->apiClient->getSerializer()->toQueryValue($station_draft_id); + $queryParams['station_draft_id'] = ObjectSerializer::toQueryValue($station_draft_id); } // query params if ($block_id !== null) { - $queryParams['block_id'] = $this->apiClient->getSerializer()->toQueryValue($block_id); + $queryParams['block_id'] = ObjectSerializer::toQueryValue($block_id); } // query params if ($broadcast_id !== null) { - $queryParams['broadcast_id'] = $this->apiClient->getSerializer()->toQueryValue($broadcast_id); + $queryParams['broadcast_id'] = ObjectSerializer::toQueryValue($broadcast_id); } // query params if ($campaign_id !== null) { - $queryParams['campaign_id'] = $this->apiClient->getSerializer()->toQueryValue($campaign_id); + $queryParams['campaign_id'] = ObjectSerializer::toQueryValue($campaign_id); } // query params if ($contact_id !== null) { - $queryParams['contact_id'] = $this->apiClient->getSerializer()->toQueryValue($contact_id); + $queryParams['contact_id'] = ObjectSerializer::toQueryValue($contact_id); } // query params if ($program_id !== null) { - $queryParams['program_id'] = $this->apiClient->getSerializer()->toQueryValue($program_id); + $queryParams['program_id'] = ObjectSerializer::toQueryValue($program_id); } // query params if ($tag_id !== null) { - $queryParams['tag_id'] = $this->apiClient->getSerializer()->toQueryValue($tag_id); + $queryParams['tag_id'] = ObjectSerializer::toQueryValue($tag_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) - } - // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; - } - // make the API Call + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation playlistPostStructure + * + * Post a playlist, keep current structure + * + * @param \RadioManager\Model\Data1 $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\InlineResponse202 + */ + public function playlistPostStructure($data = null) + { + list($response) = $this->playlistPostStructureWithHttpInfo($data); + return $response; + } + + /** + * Operation playlistPostStructureWithHttpInfo + * + * Post a playlist, keep current structure + * + * @param \RadioManager\Model\Data1 $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\InlineResponse202, HTTP status code, HTTP response headers (array of strings) + */ + public function playlistPostStructureWithHttpInfo($data = null) + { + $returnType = '\RadioManager\Model\InlineResponse202'; + $request = $this->playlistPostStructureRequest($data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\ItemResults', - '/items' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\ItemResults', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\ItemResults', $e->getResponseHeaders()); + case 202: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\InlineResponse202', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation playlistPostStructure + * Operation playlistPostStructureAsync * * Post a playlist, keep current structure * * @param \RadioManager\Model\Data1 $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\InlineResponse202 + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function playlistPostStructure($data = null) + public function playlistPostStructureAsync($data = null) { - list($response) = $this->playlistPostStructureWithHttpInfo($data); - return $response; + return $this->playlistPostStructureAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation playlistPostStructureWithHttpInfo + * Operation playlistPostStructureAsyncWithHttpInfo * * Post a playlist, keep current structure * * @param \RadioManager\Model\Data1 $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\InlineResponse202, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function playlistPostStructureWithHttpInfo($data = null) + public function playlistPostStructureAsyncWithHttpInfo($data = null) { - // parse inputs - $resourcePath = "/items/playlist/structure"; - $httpBody = ''; + $returnType = '\RadioManager\Model\InlineResponse202'; + $request = $this->playlistPostStructureRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'playlistPostStructure' + * + * @param \RadioManager\Model\Data1 $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function playlistPostStructureRequest($data = null) + { + + $resourcePath = '/items/playlist/structure'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -818,87 +1865,233 @@ public function playlistPostStructureWithHttpInfo($data = null) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation playlistPostTiming + * + * Post a playlist + * + * @param \RadioManager\Model\Data $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\InlineResponse202 + */ + public function playlistPostTiming($data = null) + { + list($response) = $this->playlistPostTimingWithHttpInfo($data); + return $response; + } + + /** + * Operation playlistPostTimingWithHttpInfo + * + * Post a playlist + * + * @param \RadioManager\Model\Data $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\InlineResponse202, HTTP status code, HTTP response headers (array of strings) + */ + public function playlistPostTimingWithHttpInfo($data = null) + { + $returnType = '\RadioManager\Model\InlineResponse202'; + $request = $this->playlistPostTimingRequest($data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\InlineResponse202', - '/items/playlist/structure' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\InlineResponse202', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 202: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\InlineResponse202', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\InlineResponse202', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation playlistPostTiming + * Operation playlistPostTimingAsync * * Post a playlist * * @param \RadioManager\Model\Data $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\InlineResponse202 + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function playlistPostTiming($data = null) + public function playlistPostTimingAsync($data = null) { - list($response) = $this->playlistPostTimingWithHttpInfo($data); - return $response; + return $this->playlistPostTimingAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation playlistPostTimingWithHttpInfo + * Operation playlistPostTimingAsyncWithHttpInfo * * Post a playlist * * @param \RadioManager\Model\Data $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\InlineResponse202, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function playlistPostTimingWithHttpInfo($data = null) + public function playlistPostTimingAsyncWithHttpInfo($data = null) { - // parse inputs - $resourcePath = "/items/playlist/timing"; - $httpBody = ''; + $returnType = '\RadioManager\Model\InlineResponse202'; + $request = $this->playlistPostTimingRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'playlistPostTiming' + * + * @param \RadioManager\Model\Data $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function playlistPostTimingRequest($data = null) + { + + $resourcePath = '/items/playlist/timing'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -906,161 +2099,325 @@ public function playlistPostTimingWithHttpInfo($data = null) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation updateItemById + * + * Update extended item details by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @param \RadioManager\Model\Item $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function updateItemById($id, $data = null) + { + list($response) = $this->updateItemByIdWithHttpInfo($id, $data); + return $response; + } + + /** + * Operation updateItemByIdWithHttpInfo + * + * Update extended item details by ID. + * + * @param int $id ID of Item **(Required)** (required) + * @param \RadioManager\Model\Item $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function updateItemByIdWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateItemByIdRequest($id, $data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\InlineResponse202', - '/items/playlist/timing' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\InlineResponse202', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { - case 202: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\InlineResponse202', $e->getResponseHeaders()); + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation updateItemById + * Operation updateItemByIdAsync * * Update extended item details by ID. * * @param int $id ID of Item **(Required)** (required) * @param \RadioManager\Model\Item $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateItemById($id, $data = null) + public function updateItemByIdAsync($id, $data = null) { - list($response) = $this->updateItemByIdWithHttpInfo($id, $data); - return $response; + return $this->updateItemByIdAsyncWithHttpInfo($id, $data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation updateItemByIdWithHttpInfo + * Operation updateItemByIdAsyncWithHttpInfo * * Update extended item details by ID. * * @param int $id ID of Item **(Required)** (required) * @param \RadioManager\Model\Item $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateItemByIdWithHttpInfo($id, $data = null) + public function updateItemByIdAsyncWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateItemByIdRequest($id, $data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'updateItemById' + * + * @param int $id ID of Item **(Required)** (required) + * @param \RadioManager\Model\Item $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updateItemByIdRequest($id, $data = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling updateItemById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling ItemApi.updateItemById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/items/{id}"; - $httpBody = ''; + + $resourcePath = '/items/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); } + // body params $_tempBody = null; if (isset($data)) { $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'PATCH', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/items/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'PATCH', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/ModelTypeApi.php b/lib/Api/ModelTypeApi.php index 3e2733b..ad1be9f 100644 --- a/lib/Api/ModelTypeApi.php +++ b/lib/Api/ModelTypeApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * ModelTypeApi Class Doc Comment @@ -44,47 +49,36 @@ class ModelTypeApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return ModelTypeApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -95,6 +89,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * @param int $id ID of ModelType **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\ModelTypeResult */ public function getModelTypeById($id, $_external_station_id = null) @@ -111,93 +106,346 @@ public function getModelTypeById($id, $_external_station_id = null) * @param int $id ID of ModelType **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\ModelTypeResult, HTTP status code, HTTP response headers (array of strings) */ public function getModelTypeByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ModelTypeResult'; + $request = $this->getModelTypeByIdRequest($id, $_external_station_id); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\ModelTypeResult', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getModelTypeByIdAsync + * + * Get modelType by id + * + * @param int $id ID of ModelType **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getModelTypeByIdAsync($id, $_external_station_id = null) + { + return $this->getModelTypeByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getModelTypeByIdAsyncWithHttpInfo + * + * Get modelType by id + * + * @param int $id ID of ModelType **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getModelTypeByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ModelTypeResult'; + $request = $this->getModelTypeByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getModelTypeById' + * + * @param int $id ID of ModelType **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getModelTypeByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getModelTypeById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling ModelTypeApi.getModelTypeById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/model_types/{id}"; - $httpBody = ''; + + $resourcePath = '/model_types/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listModelTypes + * + * Get all modelTypes. + * + * @param int $page Current page *(Optional)* (optional) + * @param string $model (optional) + * @param int $program_id Search on Program ID *(Optional)* (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* (optional) + * @param int $item_id Search on Item ID *(Optional)* (optional) + * @param int $campaign_id Search on Campaign ID *(Optional)* (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* (optional) + * @param int $contact_id Search on Contact ID *(Optional)* (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\ModelTypeResults + */ + public function listModelTypes($page = null, $model = null, $program_id = null, $broadcast_id = null, $item_id = null, $campaign_id = null, $presenter_id = null, $contact_id = null, $_external_station_id = null) + { + list($response) = $this->listModelTypesWithHttpInfo($page, $model, $program_id, $broadcast_id, $item_id, $campaign_id, $presenter_id, $contact_id, $_external_station_id); + return $response; + } + + /** + * Operation listModelTypesWithHttpInfo + * + * Get all modelTypes. + * + * @param int $page Current page *(Optional)* (optional) + * @param string $model (optional) + * @param int $program_id Search on Program ID *(Optional)* (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* (optional) + * @param int $item_id Search on Item ID *(Optional)* (optional) + * @param int $campaign_id Search on Campaign ID *(Optional)* (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* (optional) + * @param int $contact_id Search on Contact ID *(Optional)* (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\ModelTypeResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listModelTypesWithHttpInfo($page = null, $model = null, $program_id = null, $broadcast_id = null, $item_id = null, $campaign_id = null, $presenter_id = null, $contact_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ModelTypeResults'; + $request = $this->listModelTypesRequest($page, $model, $program_id, $broadcast_id, $item_id, $campaign_id, $presenter_id, $contact_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\ModelTypeResult', - '/model_types/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\ModelTypeResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\ModelTypeResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\ModelTypeResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listModelTypes + * Operation listModelTypesAsync * * Get all modelTypes. * @@ -210,17 +458,18 @@ public function getModelTypeByIdWithHttpInfo($id, $_external_station_id = null) * @param int $presenter_id Search on Presenter ID *(Optional)* (optional) * @param int $contact_id Search on Contact ID *(Optional)* (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\ModelTypeResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listModelTypes($page = null, $model = null, $program_id = null, $broadcast_id = null, $item_id = null, $campaign_id = null, $presenter_id = null, $contact_id = null, $_external_station_id = null) + public function listModelTypesAsync($page = null, $model = null, $program_id = null, $broadcast_id = null, $item_id = null, $campaign_id = null, $presenter_id = null, $contact_id = null, $_external_station_id = null) { - list($response) = $this->listModelTypesWithHttpInfo($page, $model, $program_id, $broadcast_id, $item_id, $campaign_id, $presenter_id, $contact_id, $_external_station_id); - return $response; + return $this->listModelTypesAsyncWithHttpInfo($page, $model, $program_id, $broadcast_id, $item_id, $campaign_id, $presenter_id, $contact_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listModelTypesWithHttpInfo + * Operation listModelTypesAsyncWithHttpInfo * * Get all modelTypes. * @@ -233,109 +482,170 @@ public function listModelTypes($page = null, $model = null, $program_id = null, * @param int $presenter_id Search on Presenter ID *(Optional)* (optional) * @param int $contact_id Search on Contact ID *(Optional)* (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\ModelTypeResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listModelTypesWithHttpInfo($page = null, $model = null, $program_id = null, $broadcast_id = null, $item_id = null, $campaign_id = null, $presenter_id = null, $contact_id = null, $_external_station_id = null) + public function listModelTypesAsyncWithHttpInfo($page = null, $model = null, $program_id = null, $broadcast_id = null, $item_id = null, $campaign_id = null, $presenter_id = null, $contact_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ModelTypeResults'; + $request = $this->listModelTypesRequest($page, $model, $program_id, $broadcast_id, $item_id, $campaign_id, $presenter_id, $contact_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listModelTypes' + * + * @param int $page Current page *(Optional)* (optional) + * @param string $model (optional) + * @param int $program_id Search on Program ID *(Optional)* (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* (optional) + * @param int $item_id Search on Item ID *(Optional)* (optional) + * @param int $campaign_id Search on Campaign ID *(Optional)* (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* (optional) + * @param int $contact_id Search on Contact ID *(Optional)* (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listModelTypesRequest($page = null, $model = null, $program_id = null, $broadcast_id = null, $item_id = null, $campaign_id = null, $presenter_id = null, $contact_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling ModelTypeApi.listModelTypes, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/model_types"; - $httpBody = ''; + + $resourcePath = '/model_types'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($model !== null) { - $queryParams['model'] = $this->apiClient->getSerializer()->toQueryValue($model); + $queryParams['model'] = ObjectSerializer::toQueryValue($model); } // query params if ($program_id !== null) { - $queryParams['program_id'] = $this->apiClient->getSerializer()->toQueryValue($program_id); + $queryParams['program_id'] = ObjectSerializer::toQueryValue($program_id); } // query params if ($broadcast_id !== null) { - $queryParams['broadcast_id'] = $this->apiClient->getSerializer()->toQueryValue($broadcast_id); + $queryParams['broadcast_id'] = ObjectSerializer::toQueryValue($broadcast_id); } // query params if ($item_id !== null) { - $queryParams['item_id'] = $this->apiClient->getSerializer()->toQueryValue($item_id); + $queryParams['item_id'] = ObjectSerializer::toQueryValue($item_id); } // query params if ($campaign_id !== null) { - $queryParams['campaign_id'] = $this->apiClient->getSerializer()->toQueryValue($campaign_id); + $queryParams['campaign_id'] = ObjectSerializer::toQueryValue($campaign_id); } // query params if ($presenter_id !== null) { - $queryParams['presenter_id'] = $this->apiClient->getSerializer()->toQueryValue($presenter_id); + $queryParams['presenter_id'] = ObjectSerializer::toQueryValue($presenter_id); } // query params if ($contact_id !== null) { - $queryParams['contact_id'] = $this->apiClient->getSerializer()->toQueryValue($contact_id); + $queryParams['contact_id'] = ObjectSerializer::toQueryValue($contact_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\ModelTypeResults', - '/model_types' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\ModelTypeResults', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\ModelTypeResults', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/PresenterApi.php b/lib/Api/PresenterApi.php index f6faeb3..d44e34c 100644 --- a/lib/Api/PresenterApi.php +++ b/lib/Api/PresenterApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * PresenterApi Class Doc Comment @@ -44,47 +49,36 @@ class PresenterApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return PresenterApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\PresenterDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\PostSuccess */ public function createPresenter($data) @@ -109,25 +104,160 @@ public function createPresenter($data) * * @param \RadioManager\Model\PresenterDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\PostSuccess, HTTP status code, HTTP response headers (array of strings) */ public function createPresenterWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createPresenterRequest($data); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createPresenterAsync + * + * Create presenter. + * + * @param \RadioManager\Model\PresenterDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createPresenterAsync($data) + { + return $this->createPresenterAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createPresenterAsyncWithHttpInfo + * + * Create presenter. + * + * @param \RadioManager\Model\PresenterDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createPresenterAsyncWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createPresenterRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'createPresenter' + * + * @param \RadioManager\Model\PresenterDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createPresenterRequest($data) { // verify the required parameter 'data' is set if ($data === null) { throw new \InvalidArgumentException('Missing the required parameter $data when calling createPresenter'); } - // parse inputs - $resourcePath = "/presenters"; - $httpBody = ''; + + $resourcePath = '/presenters'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -135,272 +265,670 @@ public function createPresenterWithHttpInfo($data) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation deletePresenterById + * + * Delete presenter by id + * + * @param int $id id of presenter (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function deletePresenterById($id) + { + list($response) = $this->deletePresenterByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation deletePresenterByIdWithHttpInfo + * + * Delete presenter by id + * + * @param int $id id of presenter (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function deletePresenterByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deletePresenterByIdRequest($id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PostSuccess', - '/presenters' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PostSuccess', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation deletePresenterById + * Operation deletePresenterByIdAsync * * Delete presenter by id * * @param int $id id of presenter (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deletePresenterById($id) + public function deletePresenterByIdAsync($id) { - list($response) = $this->deletePresenterByIdWithHttpInfo($id); - return $response; + return $this->deletePresenterByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation deletePresenterByIdWithHttpInfo + * Operation deletePresenterByIdAsyncWithHttpInfo * * Delete presenter by id * * @param int $id id of presenter (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deletePresenterByIdWithHttpInfo($id) + public function deletePresenterByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deletePresenterByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deletePresenterById' + * + * @param int $id id of presenter (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deletePresenterByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling deletePresenterById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling PresenterApi.deletePresenterById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/presenters/{id}"; - $httpBody = ''; + + $resourcePath = '/presenters/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getPresenterById + * + * Get presenter by id + * + * @param int $id id of Presenter (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\PresenterResult + */ + public function getPresenterById($id, $_external_station_id = null) + { + list($response) = $this->getPresenterByIdWithHttpInfo($id, $_external_station_id); + return $response; + } + + /** + * Operation getPresenterByIdWithHttpInfo + * + * Get presenter by id + * + * @param int $id id of Presenter (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\PresenterResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getPresenterByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\PresenterResult'; + $request = $this->getPresenterByIdRequest($id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/presenters/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PresenterResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getPresenterById + * Operation getPresenterByIdAsync * * Get presenter by id * * @param int $id id of Presenter (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\PresenterResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getPresenterById($id, $_external_station_id = null) + public function getPresenterByIdAsync($id, $_external_station_id = null) { - list($response) = $this->getPresenterByIdWithHttpInfo($id, $_external_station_id); - return $response; + return $this->getPresenterByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getPresenterByIdWithHttpInfo + * Operation getPresenterByIdAsyncWithHttpInfo * * Get presenter by id * * @param int $id id of Presenter (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\PresenterResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getPresenterByIdWithHttpInfo($id, $_external_station_id = null) + public function getPresenterByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\PresenterResult'; + $request = $this->getPresenterByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getPresenterById' + * + * @param int $id id of Presenter (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getPresenterByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getPresenterById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling PresenterApi.getPresenterById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/presenters/{id}"; - $httpBody = ''; + + $resourcePath = '/presenters/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listPresenters + * + * Get all presenters. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID (Optional) (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\PresenterResults + */ + public function listPresenters($page = null, $model_type_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + { + list($response) = $this->listPresentersWithHttpInfo($page, $model_type_id, $program_id, $broadcast_id, $_external_station_id); + return $response; + } + + /** + * Operation listPresentersWithHttpInfo + * + * Get all presenters. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID (Optional) (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\PresenterResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listPresentersWithHttpInfo($page = null, $model_type_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\PresenterResults'; + $request = $this->listPresentersRequest($page, $model_type_id, $program_id, $broadcast_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PresenterResult', - '/presenters/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PresenterResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PresenterResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PresenterResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listPresenters + * Operation listPresentersAsync * * Get all presenters. * @@ -409,17 +937,18 @@ public function getPresenterByIdWithHttpInfo($id, $_external_station_id = null) * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\PresenterResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listPresenters($page = null, $model_type_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + public function listPresentersAsync($page = null, $model_type_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) { - list($response) = $this->listPresentersWithHttpInfo($page, $model_type_id, $program_id, $broadcast_id, $_external_station_id); - return $response; + return $this->listPresentersAsyncWithHttpInfo($page, $model_type_id, $program_id, $broadcast_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listPresentersWithHttpInfo + * Operation listPresentersAsyncWithHttpInfo * * Get all presenters. * @@ -428,207 +957,409 @@ public function listPresenters($page = null, $model_type_id = null, $program_id * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\PresenterResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listPresentersWithHttpInfo($page = null, $model_type_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + public function listPresentersAsyncWithHttpInfo($page = null, $model_type_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\PresenterResults'; + $request = $this->listPresentersRequest($page, $model_type_id, $program_id, $broadcast_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listPresenters' + * + * @param int $page Current page *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID (Optional) (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listPresentersRequest($page = null, $model_type_id = null, $program_id = null, $broadcast_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling PresenterApi.listPresenters, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/presenters"; - $httpBody = ''; + + $resourcePath = '/presenters'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($model_type_id !== null) { - $queryParams['model_type_id'] = $this->apiClient->getSerializer()->toQueryValue($model_type_id); + $queryParams['model_type_id'] = ObjectSerializer::toQueryValue($model_type_id); } // query params if ($program_id !== null) { - $queryParams['program_id'] = $this->apiClient->getSerializer()->toQueryValue($program_id); + $queryParams['program_id'] = ObjectSerializer::toQueryValue($program_id); } // query params if ($broadcast_id !== null) { - $queryParams['broadcast_id'] = $this->apiClient->getSerializer()->toQueryValue($broadcast_id); + $queryParams['broadcast_id'] = ObjectSerializer::toQueryValue($broadcast_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation updatePresenterByID + * + * Update presenter by id + * + * @param int $id id of Presenter (required) + * @param \RadioManager\Model\PresenterDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function updatePresenterByID($id, $data = null) + { + list($response) = $this->updatePresenterByIDWithHttpInfo($id, $data); + return $response; + } + + /** + * Operation updatePresenterByIDWithHttpInfo + * + * Update presenter by id + * + * @param int $id id of Presenter (required) + * @param \RadioManager\Model\PresenterDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function updatePresenterByIDWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updatePresenterByIDRequest($id, $data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PresenterResults', - '/presenters' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PresenterResults', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PresenterResults', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation updatePresenterByID + * Operation updatePresenterByIDAsync * * Update presenter by id * * @param int $id id of Presenter (required) * @param \RadioManager\Model\PresenterDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updatePresenterByID($id, $data = null) + public function updatePresenterByIDAsync($id, $data = null) { - list($response) = $this->updatePresenterByIDWithHttpInfo($id, $data); - return $response; + return $this->updatePresenterByIDAsyncWithHttpInfo($id, $data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation updatePresenterByIDWithHttpInfo + * Operation updatePresenterByIDAsyncWithHttpInfo * * Update presenter by id * * @param int $id id of Presenter (required) * @param \RadioManager\Model\PresenterDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updatePresenterByIDWithHttpInfo($id, $data = null) + public function updatePresenterByIDAsyncWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updatePresenterByIDRequest($id, $data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'updatePresenterByID' + * + * @param int $id id of Presenter (required) + * @param \RadioManager\Model\PresenterDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updatePresenterByIDRequest($id, $data = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling updatePresenterByID'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling PresenterApi.updatePresenterByID, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/presenters/{id}"; - $httpBody = ''; + + $resourcePath = '/presenters/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); } + // body params $_tempBody = null; if (isset($data)) { $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'PATCH', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/presenters/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'PATCH', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/ProgramApi.php b/lib/Api/ProgramApi.php index 4bf8e75..38f7aba 100644 --- a/lib/Api/ProgramApi.php +++ b/lib/Api/ProgramApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * ProgramApi Class Doc Comment @@ -44,47 +49,36 @@ class ProgramApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return ProgramApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\ProgramDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\PostSuccess */ public function createProgram($data) @@ -109,25 +104,160 @@ public function createProgram($data) * * @param \RadioManager\Model\ProgramDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\PostSuccess, HTTP status code, HTTP response headers (array of strings) */ public function createProgramWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createProgramRequest($data); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createProgramAsync + * + * Create program. + * + * @param \RadioManager\Model\ProgramDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createProgramAsync($data) + { + return $this->createProgramAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createProgramAsyncWithHttpInfo + * + * Create program. + * + * @param \RadioManager\Model\ProgramDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createProgramAsyncWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createProgramRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'createProgram' + * + * @param \RadioManager\Model\ProgramDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createProgramRequest($data) { // verify the required parameter 'data' is set if ($data === null) { throw new \InvalidArgumentException('Missing the required parameter $data when calling createProgram'); } - // parse inputs - $resourcePath = "/programs"; - $httpBody = ''; + + $resourcePath = '/programs'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -135,272 +265,678 @@ public function createProgramWithHttpInfo($data) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation deleteProgramById + * + * Delete program by id + * + * @param int $id ID of program **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function deleteProgramById($id) + { + list($response) = $this->deleteProgramByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation deleteProgramByIdWithHttpInfo + * + * Delete program by id + * + * @param int $id ID of program **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteProgramByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteProgramByIdRequest($id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PostSuccess', - '/programs' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PostSuccess', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation deleteProgramById + * Operation deleteProgramByIdAsync * * Delete program by id * * @param int $id ID of program **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteProgramById($id) + public function deleteProgramByIdAsync($id) { - list($response) = $this->deleteProgramByIdWithHttpInfo($id); - return $response; + return $this->deleteProgramByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation deleteProgramByIdWithHttpInfo + * Operation deleteProgramByIdAsyncWithHttpInfo * * Delete program by id * * @param int $id ID of program **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteProgramByIdWithHttpInfo($id) + public function deleteProgramByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteProgramByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deleteProgramById' + * + * @param int $id ID of program **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteProgramByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteProgramById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling ProgramApi.deleteProgramById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/programs/{id}"; - $httpBody = ''; + + $resourcePath = '/programs/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getProgramById + * + * Get program by id + * + * @param int $id ID of Program **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\ProgramResult + */ + public function getProgramById($id, $_external_station_id = null) + { + list($response) = $this->getProgramByIdWithHttpInfo($id, $_external_station_id); + return $response; + } + + /** + * Operation getProgramByIdWithHttpInfo + * + * Get program by id + * + * @param int $id ID of Program **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\ProgramResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getProgramByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ProgramResult'; + $request = $this->getProgramByIdRequest($id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/programs/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\ProgramResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getProgramById + * Operation getProgramByIdAsync * * Get program by id * * @param int $id ID of Program **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\ProgramResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getProgramById($id, $_external_station_id = null) + public function getProgramByIdAsync($id, $_external_station_id = null) { - list($response) = $this->getProgramByIdWithHttpInfo($id, $_external_station_id); - return $response; + return $this->getProgramByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getProgramByIdWithHttpInfo + * Operation getProgramByIdAsyncWithHttpInfo * * Get program by id * * @param int $id ID of Program **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\ProgramResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getProgramByIdWithHttpInfo($id, $_external_station_id = null) + public function getProgramByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ProgramResult'; + $request = $this->getProgramByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getProgramById' + * + * @param int $id ID of Program **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getProgramByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getProgramById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling ProgramApi.getProgramById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/programs/{id}"; - $httpBody = ''; + + $resourcePath = '/programs/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listPrograms + * + * Get all programs. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $genre_id Search on Genre ID *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\ProgramResults + */ + public function listPrograms($page = null, $genre_id = null, $model_type_id = null, $presenter_id = null, $tag_id = null, $broadcast_id = null, $item_id = null, $block_id = null, $_external_station_id = null) + { + list($response) = $this->listProgramsWithHttpInfo($page, $genre_id, $model_type_id, $presenter_id, $tag_id, $broadcast_id, $item_id, $block_id, $_external_station_id); + return $response; + } + + /** + * Operation listProgramsWithHttpInfo + * + * Get all programs. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $genre_id Search on Genre ID *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\ProgramResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listProgramsWithHttpInfo($page = null, $genre_id = null, $model_type_id = null, $presenter_id = null, $tag_id = null, $broadcast_id = null, $item_id = null, $block_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\ProgramResults'; + $request = $this->listProgramsRequest($page, $genre_id, $model_type_id, $presenter_id, $tag_id, $broadcast_id, $item_id, $block_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\ProgramResult', - '/programs/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\ProgramResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\ProgramResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\ProgramResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listPrograms + * Operation listProgramsAsync * * Get all programs. * @@ -413,17 +949,18 @@ public function getProgramByIdWithHttpInfo($id, $_external_station_id = null) * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\ProgramResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listPrograms($page = null, $genre_id = null, $model_type_id = null, $presenter_id = null, $tag_id = null, $broadcast_id = null, $item_id = null, $block_id = null, $_external_station_id = null) + public function listProgramsAsync($page = null, $genre_id = null, $model_type_id = null, $presenter_id = null, $tag_id = null, $broadcast_id = null, $item_id = null, $block_id = null, $_external_station_id = null) { - list($response) = $this->listProgramsWithHttpInfo($page, $genre_id, $model_type_id, $presenter_id, $tag_id, $broadcast_id, $item_id, $block_id, $_external_station_id); - return $response; + return $this->listProgramsAsyncWithHttpInfo($page, $genre_id, $model_type_id, $presenter_id, $tag_id, $broadcast_id, $item_id, $block_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listProgramsWithHttpInfo + * Operation listProgramsAsyncWithHttpInfo * * Get all programs. * @@ -436,223 +973,429 @@ public function listPrograms($page = null, $genre_id = null, $model_type_id = nu * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\ProgramResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listProgramsWithHttpInfo($page = null, $genre_id = null, $model_type_id = null, $presenter_id = null, $tag_id = null, $broadcast_id = null, $item_id = null, $block_id = null, $_external_station_id = null) + public function listProgramsAsyncWithHttpInfo($page = null, $genre_id = null, $model_type_id = null, $presenter_id = null, $tag_id = null, $broadcast_id = null, $item_id = null, $block_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + $returnType = '\RadioManager\Model\ProgramResults'; + $request = $this->listProgramsRequest($page, $genre_id, $model_type_id, $presenter_id, $tag_id, $broadcast_id, $item_id, $block_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listPrograms' + * + * @param int $page Current page *(Optional)* (optional) + * @param int $genre_id Search on Genre ID *(Optional)* (optional) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $presenter_id Search on Presenter ID *(Optional)* `(Relation)` (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $block_id Search on Block ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listProgramsRequest($page = null, $genre_id = null, $model_type_id = null, $presenter_id = null, $tag_id = null, $broadcast_id = null, $item_id = null, $block_id = null, $_external_station_id = null) + { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling ProgramApi.listPrograms, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/programs"; - $httpBody = ''; + + $resourcePath = '/programs'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($genre_id !== null) { - $queryParams['genre_id'] = $this->apiClient->getSerializer()->toQueryValue($genre_id); + $queryParams['genre_id'] = ObjectSerializer::toQueryValue($genre_id); } // query params if ($model_type_id !== null) { - $queryParams['model_type_id'] = $this->apiClient->getSerializer()->toQueryValue($model_type_id); + $queryParams['model_type_id'] = ObjectSerializer::toQueryValue($model_type_id); } // query params if ($presenter_id !== null) { - $queryParams['presenter_id'] = $this->apiClient->getSerializer()->toQueryValue($presenter_id); + $queryParams['presenter_id'] = ObjectSerializer::toQueryValue($presenter_id); } // query params if ($tag_id !== null) { - $queryParams['tag_id'] = $this->apiClient->getSerializer()->toQueryValue($tag_id); + $queryParams['tag_id'] = ObjectSerializer::toQueryValue($tag_id); } // query params if ($broadcast_id !== null) { - $queryParams['broadcast_id'] = $this->apiClient->getSerializer()->toQueryValue($broadcast_id); + $queryParams['broadcast_id'] = ObjectSerializer::toQueryValue($broadcast_id); } // query params if ($item_id !== null) { - $queryParams['item_id'] = $this->apiClient->getSerializer()->toQueryValue($item_id); + $queryParams['item_id'] = ObjectSerializer::toQueryValue($item_id); } // query params if ($block_id !== null) { - $queryParams['block_id'] = $this->apiClient->getSerializer()->toQueryValue($block_id); + $queryParams['block_id'] = ObjectSerializer::toQueryValue($block_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation updateProgramByID + * + * Update program by id + * + * @param int $id ID of Program **(Required)** (required) + * @param \RadioManager\Model\ProgramDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function updateProgramByID($id, $data = null) + { + list($response) = $this->updateProgramByIDWithHttpInfo($id, $data); + return $response; + } + + /** + * Operation updateProgramByIDWithHttpInfo + * + * Update program by id + * + * @param int $id ID of Program **(Required)** (required) + * @param \RadioManager\Model\ProgramDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function updateProgramByIDWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateProgramByIDRequest($id, $data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\ProgramResults', - '/programs' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\ProgramResults', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\ProgramResults', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation updateProgramByID + * Operation updateProgramByIDAsync * * Update program by id * * @param int $id ID of Program **(Required)** (required) * @param \RadioManager\Model\ProgramDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateProgramByID($id, $data = null) + public function updateProgramByIDAsync($id, $data = null) { - list($response) = $this->updateProgramByIDWithHttpInfo($id, $data); - return $response; + return $this->updateProgramByIDAsyncWithHttpInfo($id, $data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation updateProgramByIDWithHttpInfo + * Operation updateProgramByIDAsyncWithHttpInfo * * Update program by id * * @param int $id ID of Program **(Required)** (required) * @param \RadioManager\Model\ProgramDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateProgramByIDWithHttpInfo($id, $data = null) + public function updateProgramByIDAsyncWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateProgramByIDRequest($id, $data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'updateProgramByID' + * + * @param int $id ID of Program **(Required)** (required) + * @param \RadioManager\Model\ProgramDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updateProgramByIDRequest($id, $data = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling updateProgramByID'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling ProgramApi.updateProgramByID, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/programs/{id}"; - $httpBody = ''; + + $resourcePath = '/programs/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); } + // body params $_tempBody = null; if (isset($data)) { $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'PATCH', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/programs/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'PATCH', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/StoryApi.php b/lib/Api/StoryApi.php index 5506647..eb5d54d 100644 --- a/lib/Api/StoryApi.php +++ b/lib/Api/StoryApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * StoryApi Class Doc Comment @@ -44,47 +49,36 @@ class StoryApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return StoryApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\StoryDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\PostSuccess */ public function createStory($data) @@ -109,25 +104,156 @@ public function createStory($data) * * @param \RadioManager\Model\StoryDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\PostSuccess, HTTP status code, HTTP response headers (array of strings) */ public function createStoryWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createStoryRequest($data); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createStoryAsync + * + * Create story. + * + * @param \RadioManager\Model\StoryDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createStoryAsync($data) + { + return $this->createStoryAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createStoryAsyncWithHttpInfo + * + * Create story. + * + * @param \RadioManager\Model\StoryDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createStoryAsyncWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createStoryRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'createStory' + * + * @param \RadioManager\Model\StoryDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createStoryRequest($data) { // verify the required parameter 'data' is set if ($data === null) { throw new \InvalidArgumentException('Missing the required parameter $data when calling createStory'); } - // parse inputs - $resourcePath = "/stories"; - $httpBody = ''; + + $resourcePath = '/stories'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -135,272 +261,670 @@ public function createStoryWithHttpInfo($data) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation deleteStoryById + * + * Delete story by id + * + * @param int $id ID of Story **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function deleteStoryById($id) + { + list($response) = $this->deleteStoryByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation deleteStoryByIdWithHttpInfo + * + * Delete story by id + * + * @param int $id ID of Story **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteStoryByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteStoryByIdRequest($id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PostSuccess', - '/stories' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PostSuccess', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation deleteStoryById + * Operation deleteStoryByIdAsync * * Delete story by id * * @param int $id ID of Story **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteStoryById($id) + public function deleteStoryByIdAsync($id) { - list($response) = $this->deleteStoryByIdWithHttpInfo($id); - return $response; + return $this->deleteStoryByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation deleteStoryByIdWithHttpInfo + * Operation deleteStoryByIdAsyncWithHttpInfo * * Delete story by id * * @param int $id ID of Story **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteStoryByIdWithHttpInfo($id) + public function deleteStoryByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteStoryByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deleteStoryById' + * + * @param int $id ID of Story **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteStoryByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteStoryById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling StoryApi.deleteStoryById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/stories/{id}"; - $httpBody = ''; + + $resourcePath = '/stories/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getStoryById + * + * Get story by id + * + * @param int $id ID of Story **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\StoryResult + */ + public function getStoryById($id, $_external_station_id = null) + { + list($response) = $this->getStoryByIdWithHttpInfo($id, $_external_station_id); + return $response; + } + + /** + * Operation getStoryByIdWithHttpInfo + * + * Get story by id + * + * @param int $id ID of Story **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\StoryResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getStoryByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\StoryResult'; + $request = $this->getStoryByIdRequest($id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/stories/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\StoryResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getStoryById + * Operation getStoryByIdAsync * * Get story by id * * @param int $id ID of Story **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\StoryResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getStoryById($id, $_external_station_id = null) + public function getStoryByIdAsync($id, $_external_station_id = null) { - list($response) = $this->getStoryByIdWithHttpInfo($id, $_external_station_id); - return $response; + return $this->getStoryByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getStoryByIdWithHttpInfo + * Operation getStoryByIdAsyncWithHttpInfo * * Get story by id * * @param int $id ID of Story **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\StoryResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getStoryByIdWithHttpInfo($id, $_external_station_id = null) + public function getStoryByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\StoryResult'; + $request = $this->getStoryByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getStoryById' + * + * @param int $id ID of Story **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getStoryByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getStoryById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling StoryApi.getStoryById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/stories/{id}"; - $httpBody = ''; + + $resourcePath = '/stories/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listStories + * + * Get all stories. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\StoryResults + */ + public function listStories($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + { + list($response) = $this->listStoriesWithHttpInfo($page, $model_type_id, $tag_id, $item_id, $_external_station_id); + return $response; + } + + /** + * Operation listStoriesWithHttpInfo + * + * Get all stories. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\StoryResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listStoriesWithHttpInfo($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\StoryResults'; + $request = $this->listStoriesRequest($page, $model_type_id, $tag_id, $item_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\StoryResult', - '/stories/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\StoryResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\StoryResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\StoryResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listStories + * Operation listStoriesAsync * * Get all stories. * @@ -409,17 +933,18 @@ public function getStoryByIdWithHttpInfo($id, $_external_station_id = null) * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\StoryResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listStories($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + public function listStoriesAsync($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) { - list($response) = $this->listStoriesWithHttpInfo($page, $model_type_id, $tag_id, $item_id, $_external_station_id); - return $response; + return $this->listStoriesAsyncWithHttpInfo($page, $model_type_id, $tag_id, $item_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listStoriesWithHttpInfo + * Operation listStoriesAsyncWithHttpInfo * * Get all stories. * @@ -428,207 +953,409 @@ public function listStories($page = '1', $model_type_id = null, $tag_id = null, * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\StoryResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listStoriesWithHttpInfo($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + public function listStoriesAsyncWithHttpInfo($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 0)) { + $returnType = '\RadioManager\Model\StoryResults'; + $request = $this->listStoriesRequest($page, $model_type_id, $tag_id, $item_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listStories' + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $model_type_id Search on ModelType ID *(Optional)* (optional) + * @param int $tag_id Search on Tag ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listStoriesRequest($page = '1', $model_type_id = null, $tag_id = null, $item_id = null, $_external_station_id = null) + { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling StoryApi.listStories, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/stories"; - $httpBody = ''; + + $resourcePath = '/stories'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($model_type_id !== null) { - $queryParams['model_type_id'] = $this->apiClient->getSerializer()->toQueryValue($model_type_id); + $queryParams['model_type_id'] = ObjectSerializer::toQueryValue($model_type_id); } // query params if ($tag_id !== null) { - $queryParams['tag_id'] = $this->apiClient->getSerializer()->toQueryValue($tag_id); + $queryParams['tag_id'] = ObjectSerializer::toQueryValue($tag_id); } // query params if ($item_id !== null) { - $queryParams['item_id'] = $this->apiClient->getSerializer()->toQueryValue($item_id); + $queryParams['item_id'] = ObjectSerializer::toQueryValue($item_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation updateStoryByID + * + * Update story by id + * + * @param int $id ID of Story **(Required)** (required) + * @param \RadioManager\Model\StoryDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function updateStoryByID($id, $data = null) + { + list($response) = $this->updateStoryByIDWithHttpInfo($id, $data); + return $response; + } + + /** + * Operation updateStoryByIDWithHttpInfo + * + * Update story by id + * + * @param int $id ID of Story **(Required)** (required) + * @param \RadioManager\Model\StoryDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function updateStoryByIDWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateStoryByIDRequest($id, $data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\StoryResults', - '/stories' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\StoryResults', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\StoryResults', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation updateStoryByID + * Operation updateStoryByIDAsync * * Update story by id * * @param int $id ID of Story **(Required)** (required) * @param \RadioManager\Model\StoryDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateStoryByID($id, $data = null) + public function updateStoryByIDAsync($id, $data = null) { - list($response) = $this->updateStoryByIDWithHttpInfo($id, $data); - return $response; + return $this->updateStoryByIDAsyncWithHttpInfo($id, $data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation updateStoryByIDWithHttpInfo + * Operation updateStoryByIDAsyncWithHttpInfo * * Update story by id * * @param int $id ID of Story **(Required)** (required) * @param \RadioManager\Model\StoryDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateStoryByIDWithHttpInfo($id, $data = null) + public function updateStoryByIDAsyncWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateStoryByIDRequest($id, $data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'updateStoryByID' + * + * @param int $id ID of Story **(Required)** (required) + * @param \RadioManager\Model\StoryDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updateStoryByIDRequest($id, $data = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling updateStoryByID'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling StoryApi.updateStoryByID, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/stories/{id}"; - $httpBody = ''; + + $resourcePath = '/stories/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); } + // body params $_tempBody = null; if (isset($data)) { $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'PATCH', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/stories/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'PATCH', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/StringApi.php b/lib/Api/StringApi.php index 6979c60..3f27037 100644 --- a/lib/Api/StringApi.php +++ b/lib/Api/StringApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * StringApi Class Doc Comment @@ -44,47 +49,36 @@ class StringApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return StringApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -95,6 +89,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * @param string $name Name of Strings **(Required)** (required) * @param bool $full_model Full model or content only **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\TextString */ public function getStringsByName($name, $full_model) @@ -111,9 +106,141 @@ public function getStringsByName($name, $full_model) * @param string $name Name of Strings **(Required)** (required) * @param bool $full_model Full model or content only **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\TextString, HTTP status code, HTTP response headers (array of strings) */ public function getStringsByNameWithHttpInfo($name, $full_model) + { + $returnType = '\RadioManager\Model\TextString'; + $request = $this->getStringsByNameRequest($name, $full_model); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TextString', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getStringsByNameAsync + * + * Get Strings (formatted) + * + * @param string $name Name of Strings **(Required)** (required) + * @param bool $full_model Full model or content only **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getStringsByNameAsync($name, $full_model) + { + return $this->getStringsByNameAsyncWithHttpInfo($name, $full_model)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getStringsByNameAsyncWithHttpInfo + * + * Get Strings (formatted) + * + * @param string $name Name of Strings **(Required)** (required) + * @param bool $full_model Full model or content only **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getStringsByNameAsyncWithHttpInfo($name, $full_model) + { + $returnType = '\RadioManager\Model\TextString'; + $request = $this->getStringsByNameRequest($name, $full_model); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getStringsByName' + * + * @param string $name Name of Strings **(Required)** (required) + * @param bool $full_model Full model or content only **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getStringsByNameRequest($name, $full_model) { // verify the required parameter 'name' is set if ($name === null) { @@ -123,72 +250,85 @@ public function getStringsByNameWithHttpInfo($name, $full_model) if ($full_model === null) { throw new \InvalidArgumentException('Missing the required parameter $full_model when calling getStringsByName'); } - // parse inputs - $resourcePath = "/strings/{name}"; - $httpBody = ''; + + $resourcePath = '/strings/{name}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($full_model !== null) { - $queryParams['full_model'] = $this->apiClient->getSerializer()->toQueryValue($full_model); + $queryParams['full_model'] = ObjectSerializer::toQueryValue($full_model); } + // path params if ($name !== null) { - $resourcePath = str_replace( - "{" . "name" . "}", - $this->apiClient->getSerializer()->toPathValue($name), - $resourcePath + $resourcePath = str_replace('{' . 'name' . '}', ObjectSerializer::toPathValue($name), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\TextString', - '/strings/{name}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\TextString', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TextString', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/TagApi.php b/lib/Api/TagApi.php index bce41ed..ed00a37 100644 --- a/lib/Api/TagApi.php +++ b/lib/Api/TagApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * TagApi Class Doc Comment @@ -44,47 +49,36 @@ class TagApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return TagApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param \RadioManager\Model\TagDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\PostSuccess */ public function createTag($data) @@ -109,25 +104,160 @@ public function createTag($data) * * @param \RadioManager\Model\TagDataInput $data Data **(Required)** (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\PostSuccess, HTTP status code, HTTP response headers (array of strings) */ public function createTagWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createTagRequest($data); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createTagAsync + * + * Create tag. + * + * @param \RadioManager\Model\TagDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createTagAsync($data) + { + return $this->createTagAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation createTagAsyncWithHttpInfo + * + * Create tag. + * + * @param \RadioManager\Model\TagDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createTagAsyncWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\PostSuccess'; + $request = $this->createTagRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'createTag' + * + * @param \RadioManager\Model\TagDataInput $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function createTagRequest($data) { // verify the required parameter 'data' is set if ($data === null) { throw new \InvalidArgumentException('Missing the required parameter $data when calling createTag'); } - // parse inputs - $resourcePath = "/tags"; - $httpBody = ''; + + $resourcePath = '/tags'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -135,272 +265,672 @@ public function createTagWithHttpInfo($data) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation deleteTagById + * + * Delete tag by id + * + * @param int $id ID of Tag **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function deleteTagById($id) + { + list($response) = $this->deleteTagByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation deleteTagByIdWithHttpInfo + * + * Delete tag by id + * + * @param int $id ID of Tag **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteTagByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteTagByIdRequest($id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\PostSuccess', - '/tags' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\PostSuccess', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\PostSuccess', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation deleteTagById + * Operation deleteTagByIdAsync * * Delete tag by id * * @param int $id ID of Tag **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteTagById($id) + public function deleteTagByIdAsync($id) { - list($response) = $this->deleteTagByIdWithHttpInfo($id); - return $response; + return $this->deleteTagByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation deleteTagByIdWithHttpInfo + * Operation deleteTagByIdAsyncWithHttpInfo * * Delete tag by id * * @param int $id ID of Tag **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function deleteTagByIdWithHttpInfo($id) + public function deleteTagByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteTagByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deleteTagById' + * + * @param int $id ID of Tag **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteTagByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteTagById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling TagApi.deleteTagById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/tags/{id}"; - $httpBody = ''; + + $resourcePath = '/tags/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getTagById + * + * Get tags by id + * + * @param int $id ID of Tag **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\TagResult + */ + public function getTagById($id, $_external_station_id = null) + { + list($response) = $this->getTagByIdWithHttpInfo($id, $_external_station_id); + return $response; + } + + /** + * Operation getTagByIdWithHttpInfo + * + * Get tags by id + * + * @param int $id ID of Tag **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\TagResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getTagByIdWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\TagResult'; + $request = $this->getTagByIdRequest($id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/tags/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TagResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getTagById + * Operation getTagByIdAsync * * Get tags by id * * @param int $id ID of Tag **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\TagResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getTagById($id, $_external_station_id = null) + public function getTagByIdAsync($id, $_external_station_id = null) { - list($response) = $this->getTagByIdWithHttpInfo($id, $_external_station_id); - return $response; + return $this->getTagByIdAsyncWithHttpInfo($id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getTagByIdWithHttpInfo + * Operation getTagByIdAsyncWithHttpInfo * * Get tags by id * * @param int $id ID of Tag **(Required)** (required) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\TagResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getTagByIdWithHttpInfo($id, $_external_station_id = null) + public function getTagByIdAsyncWithHttpInfo($id, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\TagResult'; + $request = $this->getTagByIdRequest($id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getTagById' + * + * @param int $id ID of Tag **(Required)** (required) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getTagByIdRequest($id, $_external_station_id = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getTagById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling TagApi.getTagById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/tags/{id}"; - $httpBody = ''; + + $resourcePath = '/tags/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); } + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listTags + * + * Get a list of all the tags currently in your station. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $contact_id Search on Contact ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\TagResults + */ + public function listTags($page = null, $program_id = null, $item_id = null, $broadcast_id = null, $contact_id = null, $_external_station_id = null) + { + list($response) = $this->listTagsWithHttpInfo($page, $program_id, $item_id, $broadcast_id, $contact_id, $_external_station_id); + return $response; + } + + /** + * Operation listTagsWithHttpInfo + * + * Get a list of all the tags currently in your station. + * + * @param int $page Current page *(Optional)* (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $contact_id Search on Contact ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\TagResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listTagsWithHttpInfo($page = null, $program_id = null, $item_id = null, $broadcast_id = null, $contact_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\TagResults'; + $request = $this->listTagsRequest($page, $program_id, $item_id, $broadcast_id, $contact_id, $_external_station_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\TagResult', - '/tags/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\TagResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TagResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TagResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listTags + * Operation listTagsAsync * * Get a list of all the tags currently in your station. * @@ -410,17 +940,18 @@ public function getTagByIdWithHttpInfo($id, $_external_station_id = null) * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) * @param int $contact_id Search on Contact ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\TagResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listTags($page = null, $program_id = null, $item_id = null, $broadcast_id = null, $contact_id = null, $_external_station_id = null) + public function listTagsAsync($page = null, $program_id = null, $item_id = null, $broadcast_id = null, $contact_id = null, $_external_station_id = null) { - list($response) = $this->listTagsWithHttpInfo($page, $program_id, $item_id, $broadcast_id, $contact_id, $_external_station_id); - return $response; + return $this->listTagsAsyncWithHttpInfo($page, $program_id, $item_id, $broadcast_id, $contact_id, $_external_station_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listTagsWithHttpInfo + * Operation listTagsAsyncWithHttpInfo * * Get a list of all the tags currently in your station. * @@ -430,211 +961,414 @@ public function listTags($page = null, $program_id = null, $item_id = null, $bro * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) * @param int $contact_id Search on Contact ID *(Optional)* `(Relation)` (optional) * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\TagResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listTagsWithHttpInfo($page = null, $program_id = null, $item_id = null, $broadcast_id = null, $contact_id = null, $_external_station_id = null) + public function listTagsAsyncWithHttpInfo($page = null, $program_id = null, $item_id = null, $broadcast_id = null, $contact_id = null, $_external_station_id = null) + { + $returnType = '\RadioManager\Model\TagResults'; + $request = $this->listTagsRequest($page, $program_id, $item_id, $broadcast_id, $contact_id, $_external_station_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listTags' + * + * @param int $page Current page *(Optional)* (optional) + * @param int $program_id Search on Program ID *(Optional)* `(Relation)` (optional) + * @param int $item_id Search on Item ID *(Optional)* `(Relation)` (optional) + * @param int $broadcast_id Search on Broadcast ID *(Optional)* `(Relation)` (optional) + * @param int $contact_id Search on Contact ID *(Optional)* `(Relation)` (optional) + * @param int $_external_station_id Query on a different (content providing) station *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listTagsRequest($page = null, $program_id = null, $item_id = null, $broadcast_id = null, $contact_id = null, $_external_station_id = null) { - if (!is_null($page) && ($page < 1)) { + if ($page !== null && $page < 1) { throw new \InvalidArgumentException('invalid value for "$page" when calling TagApi.listTags, must be bigger than or equal to 1.'); } - // parse inputs - $resourcePath = "/tags"; - $httpBody = ''; + + $resourcePath = '/tags'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($program_id !== null) { - $queryParams['program_id'] = $this->apiClient->getSerializer()->toQueryValue($program_id); + $queryParams['program_id'] = ObjectSerializer::toQueryValue($program_id); } // query params if ($item_id !== null) { - $queryParams['item_id'] = $this->apiClient->getSerializer()->toQueryValue($item_id); + $queryParams['item_id'] = ObjectSerializer::toQueryValue($item_id); } // query params if ($broadcast_id !== null) { - $queryParams['broadcast_id'] = $this->apiClient->getSerializer()->toQueryValue($broadcast_id); + $queryParams['broadcast_id'] = ObjectSerializer::toQueryValue($broadcast_id); } // query params if ($contact_id !== null) { - $queryParams['contact_id'] = $this->apiClient->getSerializer()->toQueryValue($contact_id); + $queryParams['contact_id'] = ObjectSerializer::toQueryValue($contact_id); } // query params if ($_external_station_id !== null) { - $queryParams['_external_station_id'] = $this->apiClient->getSerializer()->toQueryValue($_external_station_id); + $queryParams['_external_station_id'] = ObjectSerializer::toQueryValue($_external_station_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation updateTagByID + * + * Update tag by id + * + * @param int $id ID of Tag **(Required)** (required) + * @param \RadioManager\Model\TagDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\Success + */ + public function updateTagByID($id, $data = null) + { + list($response) = $this->updateTagByIDWithHttpInfo($id, $data); + return $response; + } + + /** + * Operation updateTagByIDWithHttpInfo + * + * Update tag by id + * + * @param int $id ID of Tag **(Required)** (required) + * @param \RadioManager\Model\TagDataInput $data Data *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + */ + public function updateTagByIDWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateTagByIDRequest($id, $data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\TagResults', - '/tags' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\TagResults', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TagResults', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation updateTagByID + * Operation updateTagByIDAsync * * Update tag by id * * @param int $id ID of Tag **(Required)** (required) * @param \RadioManager\Model\TagDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\Success + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateTagByID($id, $data = null) + public function updateTagByIDAsync($id, $data = null) { - list($response) = $this->updateTagByIDWithHttpInfo($id, $data); - return $response; + return $this->updateTagByIDAsyncWithHttpInfo($id, $data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation updateTagByIDWithHttpInfo + * Operation updateTagByIDAsyncWithHttpInfo * * Update tag by id * * @param int $id ID of Tag **(Required)** (required) * @param \RadioManager\Model\TagDataInput $data Data *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function updateTagByIDWithHttpInfo($id, $data = null) + public function updateTagByIDAsyncWithHttpInfo($id, $data = null) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->updateTagByIDRequest($id, $data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'updateTagByID' + * + * @param int $id ID of Tag **(Required)** (required) + * @param \RadioManager\Model\TagDataInput $data Data *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function updateTagByIDRequest($id, $data = null) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling updateTagByID'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling TagApi.updateTagByID, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/tags/{id}"; - $httpBody = ''; + + $resourcePath = '/tags/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath - ); + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); } + // body params $_tempBody = null; if (isset($data)) { $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'PATCH', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/tags/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'PATCH', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/UserApi.php b/lib/Api/UserApi.php index f343f62..cc274bd 100644 --- a/lib/Api/UserApi.php +++ b/lib/Api/UserApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * UserApi Class Doc Comment @@ -44,47 +49,36 @@ class UserApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return UserApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -94,6 +88,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * * @param int $id id of User (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\Success */ public function deleteUserById($id) @@ -109,231 +104,650 @@ public function deleteUserById($id) * * @param int $id id of User (required) * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\Success, HTTP status code, HTTP response headers (array of strings) */ public function deleteUserByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteUserByIdRequest($id); + + try { + + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 403: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 404: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 429: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation deleteUserByIdAsync + * + * Remove user from station by Id + * + * @param int $id id of User (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteUserByIdAsync($id) + { + return $this->deleteUserByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation deleteUserByIdAsyncWithHttpInfo + * + * Remove user from station by Id + * + * @param int $id id of User (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteUserByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\Success'; + $request = $this->deleteUserByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'deleteUserById' + * + * @param int $id id of User (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function deleteUserByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling deleteUserById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling UserApi.deleteUserById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/users/{id}"; - $httpBody = ''; + + $resourcePath = '/users/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'DELETE', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation getUserById + * + * Get user by id + * + * @param int $id id of User (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\UserResult + */ + public function getUserById($id) + { + list($response) = $this->getUserByIdWithHttpInfo($id); + return $response; + } + + /** + * Operation getUserByIdWithHttpInfo + * + * Get user by id + * + * @param int $id id of User (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\UserResult, HTTP status code, HTTP response headers (array of strings) + */ + public function getUserByIdWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\UserResult'; + $request = $this->getUserByIdRequest($id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'DELETE', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\Success', - '/users/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\Success', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Success', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UserResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation getUserById + * Operation getUserByIdAsync * * Get user by id * * @param int $id id of User (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\UserResult + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getUserById($id) + public function getUserByIdAsync($id) { - list($response) = $this->getUserByIdWithHttpInfo($id); - return $response; + return $this->getUserByIdAsyncWithHttpInfo($id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation getUserByIdWithHttpInfo + * Operation getUserByIdAsyncWithHttpInfo * * Get user by id * * @param int $id id of User (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\UserResult, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function getUserByIdWithHttpInfo($id) + public function getUserByIdAsyncWithHttpInfo($id) + { + $returnType = '\RadioManager\Model\UserResult'; + $request = $this->getUserByIdRequest($id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getUserById' + * + * @param int $id id of User (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getUserByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null) { throw new \InvalidArgumentException('Missing the required parameter $id when calling getUserById'); } - if (($id < 0)) { + if ($id < 0) { throw new \InvalidArgumentException('invalid value for "$id" when calling UserApi.getUserById, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/users/{id}"; - $httpBody = ''; + + $resourcePath = '/users/{id}'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + // path params if ($id !== null) { - $resourcePath = str_replace( - "{" . "id" . "}", - $this->apiClient->getSerializer()->toPathValue($id), - $resourcePath + $resourcePath = str_replace('{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath); + } + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation inviteUserByMail + * + * Invite user by mail + * + * @param \RadioManager\Model\InviteUserData $data Data **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\InviteUserSuccess + */ + public function inviteUserByMail($data) + { + list($response) = $this->inviteUserByMailWithHttpInfo($data); + return $response; + } + + /** + * Operation inviteUserByMailWithHttpInfo + * + * Invite user by mail + * + * @param \RadioManager\Model\InviteUserData $data Data **(Required)** (required) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\InviteUserSuccess, HTTP status code, HTTP response headers (array of strings) + */ + public function inviteUserByMailWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\InviteUserSuccess'; + $request = $this->inviteUserByMailRequest($data); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\UserResult', - '/users/{id}' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\UserResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UserResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\InviteUserSuccess', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $e->setResponseObject($data); + break; + case 422: + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation inviteUserByMail + * Operation inviteUserByMailAsync * * Invite user by mail * * @param \RadioManager\Model\InviteUserData $data Data **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\InviteUserSuccess + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function inviteUserByMail($data) + public function inviteUserByMailAsync($data) { - list($response) = $this->inviteUserByMailWithHttpInfo($data); - return $response; + return $this->inviteUserByMailAsyncWithHttpInfo($data)->then(function ($response) { + return $response[0]; + }); } /** - * Operation inviteUserByMailWithHttpInfo + * Operation inviteUserByMailAsyncWithHttpInfo * * Invite user by mail * * @param \RadioManager\Model\InviteUserData $data Data **(Required)** (required) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\InviteUserSuccess, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function inviteUserByMailWithHttpInfo($data) + public function inviteUserByMailAsyncWithHttpInfo($data) + { + $returnType = '\RadioManager\Model\InviteUserSuccess'; + $request = $this->inviteUserByMailRequest($data); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'inviteUserByMail' + * + * @param \RadioManager\Model\InviteUserData $data Data **(Required)** (required) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function inviteUserByMailRequest($data) { // verify the required parameter 'data' is set if ($data === null) { throw new \InvalidArgumentException('Missing the required parameter $data when calling inviteUserByMail'); } - // parse inputs - $resourcePath = "/users/invite"; - $httpBody = ''; + + $resourcePath = '/users/invite'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; + + // body params $_tempBody = null; @@ -341,156 +755,316 @@ public function inviteUserByMailWithHttpInfo($data) $_tempBody = $data; } + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } - // make the API Call + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'POST', + $url, + $headers, + $httpBody + ); + } + + /** + * Operation listUsers + * + * Get all users. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $role_id Search on Role ID *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \RadioManager\Model\UserResults + */ + public function listUsers($page = '1', $role_id = null) + { + list($response) = $this->listUsersWithHttpInfo($page, $role_id); + return $response; + } + + /** + * Operation listUsersWithHttpInfo + * + * Get all users. + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $role_id Search on Role ID *(Optional)* (optional) + * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \RadioManager\Model\UserResults, HTTP status code, HTTP response headers (array of strings) + */ + public function listUsersWithHttpInfo($page = '1', $role_id = null) + { + $returnType = '\RadioManager\Model\UserResults'; + $request = $this->listUsersRequest($page, $role_id); + try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'POST', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\InviteUserSuccess', - '/users/invite' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\InviteUserSuccess', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\InviteUserSuccess', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\UserResults', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 422: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UnprocessableEntity', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } /** - * Operation listUsers + * Operation listUsersAsync * * Get all users. * * @param int $page Current page *(Optional)* (optional, default to 1) * @param int $role_id Search on Role ID *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return \RadioManager\Model\UserResults + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listUsers($page = '1', $role_id = null) + public function listUsersAsync($page = '1', $role_id = null) { - list($response) = $this->listUsersWithHttpInfo($page, $role_id); - return $response; + return $this->listUsersAsyncWithHttpInfo($page, $role_id)->then(function ($response) { + return $response[0]; + }); } /** - * Operation listUsersWithHttpInfo + * Operation listUsersAsyncWithHttpInfo * * Get all users. * * @param int $page Current page *(Optional)* (optional, default to 1) * @param int $role_id Search on Role ID *(Optional)* (optional) - * @throws \RadioManager\ApiException on non-2xx response - * @return array of \RadioManager\Model\UserResults, HTTP status code, HTTP response headers (array of strings) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface */ - public function listUsersWithHttpInfo($page = '1', $role_id = null) + public function listUsersAsyncWithHttpInfo($page = '1', $role_id = null) { - if (!is_null($page) && ($page < 0)) { + $returnType = '\RadioManager\Model\UserResults'; + $request = $this->listUsersRequest($page, $role_id); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'listUsers' + * + * @param int $page Current page *(Optional)* (optional, default to 1) + * @param int $role_id Search on Role ID *(Optional)* (optional) + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function listUsersRequest($page = '1', $role_id = null) + { + if ($page !== null && $page < 0) { throw new \InvalidArgumentException('invalid value for "$page" when calling UserApi.listUsers, must be bigger than or equal to 0.'); } - // parse inputs - $resourcePath = "/users"; - $httpBody = ''; + + $resourcePath = '/users'; + $formParams = []; $queryParams = []; $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $httpBody = ''; + $multipart = false; // query params if ($page !== null) { - $queryParams['page'] = $this->apiClient->getSerializer()->toQueryValue($page); + $queryParams['page'] = ObjectSerializer::toQueryValue($page); } // query params if ($role_id !== null) { - $queryParams['role_id'] = $this->apiClient->getSerializer()->toQueryValue($role_id); + $queryParams['role_id'] = ObjectSerializer::toQueryValue($role_id); + } + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); } // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } } + // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; } - // make the API Call - try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\UserResults', - '/users' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\UserResults', $httpHeader), $statusCode, $httpHeader]; - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\UserResults', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 403: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\Forbidden', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); - $e->setResponseObject($data); - break; - } + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); - throw $e; + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); } + } diff --git a/lib/Api/VisualSlideApi.php b/lib/Api/VisualSlideApi.php index a8d64dc..1d499f9 100644 --- a/lib/Api/VisualSlideApi.php +++ b/lib/Api/VisualSlideApi.php @@ -28,10 +28,15 @@ namespace RadioManager\Api; -use \RadioManager\ApiClient; -use \RadioManager\ApiException; -use \RadioManager\Configuration; -use \RadioManager\ObjectSerializer; +use GuzzleHttp\Client; +use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; +use GuzzleHttp\Psr7\MultipartStream; +use GuzzleHttp\Psr7\Request; +use RadioManager\ApiException; +use RadioManager\Configuration; +use RadioManager\HeaderSelector; +use RadioManager\ObjectSerializer; /** * VisualSlideApi Class Doc Comment @@ -44,47 +49,36 @@ class VisualSlideApi { /** - * API Client - * - * @var \RadioManager\ApiClient instance of the ApiClient + * @var ClientInterface */ - protected $apiClient; + protected $client; /** - * Constructor - * - * @param \RadioManager\ApiClient|null $apiClient The api client to use + * @var Configuration */ - public function __construct(\RadioManager\ApiClient $apiClient = null) - { - if ($apiClient === null) { - $apiClient = new ApiClient(); - } - - $this->apiClient = $apiClient; - } + protected $config; /** - * Get API client - * - * @return \RadioManager\ApiClient get the API client + * @param ClientInterface $client + * @param Configuration $config + * @param HeaderSelector $selector */ - public function getApiClient() - { - return $this->apiClient; + public function __construct( + ClientInterface $client = null, + Configuration $config = null, + HeaderSelector $selector = null + ) { + $this->client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); } /** - * Set the API client - * - * @param \RadioManager\ApiClient $apiClient set the API client - * - * @return VisualSlideApi + * @return Configuration */ - public function setApiClient(\RadioManager\ApiClient $apiClient) + public function getConfig() { - $this->apiClient = $apiClient; - return $this; + return $this->config; } /** @@ -93,6 +87,7 @@ public function setApiClient(\RadioManager\ApiClient $apiClient) * Get Visual Slide Image as Base64 * * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return \RadioManager\Model\VisualResult */ public function getVisualSlide() @@ -107,64 +102,207 @@ public function getVisualSlide() * Get Visual Slide Image as Base64 * * @throws \RadioManager\ApiException on non-2xx response + * @throws \InvalidArgumentException * @return array of \RadioManager\Model\VisualResult, HTTP status code, HTTP response headers (array of strings) */ public function getVisualSlideWithHttpInfo() { - // parse inputs - $resourcePath = "/visual"; - $httpBody = ''; - $queryParams = []; - $headerParams = []; - $formParams = []; - $_header_accept = $this->apiClient->selectHeaderAccept(['application/json']); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(['application/json']); + $returnType = '\RadioManager\Model\VisualResult'; + $request = $this->getVisualSlideRequest(); - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } elseif (count($formParams) > 0) { - $httpBody = $formParams; // for HTTP post (form) - } - // this endpoint requires API key authentication - $apiKey = $this->apiClient->getApiKeyWithPrefix('api-key'); - if (strlen($apiKey) !== 0) { - $headerParams['api-key'] = $apiKey; - } - // make the API Call try { - list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( - $resourcePath, - 'GET', - $queryParams, - $httpBody, - $headerParams, - '\RadioManager\Model\VisualResult', - '/visual' - ); - return [$this->apiClient->getSerializer()->deserialize($response, '\RadioManager\Model\VisualResult', $httpHeader), $statusCode, $httpHeader]; + try { + $response = $this->client->send($request); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + "[$statusCode] Error connecting to the API ({$request->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\VisualResult', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\VisualResult', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 404: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\NotFound', $e->getResponseHeaders()); $e->setResponseObject($data); break; case 429: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); + $data = ObjectSerializer::deserialize($e->getResponseBody(), '\RadioManager\Model\TooManyRequests', $e->getResponseHeaders()); $e->setResponseObject($data); break; } - throw $e; } } + + /** + * Operation getVisualSlideAsync + * + * Get Visual Slide Image as Base64 + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getVisualSlideAsync() + { + return $this->getVisualSlideAsyncWithHttpInfo()->then(function ($response) { + return $response[0]; + }); + } + + /** + * Operation getVisualSlideAsyncWithHttpInfo + * + * Get Visual Slide Image as Base64 + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getVisualSlideAsyncWithHttpInfo() + { + $returnType = '\RadioManager\Model\VisualResult'; + $request = $this->getVisualSlideRequest(); + + return $this->client->sendAsync($request)->then(function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + "[$statusCode] Error connecting to the API ({$exception->getRequest()->getUri()})", + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + }); + } + + /** + * Create request for operation 'getVisualSlide' + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function getVisualSlideRequest() + { + + $resourcePath = '/visual'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + if ($multipart) { + $headers= $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + $httpBody = new MultipartStream($multipartContents); // for HTTP post (form) + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); // for HTTP post (form) + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api-key'); + if ($apiKey !== null) { + $headers['api-key'] = $apiKey; + } + + $query = \GuzzleHttp\Psr7\build_query($queryParams); + $url = $this->config->getHost() . $resourcePath . ($query ? '?' . $query : ''); + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + return new Request( + 'GET', + $url, + $headers, + $httpBody + ); + } + } diff --git a/lib/ApiClient.php b/lib/ApiClient.php deleted file mode 100644 index 09ea456..0000000 --- a/lib/ApiClient.php +++ /dev/null @@ -1,371 +0,0 @@ -config = $config; - $this->serializer = new ObjectSerializer(); - } - - /** - * Get the config - * - * @return Configuration - */ - public function getConfig() - { - return $this->config; - } - - /** - * Get the serializer - * - * @return ObjectSerializer - */ - public function getSerializer() - { - return $this->serializer; - } - - /** - * Get API key (with prefix if set) - * - * @param string $apiKeyIdentifier name of apikey - * - * @return string API key with the prefix - */ - public function getApiKeyWithPrefix($apiKeyIdentifier) - { - $prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier); - $apiKey = $this->config->getApiKey($apiKeyIdentifier); - - if (!isset($apiKey)) { - return null; - } - - if (isset($prefix)) { - $keyWithPrefix = $prefix." ".$apiKey; - } else { - $keyWithPrefix = $apiKey; - } - - return $keyWithPrefix; - } - - /** - * Make the HTTP call (Sync) - * - * @param string $resourcePath path to method endpoint - * @param string $method method to call - * @param array $queryParams parameters to be place in query URL - * @param array $postData parameters to be placed in POST body - * @param array $headerParams parameters to be place in request header - * @param string $responseType expected response type of the endpoint - * @param string $endpointPath path to method endpoint before expanding parameters - * - * @throws \RadioManager\ApiException on a non 2xx response - * @return mixed - */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType = null, $endpointPath = null) - { - $headers = []; - - // construct the http header - $headerParams = array_merge( - (array)$this->config->getDefaultHeaders(), - (array)$headerParams - ); - - foreach ($headerParams as $key => $val) { - $headers[] = "$key: $val"; - } - - // form data - if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers, true)) { - $postData = http_build_query($postData); - } elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers, true)) { // json model - $postData = json_encode(\RadioManager\ObjectSerializer::sanitizeForSerialization($postData)); - } - - $url = $this->config->getHost() . $resourcePath; - - $curl = curl_init(); - // set timeout, if needed - if ($this->config->getCurlTimeout() !== 0) { - curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); - } - // set connect timeout, if needed - if ($this->config->getCurlConnectTimeout() != 0) { - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->config->getCurlConnectTimeout()); - } - - // return the result on success, rather than just true - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - // disable SSL verification, if needed - if ($this->config->getSSLVerification() === false) { - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); - } - - if ($this->config->getCurlProxyHost()) { - curl_setopt($curl, CURLOPT_PROXY, $this->config->getCurlProxyHost()); - } - - if ($this->config->getCurlProxyPort()) { - curl_setopt($curl, CURLOPT_PROXYPORT, $this->config->getCurlProxyPort()); - } - - if ($this->config->getCurlProxyType()) { - curl_setopt($curl, CURLOPT_PROXYTYPE, $this->config->getCurlProxyType()); - } - - if ($this->config->getCurlProxyUser()) { - curl_setopt($curl, CURLOPT_PROXYUSERPWD, $this->config->getCurlProxyUser() . ':' .$this->config->getCurlProxyPassword()); - } - - if (!empty($queryParams)) { - $url = ($url . '?' . http_build_query($queryParams)); - } - - if ($this->config->getAllowEncoding()) { - curl_setopt($curl, CURLOPT_ENCODING, ''); - } - - if ($method === self::$POST) { - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method === self::$HEAD) { - curl_setopt($curl, CURLOPT_NOBODY, true); - } elseif ($method === self::$OPTIONS) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method === self::$PATCH) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method === self::$PUT) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method === self::$DELETE) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } elseif ($method !== self::$GET) { - throw new ApiException('Method ' . $method . ' is not recognized.'); - } - curl_setopt($curl, CURLOPT_URL, $url); - - // Set user agent - curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent()); - - // debugging for curl - if ($this->config->getDebug()) { - error_log("[DEBUG] HTTP Request body ~BEGIN~".PHP_EOL.print_r($postData, true).PHP_EOL."~END~".PHP_EOL, 3, $this->config->getDebugFile()); - - curl_setopt($curl, CURLOPT_VERBOSE, 1); - curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a')); - } else { - curl_setopt($curl, CURLOPT_VERBOSE, 0); - } - - // obtain the HTTP response headers - curl_setopt($curl, CURLOPT_HEADER, 1); - - // Make the request - $response = curl_exec($curl); - $http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); - $http_header = $this->httpParseHeaders(substr($response, 0, $http_header_size)); - $http_body = substr($response, $http_header_size); - $response_info = curl_getinfo($curl); - - // debug HTTP response body - if ($this->config->getDebug()) { - error_log("[DEBUG] HTTP Response body ~BEGIN~".PHP_EOL.print_r($http_body, true).PHP_EOL."~END~".PHP_EOL, 3, $this->config->getDebugFile()); - } - - // Handle the response - if ($response_info['http_code'] === 0) { - $curl_error_message = curl_error($curl); - - // curl_exec can sometimes fail but still return a blank message from curl_error(). - if (!empty($curl_error_message)) { - $error_message = "API call to $url failed: $curl_error_message"; - } else { - $error_message = "API call to $url failed, but for an unknown reason. " . - "This could happen if you are disconnected from the network."; - } - - $exception = new ApiException($error_message, 0, null, null); - $exception->setResponseObject($response_info); - throw $exception; - } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299) { - // return raw body if response is a file - if ($responseType === '\SplFileObject' || $responseType === 'string') { - return [$http_body, $response_info['http_code'], $http_header]; - } - - $data = json_decode($http_body); - if (json_last_error() > 0) { // if response is a string - $data = $http_body; - } - } else { - $data = json_decode($http_body); - if (json_last_error() > 0) { // if response is a string - $data = $http_body; - } - - throw new ApiException( - "[".$response_info['http_code']."] Error connecting to the API ($url)", - $response_info['http_code'], - $http_header, - $data - ); - } - return [$data, $response_info['http_code'], $http_header]; - } - - /** - * Return the header 'Accept' based on an array of Accept provided - * - * @param string[] $accept Array of header - * - * @return string Accept (e.g. application/json) - */ - public function selectHeaderAccept($accept) - { - if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) { - return null; - } elseif (preg_grep("/application\/json/i", $accept)) { - return 'application/json'; - } else { - return implode(',', $accept); - } - } - - /** - * Return the content type based on an array of content-type provided - * - * @param string[] $content_type Array fo content-type - * - * @return string Content-Type (e.g. application/json) - */ - public function selectHeaderContentType($content_type) - { - if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) { - return 'application/json'; - } elseif (preg_grep("/application\/json/i", $content_type)) { - return 'application/json'; - } else { - return implode(',', $content_type); - } - } - - /** - * Return an array of HTTP response headers - * - * @param string $raw_headers A string of raw HTTP response headers - * - * @return string[] Array of HTTP response heaers - */ - protected function httpParseHeaders($raw_headers) - { - // ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986 - $headers = []; - $key = ''; - - foreach (explode("\n", $raw_headers) as $h) { - $h = explode(':', $h, 2); - - if (isset($h[1])) { - if (!isset($headers[$h[0]])) { - $headers[$h[0]] = trim($h[1]); - } elseif (is_array($headers[$h[0]])) { - $headers[$h[0]] = array_merge($headers[$h[0]], [trim($h[1])]); - } else { - $headers[$h[0]] = array_merge([$headers[$h[0]]], [trim($h[1])]); - } - - $key = $h[0]; - } else { - if (substr($h[0], 0, 1) === "\t") { - $headers[$key] .= "\r\n\t".trim($h[0]); - } elseif (!$key) { - $headers[0] = trim($h[0]); - } - trim($h[0]); - } - } - - return $headers; - } -} diff --git a/lib/ApiException.php b/lib/ApiException.php index fdae2d7..9b0b5bb 100644 --- a/lib/ApiException.php +++ b/lib/ApiException.php @@ -51,7 +51,7 @@ class ApiException extends Exception /** * The HTTP header of the server response. * - * @var string[] + * @var string[]|null */ protected $responseHeaders; @@ -65,10 +65,10 @@ class ApiException extends Exception /** * Constructor * - * @param string $message Error message - * @param int $code HTTP status code - * @param string[] $responseHeaders HTTP response header - * @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string + * @param string $message Error message + * @param int $code HTTP status code + * @param string[]|null $responseHeaders HTTP response header + * @param mixed $responseBody HTTP decoded body of the server response either as \stdClass or string */ public function __construct($message = "", $code = 0, $responseHeaders = [], $responseBody = null) { @@ -80,7 +80,7 @@ public function __construct($message = "", $code = 0, $responseHeaders = [], $re /** * Gets the HTTP response header * - * @return string[] HTTP response headers + * @return string[]|null HTTP response header */ public function getResponseHeaders() { diff --git a/lib/Configuration.php b/lib/Configuration.php index 7f91600..7c0d8e1 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -76,33 +76,12 @@ class Configuration */ protected $password = ''; - /** - * The default header(s) - * - * @var array - */ - protected $defaultHeaders = []; - /** * The host * * @var string */ - protected $host = 'https://staging.radiomanager.pluxbox.com/api/v2'; - - /** - * Timeout (second) of the HTTP request, by default set to 0, no timeout - * - * @var string - */ - protected $curlTimeout = 0; - - /** - * Timeout (second) of the HTTP connection, by default set to 0, no timeout - * - * @var string - */ - protected $curlConnectTimeout = 0; + protected $host = 'http://radiomanager.pb/api/v2'; /** * User agent of the HTTP request, set to "PHP-Swagger" by default @@ -132,58 +111,6 @@ class Configuration */ protected $tempFolderPath; - /** - * Indicates if SSL verification should be enabled or disabled. - * - * This is useful if the host uses a self-signed SSL certificate. - * - * @var boolean True if the certificate should be validated, false otherwise. - */ - protected $sslVerification = true; - - /** - * Curl proxy host - * - * @var string - */ - protected $proxyHost; - - /** - * Curl proxy port - * - * @var integer - */ - protected $proxyPort; - - /** - * Curl proxy type, e.g. CURLPROXY_HTTP or CURLPROXY_SOCKS5 - * - * @see https://secure.php.net/manual/en/function.curl-setopt.php - * @var integer - */ - protected $proxyType; - - /** - * Curl proxy username - * - * @var string - */ - protected $proxyUser; - - /** - * Curl proxy password - * - * @var string - */ - protected $proxyPassword; - - /** - * Allow Curl encoding header - * - * @var bool - */ - protected $allowEncoding = false; - /** * Constructor */ @@ -313,48 +240,6 @@ public function getPassword() return $this->password; } - /** - * Adds a default header - * - * @param string $headerName header name (e.g. Token) - * @param string $headerValue header value (e.g. 1z8wp3) - * - * @throws \InvalidArgumentException - * @return $this - */ - public function addDefaultHeader($headerName, $headerValue) - { - if (!is_string($headerName)) { - throw new \InvalidArgumentException('Header name must be a string.'); - } - - $this->defaultHeaders[$headerName] = $headerValue; - return $this; - } - - /** - * Gets the default header - * - * @return array An array of default header(s) - */ - public function getDefaultHeaders() - { - return $this->defaultHeaders; - } - - /** - * Deletes a default header - * - * @param string $headerName the header to delete - * - * @return $this - */ - public function deleteDefaultHeader($headerName) - { - unset($this->defaultHeaders[$headerName]); - return $this; - } - /** * Sets the host * @@ -406,197 +291,6 @@ public function getUserAgent() return $this->userAgent; } - /** - * Sets the HTTP timeout value - * - * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] - * - * @throws \InvalidArgumentException - * @return $this - */ - public function setCurlTimeout($seconds) - { - if (!is_numeric($seconds) || $seconds < 0) { - throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); - } - - $this->curlTimeout = $seconds; - return $this; - } - - /** - * Gets the HTTP timeout value - * - * @return string HTTP timeout value - */ - public function getCurlTimeout() - { - return $this->curlTimeout; - } - - /** - * Sets the HTTP connect timeout value - * - * @param integer $seconds Number of seconds before connection times out [set to 0 for no timeout] - * - * @throws \InvalidArgumentException - * @return $this - */ - public function setCurlConnectTimeout($seconds) - { - if (!is_numeric($seconds) || $seconds < 0) { - throw new \InvalidArgumentException('Connect timeout value must be numeric and a non-negative number.'); - } - - $this->curlConnectTimeout = $seconds; - return $this; - } - - /** - * Set whether to accept encoding - * @param bool $allowEncoding - */ - public function setAllowEncoding($allowEncoding) - { - $this->allowEncoding = $allowEncoding; - return $this; - } - - /** - * Gets the HTTP connect timeout value - * - * @return string HTTP connect timeout value - */ - public function getCurlConnectTimeout() - { - return $this->curlConnectTimeout; - } - - /** - * Get whether to allow encoding - * - * @return bool - */ - public function getAllowEncoding() - { - return $this->allowEncoding; - } - - /** - * Sets the HTTP Proxy Host - * - * @param string $proxyHost HTTP Proxy URL - * - * @return $this - */ - public function setCurlProxyHost($proxyHost) - { - $this->proxyHost = $proxyHost; - return $this; - } - - /** - * Gets the HTTP Proxy Host - * - * @return string - */ - public function getCurlProxyHost() - { - return $this->proxyHost; - } - - /** - * Sets the HTTP Proxy Port - * - * @param integer $proxyPort HTTP Proxy Port - * - * @return $this - */ - public function setCurlProxyPort($proxyPort) - { - $this->proxyPort = $proxyPort; - return $this; - } - - /** - * Gets the HTTP Proxy Port - * - * @return integer - */ - public function getCurlProxyPort() - { - return $this->proxyPort; - } - - /** - * Sets the HTTP Proxy Type - * - * @param integer $proxyType HTTP Proxy Type - * - * @return $this - */ - public function setCurlProxyType($proxyType) - { - $this->proxyType = $proxyType; - return $this; - } - - /** - * Gets the HTTP Proxy Type - * - * @return integer - */ - public function getCurlProxyType() - { - return $this->proxyType; - } - - /** - * Sets the HTTP Proxy User - * - * @param string $proxyUser HTTP Proxy User - * - * @return $this - */ - public function setCurlProxyUser($proxyUser) - { - $this->proxyUser = $proxyUser; - return $this; - } - - /** - * Gets the HTTP Proxy User - * - * @return string - */ - public function getCurlProxyUser() - { - return $this->proxyUser; - } - - /** - * Sets the HTTP Proxy Password - * - * @param string $proxyPassword HTTP Proxy Password - * - * @return $this - */ - public function setCurlProxyPassword($proxyPassword) - { - $this->proxyPassword = $proxyPassword; - return $this; - } - - /** - * Gets the HTTP Proxy Password - * - * @return string - */ - public function getCurlProxyPassword() - { - return $this->proxyPassword; - } - /** * Sets debug flag * @@ -666,29 +360,6 @@ public function getTempFolderPath() return $this->tempFolderPath; } - /** - * Sets if SSL verification should be enabled or disabled - * - * @param boolean $sslVerification True if the certificate should be validated, false otherwise - * - * @return $this - */ - public function setSSLVerification($sslVerification) - { - $this->sslVerification = $sslVerification; - return $this; - } - - /** - * Gets if SSL verification should be enabled or disabled - * - * @return boolean True if the certificate should be validated, false otherwise - */ - public function getSSLVerification() - { - return $this->sslVerification; - } - /** * Gets the default configuration instance * @@ -730,4 +401,29 @@ public static function toDebugReport() return $report; } + + /** + * Get API key (with prefix if set) + * + * @param string $apiKeyIdentifier name of apikey + * + * @return string API key with the prefix + */ + public function getApiKeyWithPrefix($apiKeyIdentifier) + { + $prefix = $this->getApiKeyPrefix($apiKeyIdentifier); + $apiKey = $this->getApiKey($apiKeyIdentifier); + + if ($apiKey === null) { + return null; + } + + if ($prefix === null) { + $keyWithPrefix = $apiKey; + } else { + $keyWithPrefix = $prefix . ' ' . $apiKey; + } + + return $keyWithPrefix; + } } diff --git a/lib/HeaderSelector.php b/lib/HeaderSelector.php new file mode 100644 index 0000000..225d2f5 --- /dev/null +++ b/lib/HeaderSelector.php @@ -0,0 +1,110 @@ +selectAcceptHeader($accept); + if ($accept !== null) { + $headers['Accept'] = $accept; + } + + $headers['Content-Type'] = $this->selectContentTypeHeader($contentTypes); + return $headers; + } + + /** + * @param string[] $accept + * @return array + */ + public function selectHeadersForMultipart($accept) + { + $headers = $this->selectHeaders($accept, []); + + unset($headers['Content-Type']); + return $headers; + } + + /** + * Return the header 'Accept' based on an array of Accept provided + * + * @param string[] $accept Array of header + * + * @return string Accept (e.g. application/json) + */ + private function selectAcceptHeader($accept) + { + if (count($accept) === 0 || (count($accept) === 1 && $accept[0] === '')) { + return null; + } elseif (preg_grep("/application\/json/i", $accept)) { + return 'application/json'; + } else { + return implode(',', $accept); + } + } + + /** + * Return the content type based on an array of content-type provided + * + * @param string[] $contentType Array fo content-type + * + * @return string Content-Type (e.g. application/json) + */ + private function selectContentTypeHeader($contentType) + { + if (count($contentType) === 0 || (count($contentType) === 1 && $contentType[0] === '')) { + return 'application/json'; + } elseif (preg_grep("/application\/json/i", $contentType)) { + return 'application/json'; + } else { + return implode(',', $contentType); + } + } +} + diff --git a/lib/Model/Broadcast.php b/lib/Model/Broadcast.php index f837279..480c9c4 100644 --- a/lib/Model/Broadcast.php +++ b/lib/Model/Broadcast.php @@ -74,7 +74,7 @@ class Broadcast implements ArrayAccess 'repetition_type' => 'string', 'repetition_end' => '\DateTime', 'repetition_start' => '\DateTime', - 'repetition_days' => 'bool[]', + 'repetition_days' => 'string', 'pty_code_id' => 'int' ]; @@ -754,7 +754,7 @@ public function setRepetitionStart($repetition_start) /** * Gets repetition_days - * @return bool[] + * @return string */ public function getRepetitionDays() { @@ -763,7 +763,7 @@ public function getRepetitionDays() /** * Sets repetition_days - * @param bool[] $repetition_days + * @param string $repetition_days * @return $this */ public function setRepetitionDays($repetition_days) diff --git a/lib/Model/BroadcastDataInput.php b/lib/Model/BroadcastDataInput.php index 9af7f1b..2143dc7 100644 --- a/lib/Model/BroadcastDataInput.php +++ b/lib/Model/BroadcastDataInput.php @@ -74,7 +74,7 @@ class BroadcastDataInput implements ArrayAccess 'repetition_type' => 'string', 'repetition_end' => '\DateTime', 'repetition_start' => '\DateTime', - 'repetition_days' => 'bool[]', + 'repetition_days' => 'string', 'pty_code_id' => 'int', 'tags' => 'int[]', 'presenters' => 'int[]' @@ -766,7 +766,7 @@ public function setRepetitionStart($repetition_start) /** * Gets repetition_days - * @return bool[] + * @return string */ public function getRepetitionDays() { @@ -775,7 +775,7 @@ public function getRepetitionDays() /** * Sets repetition_days - * @param bool[] $repetition_days + * @param string $repetition_days * @return $this */ public function setRepetitionDays($repetition_days) diff --git a/lib/Model/BroadcastResult.php b/lib/Model/BroadcastResult.php index 7d1c2db..3311fff 100644 --- a/lib/Model/BroadcastResult.php +++ b/lib/Model/BroadcastResult.php @@ -79,7 +79,7 @@ class BroadcastResult implements ArrayAccess 'repetition_type' => 'string', 'repetition_end' => '\DateTime', 'repetition_start' => '\DateTime', - 'repetition_days' => 'bool[]', + 'repetition_days' => 'string', 'pty_code_id' => 'int', 'items' => '\RadioManager\Model\BroadcastRelationsItems', 'blocks' => '\RadioManager\Model\BroadcastRelationsBlocks', @@ -949,7 +949,7 @@ public function setRepetitionStart($repetition_start) /** * Gets repetition_days - * @return bool[] + * @return string */ public function getRepetitionDays() { @@ -958,7 +958,7 @@ public function getRepetitionDays() /** * Sets repetition_days - * @param bool[] $repetition_days + * @param string $repetition_days * @return $this */ public function setRepetitionDays($repetition_days) diff --git a/lib/Model/StoryDataInput.php b/lib/Model/StoryDataInput.php index 1c9d0a8..41b9e21 100644 --- a/lib/Model/StoryDataInput.php +++ b/lib/Model/StoryDataInput.php @@ -58,7 +58,8 @@ class StoryDataInput implements ArrayAccess 'recommended' => 'bool', 'field_values' => 'object', 'name' => 'string', - 'description' => 'string' + 'description' => 'string', + 'tags' => 'int[]' ]; /** @@ -70,7 +71,8 @@ class StoryDataInput implements ArrayAccess 'recommended' => null, 'field_values' => null, 'name' => null, - 'description' => null + 'description' => null, + 'tags' => null ]; public static function swaggerTypes() @@ -92,7 +94,8 @@ public static function swaggerFormats() 'recommended' => 'recommended', 'field_values' => 'field_values', 'name' => 'name', - 'description' => 'description' + 'description' => 'description', + 'tags' => 'tags' ]; @@ -105,7 +108,8 @@ public static function swaggerFormats() 'recommended' => 'setRecommended', 'field_values' => 'setFieldValues', 'name' => 'setName', - 'description' => 'setDescription' + 'description' => 'setDescription', + 'tags' => 'setTags' ]; @@ -118,7 +122,8 @@ public static function swaggerFormats() 'recommended' => 'getRecommended', 'field_values' => 'getFieldValues', 'name' => 'getName', - 'description' => 'getDescription' + 'description' => 'getDescription', + 'tags' => 'getTags' ]; public static function attributeMap() @@ -157,6 +162,7 @@ public function __construct(array $data = null) $this->container['field_values'] = isset($data['field_values']) ? $data['field_values'] : null; $this->container['name'] = isset($data['name']) ? $data['name'] : null; $this->container['description'] = isset($data['description']) ? $data['description'] : null; + $this->container['tags'] = isset($data['tags']) ? $data['tags'] : null; } /** @@ -300,6 +306,27 @@ public function setDescription($description) return $this; } + + /** + * Gets tags + * @return int[] + */ + public function getTags() + { + return $this->container['tags']; + } + + /** + * Sets tags + * @param int[] $tags + * @return $this + */ + public function setTags($tags) + { + $this->container['tags'] = $tags; + + return $this; + } /** * Returns true if offset exists. False otherwise. * @param integer $offset Offset diff --git a/lib/Model/StoryInputOnly.php b/lib/Model/StoryInputOnly.php new file mode 100644 index 0000000..42814a4 --- /dev/null +++ b/lib/Model/StoryInputOnly.php @@ -0,0 +1,242 @@ + 'int[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'tags' => null + ]; + + public static function swaggerTypes() + { + return self::$swaggerTypes; + } + + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + + /** + * Array of attributes where the key is the local name, and the value is the original name + * @var string[] + */ + protected static $attributeMap = [ + 'tags' => 'tags' + ]; + + + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ + protected static $setters = [ + 'tags' => 'setTags' + ]; + + + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ + protected static $getters = [ + 'tags' => 'getTags' + ]; + + public static function attributeMap() + { + return self::$attributeMap; + } + + public static function setters() + { + return self::$setters; + } + + public static function getters() + { + return self::$getters; + } + + + + + + /** + * Associative array for storing property values + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * @param mixed[] $data Associated array of property values initializing the model + */ + public function __construct(array $data = null) + { + $this->container['tags'] = isset($data['tags']) ? $data['tags'] : null; + } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalid_properties = []; + + return $invalid_properties; + } + + /** + * validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + + return true; + } + + + /** + * Gets tags + * @return int[] + */ + public function getTags() + { + return $this->container['tags']; + } + + /** + * Sets tags + * @param int[] $tags + * @return $this + */ + public function setTags($tags) + { + $this->container['tags'] = $tags; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } + + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { + if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print + return json_encode(\RadioManager\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); + } + + return json_encode(\RadioManager\ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/ObjectSerializer.php b/lib/ObjectSerializer.php index f5db154..e7b538a 100644 --- a/lib/ObjectSerializer.php +++ b/lib/ObjectSerializer.php @@ -88,7 +88,7 @@ public static function sanitizeForSerialization($data, $type = null, $format = n * * @return string the sanitized filename */ - public function sanitizeFilename($filename) + public static function sanitizeFilename($filename) { if (preg_match("/.*[\/\\\\](.*)$/", $filename, $match)) { return $match[1]; @@ -105,9 +105,9 @@ public function sanitizeFilename($filename) * * @return string the serialized object */ - public function toPathValue($value) + public static function toPathValue($value) { - return rawurlencode($this->toString($value)); + return rawurlencode(self::toString($value)); } /** @@ -120,12 +120,12 @@ public function toPathValue($value) * * @return string the serialized object */ - public function toQueryValue($object) + public static function toQueryValue($object) { if (is_array($object)) { return implode(',', $object); } else { - return $this->toString($object); + return self::toString($object); } } @@ -138,9 +138,9 @@ public function toQueryValue($object) * * @return string the header string */ - public function toHeaderValue($value) + public static function toHeaderValue($value) { - return $this->toString($value); + return self::toString($value); } /** @@ -152,12 +152,12 @@ public function toHeaderValue($value) * * @return string the form string */ - public function toFormValue($value) + public static function toFormValue($value) { if ($value instanceof \SplFileObject) { return $value->getRealPath(); } else { - return $this->toString($value); + return self::toString($value); } } @@ -170,7 +170,7 @@ public function toFormValue($value) * * @return string the header string */ - public function toString($value) + public static function toString($value) { if ($value instanceof \DateTime) { // datetime in ISO8601 format return $value->format(\DateTime::ATOM); @@ -189,7 +189,7 @@ public function toString($value) * * @return string */ - public function serializeCollection(array $collection, $collectionFormat, $allowCollectionFormatMulti = false) + public static function serializeCollection(array $collection, $collectionFormat, $allowCollectionFormatMulti = false) { if ($allowCollectionFormatMulti && ('multi' === $collectionFormat)) { // http_build_query() almost does the job for us. We just @@ -264,20 +264,23 @@ public static function deserialize($data, $class, $httpHeaders = null) settype($data, $class); return $data; } elseif ($class === '\SplFileObject') { + /** @var \Psr\Http\Message\StreamInterface $data */ + // determine file name if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) { - $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . sanitizeFilename($match[1]); + $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . self::sanitizeFilename($match[1]); } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); } - $deserialized = new \SplFileObject($filename, "w"); - $byte_written = $deserialized->fwrite($data); - if (Configuration::getDefaultConfiguration()->getDebug()) { - error_log("[DEBUG] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.".PHP_EOL, 3, Configuration::getDefaultConfiguration()->getDebugFile()); + + $file = fopen($filename, 'w'); + while ($chunk = $data->read(200)) { + fwrite($file, $chunk); } + fclose($file); - return $deserialized; + return new \SplFileObject($filename, 'r'); } elseif (method_exists($class, 'getAllowableEnumValues')) { if (!in_array($data, $class::getAllowableEnumValues())) { $imploded = implode("', '", $class::getAllowableEnumValues()); diff --git a/test/Api/BlockApiTest.php b/test/Api/BlockApiTest.php index 0c03656..b546770 100644 --- a/test/Api/BlockApiTest.php +++ b/test/Api/BlockApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/BroadcastApiTest.php b/test/Api/BroadcastApiTest.php index cef1896..c3b1854 100644 --- a/test/Api/BroadcastApiTest.php +++ b/test/Api/BroadcastApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/CampaignApiTest.php b/test/Api/CampaignApiTest.php index 2a7a595..4135de8 100644 --- a/test/Api/CampaignApiTest.php +++ b/test/Api/CampaignApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/ContactApiTest.php b/test/Api/ContactApiTest.php index 2bcf265..8720d5f 100644 --- a/test/Api/ContactApiTest.php +++ b/test/Api/ContactApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/ExternalMessageApiTest.php b/test/Api/ExternalMessageApiTest.php index 4e38de8..7aefc35 100644 --- a/test/Api/ExternalMessageApiTest.php +++ b/test/Api/ExternalMessageApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/GenreApiTest.php b/test/Api/GenreApiTest.php index 3fff553..02725ed 100644 --- a/test/Api/GenreApiTest.php +++ b/test/Api/GenreApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/ItemApiTest.php b/test/Api/ItemApiTest.php index d31f83c..622b17f 100644 --- a/test/Api/ItemApiTest.php +++ b/test/Api/ItemApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/ModelTypeApiTest.php b/test/Api/ModelTypeApiTest.php index 74d718e..81fef01 100644 --- a/test/Api/ModelTypeApiTest.php +++ b/test/Api/ModelTypeApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/PresenterApiTest.php b/test/Api/PresenterApiTest.php index 008014f..e96bca7 100644 --- a/test/Api/PresenterApiTest.php +++ b/test/Api/PresenterApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/ProgramApiTest.php b/test/Api/ProgramApiTest.php index 8a425b7..9a31736 100644 --- a/test/Api/ProgramApiTest.php +++ b/test/Api/ProgramApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/StoryApiTest.php b/test/Api/StoryApiTest.php index a8d979a..224e407 100644 --- a/test/Api/StoryApiTest.php +++ b/test/Api/StoryApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/StringApiTest.php b/test/Api/StringApiTest.php index 4a17036..64ad8cc 100644 --- a/test/Api/StringApiTest.php +++ b/test/Api/StringApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/TagApiTest.php b/test/Api/TagApiTest.php index 3d2c6d8..8a80e67 100644 --- a/test/Api/TagApiTest.php +++ b/test/Api/TagApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/UserApiTest.php b/test/Api/UserApiTest.php index cc3e567..9c65cfd 100644 --- a/test/Api/UserApiTest.php +++ b/test/Api/UserApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Api/VisualSlideApiTest.php b/test/Api/VisualSlideApiTest.php index a03fcec..bedf5e2 100644 --- a/test/Api/VisualSlideApiTest.php +++ b/test/Api/VisualSlideApiTest.php @@ -29,7 +29,6 @@ namespace RadioManager; use \RadioManager\Configuration; -use \RadioManager\ApiClient; use \RadioManager\ApiException; use \RadioManager\ObjectSerializer; diff --git a/test/Model/StoryDataInputTest.php b/test/Model/StoryDataInputTest.php index 12b9a87..bb3e989 100644 --- a/test/Model/StoryDataInputTest.php +++ b/test/Model/StoryDataInputTest.php @@ -111,4 +111,11 @@ public function testPropertyName() public function testPropertyDescription() { } + + /** + * Test attribute "tags" + */ + public function testPropertyTags() + { + } } diff --git a/test/Model/StoryInputOnlyTest.php b/test/Model/StoryInputOnlyTest.php new file mode 100644 index 0000000..6aa7429 --- /dev/null +++ b/test/Model/StoryInputOnlyTest.php @@ -0,0 +1,86 @@ +