From d5b6b1e8035f5a63a63ac7c79ab3839a6d62bb57 Mon Sep 17 00:00:00 2001 From: Jonathan Batscha <61248025+jon-batscha@users.noreply.github.com> Date: Tue, 29 Mar 2022 22:49:21 -0600 Subject: [PATCH] initial commit --- LICENSE | 21 + README.md | 991 ++++ composer.json | 40 + composer.sh | 5 + demo.php | 8 + lib/API/CampaignsApi.php | 2995 +++++++++++ lib/API/DataPrivacyApi.php | 415 ++ lib/API/ListsSegmentsApi.php | 4646 ++++++++++++++++++ lib/API/MetricsApi.php | 1518 ++++++ lib/API/ProfilesApi.php | 1708 +++++++ lib/API/TemplatesApi.php | 2291 +++++++++ lib/API/TrackIdentifyApi.php | 1262 +++++ lib/ApiException.php | 120 + lib/Client.php | 50 + lib/Configuration.php | 486 ++ lib/HeaderSelector.php | 108 + lib/Model/Campaign.php | 620 +++ lib/Model/CheckMembershipRequest.php | 380 ++ lib/Model/DeleteEmail.php | 320 ++ lib/Model/DeletePerson.php | 320 ++ lib/Model/DeletePhone.php | 320 ++ lib/Model/DeprecatedGetListResponse.php | 515 ++ lib/Model/DeprecatedGetListResponseData.php | 470 ++ lib/Model/GlobalExclusionResponseData.php | 500 ++ lib/Model/IdentifyPayload.php | 356 ++ lib/Model/IdentifyPayloadProperties.php | 680 +++ lib/Model/InlineObject.php | 320 ++ lib/Model/InlineObject3.php | 324 ++ lib/Model/InlineObject4.php | 339 ++ lib/Model/InlineObject5.php | 408 ++ lib/Model/Metric.php | 470 ++ lib/Model/MetricExport.php | 530 ++ lib/Model/MetricTimeline.php | 425 ++ lib/Model/MetricTimelineData.php | 560 +++ lib/Model/ModelInterface.php | 95 + lib/Model/Person.php | 860 ++++ lib/Model/PrivacyEmail.php | 320 ++ lib/Model/PrivacyId.php | 320 ++ lib/Model/PrivacyPhone.php | 320 ++ lib/Model/RenderedTemplate.php | 410 ++ lib/Model/Template.php | 500 ++ lib/Model/TrackPayload.php | 419 ++ lib/Model/TrackPayloadCustomerProperties.php | 350 ++ lib/Model/TrackPayloadProperties.php | 380 ++ lib/ObjectSerializer.php | 415 ++ lib/Subclient.php | 74 + 46 files changed, 28984 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 composer.json create mode 100644 composer.sh create mode 100644 demo.php create mode 100644 lib/API/CampaignsApi.php create mode 100644 lib/API/DataPrivacyApi.php create mode 100644 lib/API/ListsSegmentsApi.php create mode 100644 lib/API/MetricsApi.php create mode 100644 lib/API/ProfilesApi.php create mode 100644 lib/API/TemplatesApi.php create mode 100644 lib/API/TrackIdentifyApi.php create mode 100644 lib/ApiException.php create mode 100644 lib/Client.php create mode 100644 lib/Configuration.php create mode 100644 lib/HeaderSelector.php create mode 100644 lib/Model/Campaign.php create mode 100644 lib/Model/CheckMembershipRequest.php create mode 100644 lib/Model/DeleteEmail.php create mode 100644 lib/Model/DeletePerson.php create mode 100644 lib/Model/DeletePhone.php create mode 100644 lib/Model/DeprecatedGetListResponse.php create mode 100644 lib/Model/DeprecatedGetListResponseData.php create mode 100644 lib/Model/GlobalExclusionResponseData.php create mode 100644 lib/Model/IdentifyPayload.php create mode 100644 lib/Model/IdentifyPayloadProperties.php create mode 100644 lib/Model/InlineObject.php create mode 100644 lib/Model/InlineObject3.php create mode 100644 lib/Model/InlineObject4.php create mode 100644 lib/Model/InlineObject5.php create mode 100644 lib/Model/Metric.php create mode 100644 lib/Model/MetricExport.php create mode 100644 lib/Model/MetricTimeline.php create mode 100644 lib/Model/MetricTimelineData.php create mode 100644 lib/Model/ModelInterface.php create mode 100644 lib/Model/Person.php create mode 100644 lib/Model/PrivacyEmail.php create mode 100644 lib/Model/PrivacyId.php create mode 100644 lib/Model/PrivacyPhone.php create mode 100644 lib/Model/RenderedTemplate.php create mode 100644 lib/Model/Template.php create mode 100644 lib/Model/TrackPayload.php create mode 100644 lib/Model/TrackPayloadCustomerProperties.php create mode 100644 lib/Model/TrackPayloadProperties.php create mode 100644 lib/ObjectSerializer.php create mode 100644 lib/Subclient.php diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5b1cc13 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Klaviyo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8d567f0 --- /dev/null +++ b/README.md @@ -0,0 +1,991 @@ +# Klaviyo PHP SDK + +- SDK version: 1.0.0.20220329 + +## Helpful Resources + +- [API Reference](https://developers.klaviyo.com/en/reference/api-overview) +- [API Guides](https://developers.klaviyo.com/en/docs) +- [Postman Workspace](https://www.postman.com/klaviyo/workspace/klaviyo-developers) + +## Design & Approach + +This SDK is a thin wrapper around our API. See our API Reference for full documentation on API behavior. + +This SDK mirrors the organization and naming convention of the above language-agnostic resources, with a few namespace changes to conform to PHP idioms (details in Appendix). + +## Organization + +This SDK is organized into the following resources: + + + +- Campaigns + + + +- DataPrivacy + + + +- ListsSegments + + + +- Metrics + + + +- Profiles + + + +- Templates + + + +- TrackIdentify + + + +# Installation + +You can install this package using either [Packagist](https://packagist.org/packages/klaviyo/sdk), or the source code. + +## Option 1: Packagist + +You can install this library using Packagist. + +### optional 1a: with composer installed + +If you have composer installed, you can run: `composer require klaviyo/sdk` + +### optional 1b: without composer installed + +If you don't have composer installed, you can get an executable version by running `bash composer.sh` + +This will download an executable version of composer that you can use by running `php composer.phar` wherever you would otherwise run `composer`. + +You can then install the library from Packagist by running `php composer.phar require klaviyo/sdk` + +## Option 2: Source code + +You can also install this library directly from source code, without using the Packagist package, as follows: + +1. cloning this repo +2. running `bash composer.json` + +# Usage Example + +```php +Metrics->getMetrics(); +``` + +# Retry behavior + +* The SDK retries on resolvable errors, namely: rate limits (common) and server errors on Klaviyo's end (rare). +* The keyword arguments in the example above define retry behavior + * `wait_seconds` denotes how long to wait per retry, in *seconds* + * If you wish to disable retries, set `$num_retries = 0` + * the example is populated with the default values +* non-resolvable errors and resolvable errors which have timed out throw an `ApiException`, detailed below. + +# Error Handling + +This SDK throws an `ApiException` error when the server returns a non resolvable response, or a resolvable non-`2XX` response times out. + +If you'd like to extend error handling beyond what the SDK supports natively, you can use the following methods to retrieve the corresponding attributes from the `ApiException` object: + +* `getCode() : int` +* `getMessage() : str` +* `getReponseBody() : bytes` +* `getResponseHeaders() : string[]` + +For example: + +```php +try { + $client.Metrics.getMetrics(); +} catch (Exception $e) { + if ($e->getCode() == SOME_INTEGER) { + doSomething(); + } +} +``` + +# Comprehensive list of Operations & Parameters + +_**NOTE:**_ +- Organization: Resource groups and functions are listed in alphabetical order, first by Resource name, then by **OpenAPI Summary**. Operation summaries are those listed in the right side bar of the [API Reference](https://developers.klaviyo.com/en/reference/track-post). These summaries link directly to the corresponding section of the API reference. +- For example values / data types, as well as whether parameters are required/optional, please reference the corresponding API Reference link. +- Some keyword args are required for the API call to succeed, the API docs above are the source of truth regarding which keyword args are required. +- Keyword args are not included in the sample SDK calls; instead, where applicable, they are included as comments above each SDK call. +- JSON payloads should be passed in as associative arrays +- A strange quirk of PHP is that default/optional arguments must be passed in in order, and MUST be included and set as `null`, at least up to the last default value you wish to use. + - For example, if a given function has the following optional parameters `someFunction($a=1, $b=2, $c=3)`, and you wish to only set `$b`, you MUST pass in `someFunction($a=null, $b=$YOUR_VALUE)` + - Otherwise, if you pass in something such as `someFunction($b=$YOUR_VALUE)`, PHP will actually assign the `$YOUR_VALUE` to parameter `$a`, which is wrong. + + + + + +## Campaigns + +#### [Cancel a Campaign](https://developers.klaviyo.com/en/reference/cancel-campaign) + +```php +## Positional Arguments + +# $campaign_id | string + + +client->Campaigns->cancelCampaign($campaign_id); +``` + + + + + +#### [Clone a Campaign](https://developers.klaviyo.com/en/reference/clone-campaign) + +```php +## Positional Arguments + +# $campaign_id | string +# $name | string +# $list_id | string + + +client->Campaigns->cloneCampaign($campaign_id, $name, $list_id); +``` + + + + + +#### [Create New Campaign](https://developers.klaviyo.com/en/reference/create-campaign) + +```php +## Positional Arguments + +# $list_id | string +# $template_id | string +# $from_email | string +# $from_name | string +# $subject | string + +## Keyword Arguments + +# $name | string +# $use_smart_sending | bool +# $add_google_analytics | bool + +client->Campaigns->createCampaign($list_id, $template_id, $from_email, $from_name, $subject); +``` + + + + + +#### [Get Campaign Info](https://developers.klaviyo.com/en/reference/get-campaign-info) + +```php +## Positional Arguments + +# $campaign_id | string + + +client->Campaigns->getCampaignInfo($campaign_id); +``` + + + + + +#### [Get Campaign Recipients](https://developers.klaviyo.com/en/reference/get-campaign-recipients) + +```php +## Positional Arguments + +# $campaign_id | string + +## Keyword Arguments + +# $count | int +# $sort | string +# $offset | string + +client->Campaigns->getCampaignRecipients($campaign_id); +``` + + + + + +#### [Get Campaigns](https://developers.klaviyo.com/en/reference/get-campaigns) + +```php + +## Keyword Arguments + +# $page | int +# $count | int + +client->Campaigns->getCampaigns(); +``` + + + + + +#### [Schedule a Campaign](https://developers.klaviyo.com/en/reference/schedule-campaign) + +```php +## Positional Arguments + +# $campaign_id | string +# $send_time | string + + +client->Campaigns->scheduleCampaign($campaign_id, $send_time); +``` + + + + + +#### [Send a Campaign Immediately](https://developers.klaviyo.com/en/reference/send-campaign) + +```php +## Positional Arguments + +# $campaign_id | string + + +client->Campaigns->sendCampaign($campaign_id); +``` + + + + + +#### [Update Campaign](https://developers.klaviyo.com/en/reference/update-campaign) + +```php +## Positional Arguments + +# $campaign_id | string + +## Keyword Arguments + +# $list_id | string +# $template_id | string +# $from_email | string +# $from_name | string +# $subject | string +# $name | string +# $use_smart_sending | bool +# $add_google_analytics | bool + +client->Campaigns->updateCampaign($campaign_id); +``` + + + + + + + +## DataPrivacy + +#### [Request a Deletion](https://developers.klaviyo.com/en/reference/request-deletion) + +```php + +## Keyword Arguments + +# $body | array + +client->DataPrivacy->requestDeletion(); +``` + + + + + + + +## ListsSegments + +#### [Add Members to a List](https://developers.klaviyo.com/en/reference/add-members) + +```php +## Positional Arguments + +# $list_id | string + +## Keyword Arguments + +# $body | array + +client->ListsSegments->addMembers($list_id); +``` + + + + + +#### [Create List](https://developers.klaviyo.com/en/reference/create-list) + +```php +## Positional Arguments + +# $list_name | string + + +client->ListsSegments->createList($list_name); +``` + + + + + +#### [Delete List](https://developers.klaviyo.com/en/reference/delete-list) + +```php +## Positional Arguments + +# $list_id | string + + +client->ListsSegments->deleteList($list_id); +``` + + + + + +#### [Exclude Profile From All Email](https://developers.klaviyo.com/en/reference/exclude-globally) + +```php +## Positional Arguments + +# $email | string + + +client->ListsSegments->excludeGlobally($email); +``` + + + + + +#### [Get Global Exclusions & Unsubscribes](https://developers.klaviyo.com/en/reference/get-global-exclusions) + +```php + +## Keyword Arguments + +# $reason | string +# $sort | string +# $count | int +# $page | int + +client->ListsSegments->getGlobalExclusions(); +``` + + + + + +#### [Get All Exclusions for a List](https://developers.klaviyo.com/en/reference/get-list-exclusions) + +```php +## Positional Arguments + +# $list_id | string + +## Keyword Arguments + +# $marker | int + +client->ListsSegments->getListExclusions($list_id); +``` + + + + + +#### [Get List Info](https://developers.klaviyo.com/en/reference/get-list-info) + +```php +## Positional Arguments + +# $list_id | string + + +client->ListsSegments->getListInfo($list_id); +``` + + + + + +#### [Check if Profiles Are in a List](https://developers.klaviyo.com/en/reference/get-list-members) + +```php +## Positional Arguments + +# $list_id | string + +## Keyword Arguments + +# $body | array + +client->ListsSegments->getListMembers($list_id); +``` + + + + + +#### [Check if Profiles Are in a List and not Suppressed](https://developers.klaviyo.com/en/reference/get-list-subscriptions) + +```php +## Positional Arguments + +# $list_id | string + +## Keyword Arguments + +# $body | array + +client->ListsSegments->getListSubscriptions($list_id); +``` + + + + + +#### [Get Lists](https://developers.klaviyo.com/en/reference/get-lists) + +```php + + +client->ListsSegments->getLists(); +``` + + + + + +#### [Get List and Segment Members](https://developers.klaviyo.com/en/reference/get-members) + +```php +## Positional Arguments + +# $list_or_segment_id | string + +## Keyword Arguments + +# $marker | int + +client->ListsSegments->getMembers($list_or_segment_id); +``` + + + + + +#### [Check if Profiles Are in a Segment](https://developers.klaviyo.com/en/reference/get-segment-members) + +```php +## Positional Arguments + +# $segment_id | string + +## Keyword Arguments + +# $body | array + +client->ListsSegments->getSegmentMembers($segment_id); +``` + + + + + +#### [Remove Profiles From List](https://developers.klaviyo.com/en/reference/remove-members) + +```php +## Positional Arguments + +# $list_id | string + +## Keyword Arguments + +# $body | array + +client->ListsSegments->removeMembers($list_id); +``` + + + + + +#### [Subscribe Profiles to List](https://developers.klaviyo.com/en/reference/subscribe) + +```php +## Positional Arguments + +# $list_id | string + +## Keyword Arguments + +# $body | array + +client->ListsSegments->subscribe($list_id); +``` + + + + + +#### [Unsubscribe Profiles From List](https://developers.klaviyo.com/en/reference/unsubscribe) + +```php +## Positional Arguments + +# $list_id | string + +## Keyword Arguments + +# $body | array + +client->ListsSegments->unsubscribe($list_id); +``` + + + + + +#### [Update List Name](https://developers.klaviyo.com/en/reference/update-list-name) + +```php +## Positional Arguments + +# $list_id | string +# $list_name | string + + +client->ListsSegments->updateListName($list_id, $list_name); +``` + + + + + + + +## Metrics + +#### [Get Metrics Info](https://developers.klaviyo.com/en/reference/get-metrics) + +```php + +## Keyword Arguments + +# $page | int +# $count | int + +client->Metrics->getMetrics(); +``` + + + + + +#### [Query Event Data](https://developers.klaviyo.com/en/reference/metric-export) + +```php +## Positional Arguments + +# $metric_id | string + +## Keyword Arguments + +# $start_date | string +# $end_date | string +# $unit | string +# $measurement | string +# $where | string +# $by | string +# $count | int + +client->Metrics->metricExport($metric_id); +``` + + + + + +#### [Get Events for a Specific Metric](https://developers.klaviyo.com/en/reference/metric-timeline) + +```php +## Positional Arguments + +# $metric_id | string + +## Keyword Arguments + +# $since | string +# $count | int +# $sort | string + +client->Metrics->metricTimeline($metric_id); +``` + + + + + +#### [Get Events for All Metrics](https://developers.klaviyo.com/en/reference/metrics-timeline) + +```php + +## Keyword Arguments + +# $since | string +# $count | int +# $sort | string + +client->Metrics->metricsTimeline(); +``` + + + + + + + +## Profiles + +#### [Exchange ID for Profile ID](https://developers.klaviyo.com/en/reference/exchange) + +```php + +## Keyword Arguments + +# $body | array + +client->Profiles->exchange(); +``` + + + + + +#### [Get Profile](https://developers.klaviyo.com/en/reference/get-profile) + +```php +## Positional Arguments + +# $person_id | string + + +client->Profiles->getProfile($person_id); +``` + + + + + +#### [Get Profile's Events for a Specific Metric](https://developers.klaviyo.com/en/reference/profile-metric-timeline) + +```php +## Positional Arguments + +# $person_id | string +# $metric_id | string + +## Keyword Arguments + +# $since | string +# $count | int +# $sort | string + +client->Profiles->profileMetricTimeline($person_id, $metric_id); +``` + + + + + +#### [Get Profile's Events for all Metrics](https://developers.klaviyo.com/en/reference/profile-metrics-timeline) + +```php +## Positional Arguments + +# $person_id | string + +## Keyword Arguments + +# $since | string +# $count | int +# $sort | string + +client->Profiles->profileMetricsTimeline($person_id); +``` + + + + + +#### [Update Profile](https://developers.klaviyo.com/en/reference/update-profile) + +```php +## Positional Arguments + +# $person_id | string + +## Keyword Arguments + +# $params | array<string,object> + +client->Profiles->updateProfile($person_id); +``` + + + + + + + +## Templates + +#### [Clone Template](https://developers.klaviyo.com/en/reference/clone-template) + +```php +## Positional Arguments + +# $template_id | string +# $name | string + + +client->Templates->cloneTemplate($template_id, $name); +``` + + + + + +#### [Create New Template](https://developers.klaviyo.com/en/reference/create-template) + +```php +## Positional Arguments + +# $name | string +# $html | string + + +client->Templates->createTemplate($name, $html); +``` + + + + + +#### [Delete Template](https://developers.klaviyo.com/en/reference/delete-template) + +```php +## Positional Arguments + +# $template_id | string + + +client->Templates->deleteTemplate($template_id); +``` + + + + + +#### [Get All Templates](https://developers.klaviyo.com/en/reference/get-templates) + +```php + +## Keyword Arguments + +# $page | int +# $count | int + +client->Templates->getTemplates(); +``` + + + + + +#### [Render Template](https://developers.klaviyo.com/en/reference/render-template) + +```php +## Positional Arguments + +# $template_id | string + +## Keyword Arguments + +# $context | string + +client->Templates->renderTemplate($template_id); +``` + + + + + +#### [Render and Send Template](https://developers.klaviyo.com/en/reference/send-template) + +```php +## Positional Arguments + +# $template_id | string +# $from_email | string +# $from_name | string +# $subject | string +# $to | string + +## Keyword Arguments + +# $context | string + +client->Templates->sendTemplate($template_id, $from_email, $from_name, $subject, $to); +``` + + + + + +#### [Update Template](https://developers.klaviyo.com/en/reference/update-template) + +```php +## Positional Arguments + +# $template_id | string + +## Keyword Arguments + +# $name | string +# $html | string + +client->Templates->updateTemplate($template_id); +``` + + + + + + + +## TrackIdentify + +#### [Identify Profile (Legacy)](https://developers.klaviyo.com/en/reference/identify-get) + +```php +## Positional Arguments + +# $data | string + + +client->TrackIdentify->identifyGet($data); +``` + + + + + +#### [Identify Profile](https://developers.klaviyo.com/en/reference/identify-post) + +```php +## Positional Arguments + +# $data | string + + +client->TrackIdentify->identifyPost($data); +``` + + + + + +#### [Track Profile Activity (Legacy)](https://developers.klaviyo.com/en/reference/track-get) + +```php +## Positional Arguments + +# $data | string + + +client->TrackIdentify->trackGet($data); +``` + + + + + +#### [Track Profile Activity](https://developers.klaviyo.com/en/reference/track-post) + +```php +## Positional Arguments + +# $data | string + + +client->TrackIdentify->trackPost($data); +``` + + + + + + +# Appendix + +## Limitations + +- The `api_key` is set at the global level: this means that if you manage multiple stores, you will need to run the code for each store in a different environment + +## Namespace + +In the interest of making the SDK conform to PHP idioms, we made the following namespace changes *relative* to the language agnostic resources up top (API Docs, Guides, etc). + +- non-alphanumeric symbols (spaces, dashes, underscore, ampersand etc) stripped from resource names (tags) and function names (operation IDs) +- Resource names and function names use camelCase +- NOTE: this does not apply to parameter names + +For example: +* `Track & Identify` becomes `TrackIdentify` +* `get-campaigns` becomes `getCampaigns` +* `profile_id` *remains* unchanged + +## Parameters & Arguments + +The parameters follow the same naming conventions as the resource groups and operations. + +We stick to the following convention for parameters/arguments + +1. All parameters are passed as function args. +2. All optional params, as well as all Body and Form Data params (including required ones), are passed as keyword args. +3. All query and path params that are tagged as `required` in the docs are passed as positional args. +4. There is no need to pass in your private `api_key` for any operations, as it is defined upon client instantiation; public key is still required where noted for Track/Identify endpoints. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..4e73ef9 --- /dev/null +++ b/composer.json @@ -0,0 +1,40 @@ +{ + "name" : "klaviyo/sdk", + "type": "library", + "description": "Empowering creators to own their destiny", + "keywords": [ + "klaviyo", + "php", + "sdk", + "rest", + "api", + "email", + "sms" + ], + "homepage": "https://developers.klaviyo.com/en", + "license": "MIT", + "authors": [ + { + "name": "Klaviyo", + "homepage": "https://developers.klaviyo.com/en" + } + ], + "require": { + "php": "^7.3 || ^8.0", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "guzzlehttp/guzzle": "^7.3", + "guzzlehttp/psr7": "^1.7 || ^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.0 || ^9.0", + "friendsofphp/php-cs-fixer": "^2.12" + }, + "autoload": { + "psr-4": { "Klaviyo\\" : "lib/" } + }, + "autoload-dev": { + "psr-4": { "Klaviyo\\Test\\" : "test/" } + } +} diff --git a/composer.sh b/composer.sh new file mode 100644 index 0000000..01bdb0d --- /dev/null +++ b/composer.sh @@ -0,0 +1,5 @@ +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" +php composer-setup.php +php -r "unlink('composer-setup.php');" +php composer.phar install diff --git a/demo.php b/demo.php new file mode 100644 index 0000000..d6f4c02 --- /dev/null +++ b/demo.php @@ -0,0 +1,8 @@ +Metrics->getMetrics()); \ No newline at end of file diff --git a/lib/API/CampaignsApi.php b/lib/API/CampaignsApi.php new file mode 100644 index 0000000..ae52cd7 --- /dev/null +++ b/lib/API/CampaignsApi.php @@ -0,0 +1,2995 @@ +client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation cancelCampaign + * + * Cancel a Campaign + * + * @param string $campaign_id campaign_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function cancelCampaign($campaign_id) + { + list($response) = $this->cancelCampaignWithHttpInfo($campaign_id); + return $response; + } + + /** + * Operation cancelCampaignWithHttpInfo + * + * Cancel a Campaign + * + * @param string $campaign_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function cancelCampaignWithHttpInfo($campaign_id) + { + $request = $this->cancelCampaignRequest($campaign_id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation cancelCampaignAsync + * + * Cancel a Campaign + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function cancelCampaignAsync($campaign_id) + { + return $this->cancelCampaignAsyncWithHttpInfo($campaign_id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation cancelCampaignAsyncWithHttpInfo + * + * Cancel a Campaign + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function cancelCampaignAsyncWithHttpInfo($campaign_id) + { + $returnType = 'array'; + $request = $this->cancelCampaignRequest($campaign_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'cancelCampaign' + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function cancelCampaignRequest($campaign_id) + { + // verify the required parameter 'campaign_id' is set + if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $campaign_id when calling cancelCampaign' + ); + } + + $resourcePath = '/v1/campaign/{campaign_id}/cancel'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($campaign_id !== null) { + $resourcePath = str_replace( + '{' . 'campaign_id' . '}', + ObjectSerializer::toPathValue($campaign_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation cloneCampaign + * + * Clone a Campaign + * + * @param string $campaign_id campaign_id (required) + * @param string $name The name for the new campaign. All other properties of the campaign will remain the same. Note, the template for the new campaign will be cloned from the existing template so changes to the existing campaign's content will not alter the content of the new campaign. (required) + * @param string $list_id The list you will send the campaign to. (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function cloneCampaign($campaign_id, $name, $list_id) + { + list($response) = $this->cloneCampaignWithHttpInfo($campaign_id, $name, $list_id); + return $response; + } + + /** + * Operation cloneCampaignWithHttpInfo + * + * Clone a Campaign + * + * @param string $campaign_id (required) + * @param string $name The name for the new campaign. All other properties of the campaign will remain the same. Note, the template for the new campaign will be cloned from the existing template so changes to the existing campaign's content will not alter the content of the new campaign. (required) + * @param string $list_id The list you will send the campaign to. (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function cloneCampaignWithHttpInfo($campaign_id, $name, $list_id) + { + $request = $this->cloneCampaignRequest($campaign_id, $name, $list_id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation cloneCampaignAsync + * + * Clone a Campaign + * + * @param string $campaign_id (required) + * @param string $name The name for the new campaign. All other properties of the campaign will remain the same. Note, the template for the new campaign will be cloned from the existing template so changes to the existing campaign's content will not alter the content of the new campaign. (required) + * @param string $list_id The list you will send the campaign to. (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function cloneCampaignAsync($campaign_id, $name, $list_id) + { + return $this->cloneCampaignAsyncWithHttpInfo($campaign_id, $name, $list_id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation cloneCampaignAsyncWithHttpInfo + * + * Clone a Campaign + * + * @param string $campaign_id (required) + * @param string $name The name for the new campaign. All other properties of the campaign will remain the same. Note, the template for the new campaign will be cloned from the existing template so changes to the existing campaign's content will not alter the content of the new campaign. (required) + * @param string $list_id The list you will send the campaign to. (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function cloneCampaignAsyncWithHttpInfo($campaign_id, $name, $list_id) + { + $returnType = 'array'; + $request = $this->cloneCampaignRequest($campaign_id, $name, $list_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'cloneCampaign' + * + * @param string $campaign_id (required) + * @param string $name The name for the new campaign. All other properties of the campaign will remain the same. Note, the template for the new campaign will be cloned from the existing template so changes to the existing campaign's content will not alter the content of the new campaign. (required) + * @param string $list_id The list you will send the campaign to. (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function cloneCampaignRequest($campaign_id, $name, $list_id) + { + // verify the required parameter 'campaign_id' is set + if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $campaign_id when calling cloneCampaign' + ); + } + // verify the required parameter 'name' is set + if ($name === null || (is_array($name) && count($name) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $name when calling cloneCampaign' + ); + } + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling cloneCampaign' + ); + } + + $resourcePath = '/v1/campaign/{campaign_id}/clone'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($campaign_id !== null) { + $resourcePath = str_replace( + '{' . 'campaign_id' . '}', + ObjectSerializer::toPathValue($campaign_id), + $resourcePath + ); + } + + // form params + if ($name !== null) { + $formParams['name'] = ObjectSerializer::toFormValue($name); + } + // form params + if ($list_id !== null) { + $formParams['list_id'] = ObjectSerializer::toFormValue($list_id); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation createCampaign + * + * Create New Campaign + * + * @param string $list_id The list you will send the campaign to. (required) + * @param string $template_id The template that will define the content of the page. Note: the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (required) + * @param string $from_email The email address your email will be sent from and will be used in the `reply-to` header. (required) + * @param string $from_name The name or label associated with the email address you're sending from. (required) + * @param string $subject The email subject of the campaign (required) + * @param string $name If not specified, this will default to the subject of the campaign. (optional, default to 'Campaign Name') + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Valid values are `true` and `false`. If not specified, defaults to `true`. (optional, default to true) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Valid values are `true` and `false`. If not specified, defaults to `false`. (optional, default to false) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function createCampaign($list_id, $template_id, $from_email, $from_name, $subject, $name = 'Campaign Name', $use_smart_sending = true, $add_google_analytics = false) + { + list($response) = $this->createCampaignWithHttpInfo($list_id, $template_id, $from_email, $from_name, $subject, $name, $use_smart_sending, $add_google_analytics); + return $response; + } + + /** + * Operation createCampaignWithHttpInfo + * + * Create New Campaign + * + * @param string $list_id The list you will send the campaign to. (required) + * @param string $template_id The template that will define the content of the page. Note: the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (required) + * @param string $from_email The email address your email will be sent from and will be used in the `reply-to` header. (required) + * @param string $from_name The name or label associated with the email address you're sending from. (required) + * @param string $subject The email subject of the campaign (required) + * @param string $name If not specified, this will default to the subject of the campaign. (optional, default to 'Campaign Name') + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Valid values are `true` and `false`. If not specified, defaults to `true`. (optional, default to true) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Valid values are `true` and `false`. If not specified, defaults to `false`. (optional, default to false) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function createCampaignWithHttpInfo($list_id, $template_id, $from_email, $from_name, $subject, $name = 'Campaign Name', $use_smart_sending = true, $add_google_analytics = false) + { + $request = $this->createCampaignRequest($list_id, $template_id, $from_email, $from_name, $subject, $name, $use_smart_sending, $add_google_analytics); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createCampaignAsync + * + * Create New Campaign + * + * @param string $list_id The list you will send the campaign to. (required) + * @param string $template_id The template that will define the content of the page. Note: the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (required) + * @param string $from_email The email address your email will be sent from and will be used in the `reply-to` header. (required) + * @param string $from_name The name or label associated with the email address you're sending from. (required) + * @param string $subject The email subject of the campaign (required) + * @param string $name If not specified, this will default to the subject of the campaign. (optional, default to 'Campaign Name') + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Valid values are `true` and `false`. If not specified, defaults to `true`. (optional, default to true) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Valid values are `true` and `false`. If not specified, defaults to `false`. (optional, default to false) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createCampaignAsync($list_id, $template_id, $from_email, $from_name, $subject, $name = 'Campaign Name', $use_smart_sending = true, $add_google_analytics = false) + { + return $this->createCampaignAsyncWithHttpInfo($list_id, $template_id, $from_email, $from_name, $subject, $name, $use_smart_sending, $add_google_analytics) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation createCampaignAsyncWithHttpInfo + * + * Create New Campaign + * + * @param string $list_id The list you will send the campaign to. (required) + * @param string $template_id The template that will define the content of the page. Note: the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (required) + * @param string $from_email The email address your email will be sent from and will be used in the `reply-to` header. (required) + * @param string $from_name The name or label associated with the email address you're sending from. (required) + * @param string $subject The email subject of the campaign (required) + * @param string $name If not specified, this will default to the subject of the campaign. (optional, default to 'Campaign Name') + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Valid values are `true` and `false`. If not specified, defaults to `true`. (optional, default to true) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Valid values are `true` and `false`. If not specified, defaults to `false`. (optional, default to false) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createCampaignAsyncWithHttpInfo($list_id, $template_id, $from_email, $from_name, $subject, $name = 'Campaign Name', $use_smart_sending = true, $add_google_analytics = false) + { + $returnType = 'array'; + $request = $this->createCampaignRequest($list_id, $template_id, $from_email, $from_name, $subject, $name, $use_smart_sending, $add_google_analytics); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'createCampaign' + * + * @param string $list_id The list you will send the campaign to. (required) + * @param string $template_id The template that will define the content of the page. Note: the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (required) + * @param string $from_email The email address your email will be sent from and will be used in the `reply-to` header. (required) + * @param string $from_name The name or label associated with the email address you're sending from. (required) + * @param string $subject The email subject of the campaign (required) + * @param string $name If not specified, this will default to the subject of the campaign. (optional, default to 'Campaign Name') + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Valid values are `true` and `false`. If not specified, defaults to `true`. (optional, default to true) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Valid values are `true` and `false`. If not specified, defaults to `false`. (optional, default to false) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function createCampaignRequest($list_id, $template_id, $from_email, $from_name, $subject, $name = 'Campaign Name', $use_smart_sending = true, $add_google_analytics = false) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling createCampaign' + ); + } + // verify the required parameter 'template_id' is set + if ($template_id === null || (is_array($template_id) && count($template_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $template_id when calling createCampaign' + ); + } + // verify the required parameter 'from_email' is set + if ($from_email === null || (is_array($from_email) && count($from_email) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $from_email when calling createCampaign' + ); + } + // verify the required parameter 'from_name' is set + if ($from_name === null || (is_array($from_name) && count($from_name) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $from_name when calling createCampaign' + ); + } + // verify the required parameter 'subject' is set + if ($subject === null || (is_array($subject) && count($subject) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $subject when calling createCampaign' + ); + } + + $resourcePath = '/v1/campaigns'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + // form params + if ($list_id !== null) { + $formParams['list_id'] = ObjectSerializer::toFormValue($list_id); + } + // form params + if ($template_id !== null) { + $formParams['template_id'] = ObjectSerializer::toFormValue($template_id); + } + // form params + if ($from_email !== null) { + $formParams['from_email'] = ObjectSerializer::toFormValue($from_email); + } + // form params + if ($from_name !== null) { + $formParams['from_name'] = ObjectSerializer::toFormValue($from_name); + } + // form params + if ($subject !== null) { + $formParams['subject'] = ObjectSerializer::toFormValue($subject); + } + // form params + if ($name !== null) { + $formParams['name'] = ObjectSerializer::toFormValue($name); + } + // form params + if ($use_smart_sending !== null) { + $formParams['use_smart_sending'] = ObjectSerializer::toFormValue($use_smart_sending); + } + // form params + if ($add_google_analytics !== null) { + $formParams['add_google_analytics'] = ObjectSerializer::toFormValue($add_google_analytics); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getCampaignInfo + * + * Get Campaign Info + * + * @param string $campaign_id campaign_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getCampaignInfo($campaign_id) + { + list($response) = $this->getCampaignInfoWithHttpInfo($campaign_id); + return $response; + } + + /** + * Operation getCampaignInfoWithHttpInfo + * + * Get Campaign Info + * + * @param string $campaign_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getCampaignInfoWithHttpInfo($campaign_id) + { + $request = $this->getCampaignInfoRequest($campaign_id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getCampaignInfoAsync + * + * Get Campaign Info + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCampaignInfoAsync($campaign_id) + { + return $this->getCampaignInfoAsyncWithHttpInfo($campaign_id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getCampaignInfoAsyncWithHttpInfo + * + * Get Campaign Info + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCampaignInfoAsyncWithHttpInfo($campaign_id) + { + $returnType = 'array'; + $request = $this->getCampaignInfoRequest($campaign_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getCampaignInfo' + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getCampaignInfoRequest($campaign_id) + { + // verify the required parameter 'campaign_id' is set + if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $campaign_id when calling getCampaignInfo' + ); + } + + $resourcePath = '/v1/campaign/{campaign_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($campaign_id !== null) { + $resourcePath = str_replace( + '{' . 'campaign_id' . '}', + ObjectSerializer::toPathValue($campaign_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getCampaignRecipients + * + * Get Campaign Recipients + * + * @param string $campaign_id campaign_id (required) + * @param int $count For pagination, the number of results to return. Max = 25,000 (optional, default to 5000) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param string $offset For pagination, if a response to this endpoint includes a `next_offset`, use that value to get the next page of recipients. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getCampaignRecipients($campaign_id, $count = 5000, $sort = 'asc', $offset = null) + { + list($response) = $this->getCampaignRecipientsWithHttpInfo($campaign_id, $count, $sort, $offset); + return $response; + } + + /** + * Operation getCampaignRecipientsWithHttpInfo + * + * Get Campaign Recipients + * + * @param string $campaign_id (required) + * @param int $count For pagination, the number of results to return. Max = 25,000 (optional, default to 5000) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param string $offset For pagination, if a response to this endpoint includes a `next_offset`, use that value to get the next page of recipients. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getCampaignRecipientsWithHttpInfo($campaign_id, $count = 5000, $sort = 'asc', $offset = null) + { + $request = $this->getCampaignRecipientsRequest($campaign_id, $count, $sort, $offset); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getCampaignRecipientsAsync + * + * Get Campaign Recipients + * + * @param string $campaign_id (required) + * @param int $count For pagination, the number of results to return. Max = 25,000 (optional, default to 5000) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param string $offset For pagination, if a response to this endpoint includes a `next_offset`, use that value to get the next page of recipients. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCampaignRecipientsAsync($campaign_id, $count = 5000, $sort = 'asc', $offset = null) + { + return $this->getCampaignRecipientsAsyncWithHttpInfo($campaign_id, $count, $sort, $offset) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getCampaignRecipientsAsyncWithHttpInfo + * + * Get Campaign Recipients + * + * @param string $campaign_id (required) + * @param int $count For pagination, the number of results to return. Max = 25,000 (optional, default to 5000) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param string $offset For pagination, if a response to this endpoint includes a `next_offset`, use that value to get the next page of recipients. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCampaignRecipientsAsyncWithHttpInfo($campaign_id, $count = 5000, $sort = 'asc', $offset = null) + { + $returnType = 'array'; + $request = $this->getCampaignRecipientsRequest($campaign_id, $count, $sort, $offset); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getCampaignRecipients' + * + * @param string $campaign_id (required) + * @param int $count For pagination, the number of results to return. Max = 25,000 (optional, default to 5000) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param string $offset For pagination, if a response to this endpoint includes a `next_offset`, use that value to get the next page of recipients. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getCampaignRecipientsRequest($campaign_id, $count = 5000, $sort = 'asc', $offset = null) + { + // verify the required parameter 'campaign_id' is set + if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $campaign_id when calling getCampaignRecipients' + ); + } + if ($count !== null && $count > 25000) { + throw new \InvalidArgumentException('invalid value for "$count" when calling CampaignsApi.getCampaignRecipients, must be smaller than or equal to 25000.'); + } + + + $resourcePath = '/v1/campaign/{campaign_id}/recipients'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + // query params + if ($sort !== null) { + if('form' === 'form' && is_array($sort)) { + foreach($sort as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['sort'] = $sort; + } + } + // query params + if ($offset !== null) { + if('form' === 'form' && is_array($offset)) { + foreach($offset as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['offset'] = $offset; + } + } + + + // path params + if ($campaign_id !== null) { + $resourcePath = str_replace( + '{' . 'campaign_id' . '}', + ObjectSerializer::toPathValue($campaign_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getCampaigns + * + * Get Campaigns + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getCampaigns($page = 0, $count = 50) + { + list($response) = $this->getCampaignsWithHttpInfo($page, $count); + return $response; + } + + /** + * Operation getCampaignsWithHttpInfo + * + * Get Campaigns + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getCampaignsWithHttpInfo($page = 0, $count = 50) + { + $request = $this->getCampaignsRequest($page, $count); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getCampaignsAsync + * + * Get Campaigns + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCampaignsAsync($page = 0, $count = 50) + { + return $this->getCampaignsAsyncWithHttpInfo($page, $count) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getCampaignsAsyncWithHttpInfo + * + * Get Campaigns + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getCampaignsAsyncWithHttpInfo($page = 0, $count = 50) + { + $returnType = 'array'; + $request = $this->getCampaignsRequest($page, $count); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getCampaigns' + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getCampaignsRequest($page = 0, $count = 50) + { + if ($page !== null && $page < 0) { + throw new \InvalidArgumentException('invalid value for "$page" when calling CampaignsApi.getCampaigns, must be bigger than or equal to 0.'); + } + + if ($count !== null && $count > 100) { + throw new \InvalidArgumentException('invalid value for "$count" when calling CampaignsApi.getCampaigns, must be smaller than or equal to 100.'); + } + if ($count !== null && $count < 1) { + throw new \InvalidArgumentException('invalid value for "$count" when calling CampaignsApi.getCampaigns, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/v1/campaigns'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($page !== null) { + if('form' === 'form' && is_array($page)) { + foreach($page as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['page'] = $page; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + + + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation scheduleCampaign + * + * Schedule a Campaign + * + * @param string $campaign_id campaign_id (required) + * @param string $send_time A timestamp of the format `%Y-%m-%d %H:%M:%S` in the UTC timezone. Ex: `2022-01-13 00:00:00` (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function scheduleCampaign($campaign_id, $send_time) + { + list($response) = $this->scheduleCampaignWithHttpInfo($campaign_id, $send_time); + return $response; + } + + /** + * Operation scheduleCampaignWithHttpInfo + * + * Schedule a Campaign + * + * @param string $campaign_id (required) + * @param string $send_time A timestamp of the format `%Y-%m-%d %H:%M:%S` in the UTC timezone. Ex: `2022-01-13 00:00:00` (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function scheduleCampaignWithHttpInfo($campaign_id, $send_time) + { + $request = $this->scheduleCampaignRequest($campaign_id, $send_time); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation scheduleCampaignAsync + * + * Schedule a Campaign + * + * @param string $campaign_id (required) + * @param string $send_time A timestamp of the format `%Y-%m-%d %H:%M:%S` in the UTC timezone. Ex: `2022-01-13 00:00:00` (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function scheduleCampaignAsync($campaign_id, $send_time) + { + return $this->scheduleCampaignAsyncWithHttpInfo($campaign_id, $send_time) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation scheduleCampaignAsyncWithHttpInfo + * + * Schedule a Campaign + * + * @param string $campaign_id (required) + * @param string $send_time A timestamp of the format `%Y-%m-%d %H:%M:%S` in the UTC timezone. Ex: `2022-01-13 00:00:00` (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function scheduleCampaignAsyncWithHttpInfo($campaign_id, $send_time) + { + $returnType = 'array'; + $request = $this->scheduleCampaignRequest($campaign_id, $send_time); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'scheduleCampaign' + * + * @param string $campaign_id (required) + * @param string $send_time A timestamp of the format `%Y-%m-%d %H:%M:%S` in the UTC timezone. Ex: `2022-01-13 00:00:00` (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function scheduleCampaignRequest($campaign_id, $send_time) + { + // verify the required parameter 'campaign_id' is set + if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $campaign_id when calling scheduleCampaign' + ); + } + // verify the required parameter 'send_time' is set + if ($send_time === null || (is_array($send_time) && count($send_time) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $send_time when calling scheduleCampaign' + ); + } + + $resourcePath = '/v1/campaign/{campaign_id}/schedule'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($campaign_id !== null) { + $resourcePath = str_replace( + '{' . 'campaign_id' . '}', + ObjectSerializer::toPathValue($campaign_id), + $resourcePath + ); + } + + // form params + if ($send_time !== null) { + $formParams['send_time'] = ObjectSerializer::toFormValue($send_time); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation sendCampaign + * + * Send a Campaign Immediately + * + * @param string $campaign_id campaign_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function sendCampaign($campaign_id) + { + list($response) = $this->sendCampaignWithHttpInfo($campaign_id); + return $response; + } + + /** + * Operation sendCampaignWithHttpInfo + * + * Send a Campaign Immediately + * + * @param string $campaign_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function sendCampaignWithHttpInfo($campaign_id) + { + $request = $this->sendCampaignRequest($campaign_id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation sendCampaignAsync + * + * Send a Campaign Immediately + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function sendCampaignAsync($campaign_id) + { + return $this->sendCampaignAsyncWithHttpInfo($campaign_id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation sendCampaignAsyncWithHttpInfo + * + * Send a Campaign Immediately + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function sendCampaignAsyncWithHttpInfo($campaign_id) + { + $returnType = 'array'; + $request = $this->sendCampaignRequest($campaign_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'sendCampaign' + * + * @param string $campaign_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function sendCampaignRequest($campaign_id) + { + // verify the required parameter 'campaign_id' is set + if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $campaign_id when calling sendCampaign' + ); + } + + $resourcePath = '/v1/campaign/{campaign_id}/send'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($campaign_id !== null) { + $resourcePath = str_replace( + '{' . 'campaign_id' . '}', + ObjectSerializer::toPathValue($campaign_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation updateCampaign + * + * Update Campaign + * + * @param string $campaign_id campaign_id (required) + * @param string $list_id The list you will send the campaign to. (optional) + * @param string $template_id The ID of the Email Template object that will be the content of this campaign. Note the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (optional) + * @param string $from_email The email address your email will be sent from and will be used in the reply-to header. (optional) + * @param string $from_name The name or label associated with the email address you're sending from. (optional) + * @param string $subject The email subject of the campaign (optional) + * @param string $name A name for this campaign. If not specified, this will default to the subject of the campaign. (optional) + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Campaigns initially default to `true`. (optional) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Campaigns initially default to `false`. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function updateCampaign($campaign_id, $list_id = null, $template_id = null, $from_email = null, $from_name = null, $subject = null, $name = null, $use_smart_sending = null, $add_google_analytics = null) + { + list($response) = $this->updateCampaignWithHttpInfo($campaign_id, $list_id, $template_id, $from_email, $from_name, $subject, $name, $use_smart_sending, $add_google_analytics); + return $response; + } + + /** + * Operation updateCampaignWithHttpInfo + * + * Update Campaign + * + * @param string $campaign_id (required) + * @param string $list_id The list you will send the campaign to. (optional) + * @param string $template_id The ID of the Email Template object that will be the content of this campaign. Note the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (optional) + * @param string $from_email The email address your email will be sent from and will be used in the reply-to header. (optional) + * @param string $from_name The name or label associated with the email address you're sending from. (optional) + * @param string $subject The email subject of the campaign (optional) + * @param string $name A name for this campaign. If not specified, this will default to the subject of the campaign. (optional) + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Campaigns initially default to `true`. (optional) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Campaigns initially default to `false`. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function updateCampaignWithHttpInfo($campaign_id, $list_id = null, $template_id = null, $from_email = null, $from_name = null, $subject = null, $name = null, $use_smart_sending = null, $add_google_analytics = null) + { + $request = $this->updateCampaignRequest($campaign_id, $list_id, $template_id, $from_email, $from_name, $subject, $name, $use_smart_sending, $add_google_analytics); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation updateCampaignAsync + * + * Update Campaign + * + * @param string $campaign_id (required) + * @param string $list_id The list you will send the campaign to. (optional) + * @param string $template_id The ID of the Email Template object that will be the content of this campaign. Note the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (optional) + * @param string $from_email The email address your email will be sent from and will be used in the reply-to header. (optional) + * @param string $from_name The name or label associated with the email address you're sending from. (optional) + * @param string $subject The email subject of the campaign (optional) + * @param string $name A name for this campaign. If not specified, this will default to the subject of the campaign. (optional) + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Campaigns initially default to `true`. (optional) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Campaigns initially default to `false`. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateCampaignAsync($campaign_id, $list_id = null, $template_id = null, $from_email = null, $from_name = null, $subject = null, $name = null, $use_smart_sending = null, $add_google_analytics = null) + { + return $this->updateCampaignAsyncWithHttpInfo($campaign_id, $list_id, $template_id, $from_email, $from_name, $subject, $name, $use_smart_sending, $add_google_analytics) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation updateCampaignAsyncWithHttpInfo + * + * Update Campaign + * + * @param string $campaign_id (required) + * @param string $list_id The list you will send the campaign to. (optional) + * @param string $template_id The ID of the Email Template object that will be the content of this campaign. Note the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (optional) + * @param string $from_email The email address your email will be sent from and will be used in the reply-to header. (optional) + * @param string $from_name The name or label associated with the email address you're sending from. (optional) + * @param string $subject The email subject of the campaign (optional) + * @param string $name A name for this campaign. If not specified, this will default to the subject of the campaign. (optional) + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Campaigns initially default to `true`. (optional) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Campaigns initially default to `false`. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateCampaignAsyncWithHttpInfo($campaign_id, $list_id = null, $template_id = null, $from_email = null, $from_name = null, $subject = null, $name = null, $use_smart_sending = null, $add_google_analytics = null) + { + $returnType = 'array'; + $request = $this->updateCampaignRequest($campaign_id, $list_id, $template_id, $from_email, $from_name, $subject, $name, $use_smart_sending, $add_google_analytics); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'updateCampaign' + * + * @param string $campaign_id (required) + * @param string $list_id The list you will send the campaign to. (optional) + * @param string $template_id The ID of the Email Template object that will be the content of this campaign. Note the Email Template is copied when creating this campaign, so future changes to that Email Template will not alter the content of this campaign. (optional) + * @param string $from_email The email address your email will be sent from and will be used in the reply-to header. (optional) + * @param string $from_name The name or label associated with the email address you're sending from. (optional) + * @param string $subject The email subject of the campaign (optional) + * @param string $name A name for this campaign. If not specified, this will default to the subject of the campaign. (optional) + * @param bool $use_smart_sending If set, limits the number of emails sent to an individual within a short period. Campaigns initially default to `true`. (optional) + * @param bool $add_google_analytics If specified, adds Google Analytics tracking tags to links. Campaigns initially default to `false`. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function updateCampaignRequest($campaign_id, $list_id = null, $template_id = null, $from_email = null, $from_name = null, $subject = null, $name = null, $use_smart_sending = null, $add_google_analytics = null) + { + // verify the required parameter 'campaign_id' is set + if ($campaign_id === null || (is_array($campaign_id) && count($campaign_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $campaign_id when calling updateCampaign' + ); + } + + $resourcePath = '/v1/campaign/{campaign_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($campaign_id !== null) { + $resourcePath = str_replace( + '{' . 'campaign_id' . '}', + ObjectSerializer::toPathValue($campaign_id), + $resourcePath + ); + } + + // form params + if ($list_id !== null) { + $formParams['list_id'] = ObjectSerializer::toFormValue($list_id); + } + // form params + if ($template_id !== null) { + $formParams['template_id'] = ObjectSerializer::toFormValue($template_id); + } + // form params + if ($from_email !== null) { + $formParams['from_email'] = ObjectSerializer::toFormValue($from_email); + } + // form params + if ($from_name !== null) { + $formParams['from_name'] = ObjectSerializer::toFormValue($from_name); + } + // form params + if ($subject !== null) { + $formParams['subject'] = ObjectSerializer::toFormValue($subject); + } + // form params + if ($name !== null) { + $formParams['name'] = ObjectSerializer::toFormValue($name); + } + // form params + if ($use_smart_sending !== null) { + $formParams['use_smart_sending'] = ObjectSerializer::toFormValue($use_smart_sending); + } + // form params + if ($add_google_analytics !== null) { + $formParams['add_google_analytics'] = ObjectSerializer::toFormValue($add_google_analytics); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'PUT', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/lib/API/DataPrivacyApi.php b/lib/API/DataPrivacyApi.php new file mode 100644 index 0000000..9c4dde7 --- /dev/null +++ b/lib/API/DataPrivacyApi.php @@ -0,0 +1,415 @@ +client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation requestDeletion + * + * Request a Deletion + * + * @param string $body body (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function requestDeletion($body = null) + { + list($response) = $this->requestDeletionWithHttpInfo($body); + return $response; + } + + /** + * Operation requestDeletionWithHttpInfo + * + * Request a Deletion + * + * @param string $body (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function requestDeletionWithHttpInfo($body = null) + { + $request = $this->requestDeletionRequest($body); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation requestDeletionAsync + * + * Request a Deletion + * + * @param string $body (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function requestDeletionAsync($body = null) + { + return $this->requestDeletionAsyncWithHttpInfo($body) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation requestDeletionAsyncWithHttpInfo + * + * Request a Deletion + * + * @param string $body (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function requestDeletionAsyncWithHttpInfo($body = null) + { + $returnType = 'array'; + $request = $this->requestDeletionRequest($body); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'requestDeletion' + * + * @param string $body (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function requestDeletionRequest($body = null) + { + + $resourcePath = '/v2/data-privacy/deletion-request'; + $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($body)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($body)); + } else { + $httpBody = $body; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/lib/API/ListsSegmentsApi.php b/lib/API/ListsSegmentsApi.php new file mode 100644 index 0000000..0407a20 --- /dev/null +++ b/lib/API/ListsSegmentsApi.php @@ -0,0 +1,4646 @@ +client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation addMembers + * + * Add Members to a List + * + * @param string $list_id list_id (required) + * @param \Klaviyo\Model\InlineObject4 $inline_object4 inline_object4 (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function addMembers($list_id, $inline_object4 = null) + { + list($response) = $this->addMembersWithHttpInfo($list_id, $inline_object4); + return $response; + } + + /** + * Operation addMembersWithHttpInfo + * + * Add Members to a List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject4 $inline_object4 (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function addMembersWithHttpInfo($list_id, $inline_object4 = null) + { + $request = $this->addMembersRequest($list_id, $inline_object4); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation addMembersAsync + * + * Add Members to a List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject4 $inline_object4 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function addMembersAsync($list_id, $inline_object4 = null) + { + return $this->addMembersAsyncWithHttpInfo($list_id, $inline_object4) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation addMembersAsyncWithHttpInfo + * + * Add Members to a List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject4 $inline_object4 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function addMembersAsyncWithHttpInfo($list_id, $inline_object4 = null) + { + $returnType = 'array'; + $request = $this->addMembersRequest($list_id, $inline_object4); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'addMembers' + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject4 $inline_object4 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function addMembersRequest($list_id, $inline_object4 = null) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling addMembers' + ); + } + + $resourcePath = '/v2/list/{list_id}/members'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_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($inline_object4)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($inline_object4)); + } else { + $httpBody = $inline_object4; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation createList + * + * Create List + * + * @param string $list_name list_name (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function createList($list_name) + { + list($response) = $this->createListWithHttpInfo($list_name); + return $response; + } + + /** + * Operation createListWithHttpInfo + * + * Create List + * + * @param string $list_name (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function createListWithHttpInfo($list_name) + { + $request = $this->createListRequest($list_name); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createListAsync + * + * Create List + * + * @param string $list_name (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createListAsync($list_name) + { + return $this->createListAsyncWithHttpInfo($list_name) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation createListAsyncWithHttpInfo + * + * Create List + * + * @param string $list_name (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createListAsyncWithHttpInfo($list_name) + { + $returnType = 'array'; + $request = $this->createListRequest($list_name); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'createList' + * + * @param string $list_name (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function createListRequest($list_name) + { + // verify the required parameter 'list_name' is set + if ($list_name === null || (is_array($list_name) && count($list_name) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_name when calling createList' + ); + } + + $resourcePath = '/v2/lists'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + // form params + if ($list_name !== null) { + $formParams['list_name'] = ObjectSerializer::toFormValue($list_name); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation deleteList + * + * Delete List + * + * @param string $list_id list_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return void + */ + public function deleteList($list_id) + { + $this->deleteListWithHttpInfo($list_id); + } + + /** + * Operation deleteListWithHttpInfo + * + * Delete List + * + * @param string $list_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteListWithHttpInfo($list_id) + { + $request = $this->deleteListRequest($list_id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation deleteListAsync + * + * Delete List + * + * @param string $list_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteListAsync($list_id) + { + return $this->deleteListAsyncWithHttpInfo($list_id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation deleteListAsyncWithHttpInfo + * + * Delete List + * + * @param string $list_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteListAsyncWithHttpInfo($list_id) + { + $returnType = ''; + $request = $this->deleteListRequest($list_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'deleteList' + * + * @param string $list_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function deleteListRequest($list_id) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling deleteList' + ); + } + + $resourcePath = '/v2/list/{list_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'DELETE', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation excludeGlobally + * + * Exclude Profile From All Email + * + * @param string $email email (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function excludeGlobally($email) + { + list($response) = $this->excludeGloballyWithHttpInfo($email); + return $response; + } + + /** + * Operation excludeGloballyWithHttpInfo + * + * Exclude Profile From All Email + * + * @param string $email (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function excludeGloballyWithHttpInfo($email) + { + $request = $this->excludeGloballyRequest($email); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation excludeGloballyAsync + * + * Exclude Profile From All Email + * + * @param string $email (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function excludeGloballyAsync($email) + { + return $this->excludeGloballyAsyncWithHttpInfo($email) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation excludeGloballyAsyncWithHttpInfo + * + * Exclude Profile From All Email + * + * @param string $email (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function excludeGloballyAsyncWithHttpInfo($email) + { + $returnType = 'array'; + $request = $this->excludeGloballyRequest($email); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'excludeGlobally' + * + * @param string $email (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function excludeGloballyRequest($email) + { + // verify the required parameter 'email' is set + if ($email === null || (is_array($email) && count($email) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $email when calling excludeGlobally' + ); + } + + $resourcePath = '/v1/people/exclusions'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + // form params + if ($email !== null) { + $formParams['email'] = ObjectSerializer::toFormValue($email); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getGlobalExclusions + * + * Get Global Exclusions & Unsubscribes + * + * @param string $reason Filter results based on the reason for someone being excluded. The possible values are `unsubscribed`, `bounced`, `invalid_email`, `reported_spam` and `manually_excluded`. Only a single value may be specified at a time. Defaults to return all profiles regardless of reason. (optional) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param int $count For pagination, the number of results to return. Default = 500 (optional, default to 500) + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getGlobalExclusions($reason = null, $sort = 'asc', $count = 500, $page = 0) + { + list($response) = $this->getGlobalExclusionsWithHttpInfo($reason, $sort, $count, $page); + return $response; + } + + /** + * Operation getGlobalExclusionsWithHttpInfo + * + * Get Global Exclusions & Unsubscribes + * + * @param string $reason Filter results based on the reason for someone being excluded. The possible values are `unsubscribed`, `bounced`, `invalid_email`, `reported_spam` and `manually_excluded`. Only a single value may be specified at a time. Defaults to return all profiles regardless of reason. (optional) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param int $count For pagination, the number of results to return. Default = 500 (optional, default to 500) + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getGlobalExclusionsWithHttpInfo($reason = null, $sort = 'asc', $count = 500, $page = 0) + { + $request = $this->getGlobalExclusionsRequest($reason, $sort, $count, $page); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getGlobalExclusionsAsync + * + * Get Global Exclusions & Unsubscribes + * + * @param string $reason Filter results based on the reason for someone being excluded. The possible values are `unsubscribed`, `bounced`, `invalid_email`, `reported_spam` and `manually_excluded`. Only a single value may be specified at a time. Defaults to return all profiles regardless of reason. (optional) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param int $count For pagination, the number of results to return. Default = 500 (optional, default to 500) + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getGlobalExclusionsAsync($reason = null, $sort = 'asc', $count = 500, $page = 0) + { + return $this->getGlobalExclusionsAsyncWithHttpInfo($reason, $sort, $count, $page) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getGlobalExclusionsAsyncWithHttpInfo + * + * Get Global Exclusions & Unsubscribes + * + * @param string $reason Filter results based on the reason for someone being excluded. The possible values are `unsubscribed`, `bounced`, `invalid_email`, `reported_spam` and `manually_excluded`. Only a single value may be specified at a time. Defaults to return all profiles regardless of reason. (optional) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param int $count For pagination, the number of results to return. Default = 500 (optional, default to 500) + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getGlobalExclusionsAsyncWithHttpInfo($reason = null, $sort = 'asc', $count = 500, $page = 0) + { + $returnType = 'array'; + $request = $this->getGlobalExclusionsRequest($reason, $sort, $count, $page); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getGlobalExclusions' + * + * @param string $reason Filter results based on the reason for someone being excluded. The possible values are `unsubscribed`, `bounced`, `invalid_email`, `reported_spam` and `manually_excluded`. Only a single value may be specified at a time. Defaults to return all profiles regardless of reason. (optional) + * @param string $sort Sort order to apply to results, either ascending or descending. Valid values are `asc` or `desc`. Defaults to `asc`. (optional, default to 'asc') + * @param int $count For pagination, the number of results to return. Default = 500 (optional, default to 500) + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getGlobalExclusionsRequest($reason = null, $sort = 'asc', $count = 500, $page = 0) + { + + $resourcePath = '/v1/people/exclusions'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($reason !== null) { + if('form' === 'form' && is_array($reason)) { + foreach($reason as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['reason'] = $reason; + } + } + // query params + if ($sort !== null) { + if('form' === 'form' && is_array($sort)) { + foreach($sort as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['sort'] = $sort; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + // query params + if ($page !== null) { + if('form' === 'form' && is_array($page)) { + foreach($page as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['page'] = $page; + } + } + + + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getListExclusions + * + * Get All Exclusions for a List + * + * @param string $list_id list_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getListExclusions($list_id, $marker = null) + { + list($response) = $this->getListExclusionsWithHttpInfo($list_id, $marker); + return $response; + } + + /** + * Operation getListExclusionsWithHttpInfo + * + * Get All Exclusions for a List + * + * @param string $list_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getListExclusionsWithHttpInfo($list_id, $marker = null) + { + $request = $this->getListExclusionsRequest($list_id, $marker); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getListExclusionsAsync + * + * Get All Exclusions for a List + * + * @param string $list_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListExclusionsAsync($list_id, $marker = null) + { + return $this->getListExclusionsAsyncWithHttpInfo($list_id, $marker) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getListExclusionsAsyncWithHttpInfo + * + * Get All Exclusions for a List + * + * @param string $list_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListExclusionsAsyncWithHttpInfo($list_id, $marker = null) + { + $returnType = 'array'; + $request = $this->getListExclusionsRequest($list_id, $marker); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getListExclusions' + * + * @param string $list_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getListExclusionsRequest($list_id, $marker = null) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling getListExclusions' + ); + } + + $resourcePath = '/v2/list/{list_id}/exclusions/all'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($marker !== null) { + if('form' === 'form' && is_array($marker)) { + foreach($marker as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['marker'] = $marker; + } + } + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getListInfo + * + * Get List Info + * + * @param string $list_id list_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getListInfo($list_id) + { + list($response) = $this->getListInfoWithHttpInfo($list_id); + return $response; + } + + /** + * Operation getListInfoWithHttpInfo + * + * Get List Info + * + * @param string $list_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getListInfoWithHttpInfo($list_id) + { + $request = $this->getListInfoRequest($list_id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getListInfoAsync + * + * Get List Info + * + * @param string $list_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListInfoAsync($list_id) + { + return $this->getListInfoAsyncWithHttpInfo($list_id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getListInfoAsyncWithHttpInfo + * + * Get List Info + * + * @param string $list_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListInfoAsyncWithHttpInfo($list_id) + { + $returnType = 'array'; + $request = $this->getListInfoRequest($list_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getListInfo' + * + * @param string $list_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getListInfoRequest($list_id) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling getListInfo' + ); + } + + $resourcePath = '/v2/list/{list_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getListMembers + * + * Check if Profiles Are in a List + * + * @param string $list_id list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request check_membership_request (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getListMembers($list_id, $check_membership_request = null) + { + list($response) = $this->getListMembersWithHttpInfo($list_id, $check_membership_request); + return $response; + } + + /** + * Operation getListMembersWithHttpInfo + * + * Check if Profiles Are in a List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getListMembersWithHttpInfo($list_id, $check_membership_request = null) + { + $request = $this->getListMembersRequest($list_id, $check_membership_request); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getListMembersAsync + * + * Check if Profiles Are in a List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListMembersAsync($list_id, $check_membership_request = null) + { + return $this->getListMembersAsyncWithHttpInfo($list_id, $check_membership_request) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getListMembersAsyncWithHttpInfo + * + * Check if Profiles Are in a List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListMembersAsyncWithHttpInfo($list_id, $check_membership_request = null) + { + $returnType = 'array'; + $request = $this->getListMembersRequest($list_id, $check_membership_request); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getListMembers' + * + * @param string $list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getListMembersRequest($list_id, $check_membership_request = null) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling getListMembers' + ); + } + + $resourcePath = '/v2/list/{list_id}/get-members'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_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($check_membership_request)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($check_membership_request)); + } else { + $httpBody = $check_membership_request; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getListSubscriptions + * + * Check if Profiles Are in a List and not Suppressed + * + * @param string $list_id list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request check_membership_request (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getListSubscriptions($list_id, $check_membership_request = null) + { + list($response) = $this->getListSubscriptionsWithHttpInfo($list_id, $check_membership_request); + return $response; + } + + /** + * Operation getListSubscriptionsWithHttpInfo + * + * Check if Profiles Are in a List and not Suppressed + * + * @param string $list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getListSubscriptionsWithHttpInfo($list_id, $check_membership_request = null) + { + $request = $this->getListSubscriptionsRequest($list_id, $check_membership_request); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getListSubscriptionsAsync + * + * Check if Profiles Are in a List and not Suppressed + * + * @param string $list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListSubscriptionsAsync($list_id, $check_membership_request = null) + { + return $this->getListSubscriptionsAsyncWithHttpInfo($list_id, $check_membership_request) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getListSubscriptionsAsyncWithHttpInfo + * + * Check if Profiles Are in a List and not Suppressed + * + * @param string $list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListSubscriptionsAsyncWithHttpInfo($list_id, $check_membership_request = null) + { + $returnType = 'array'; + $request = $this->getListSubscriptionsRequest($list_id, $check_membership_request); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getListSubscriptions' + * + * @param string $list_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getListSubscriptionsRequest($list_id, $check_membership_request = null) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling getListSubscriptions' + ); + } + + $resourcePath = '/v2/list/{list_id}/get-list-subscriptions'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_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($check_membership_request)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($check_membership_request)); + } else { + $httpBody = $check_membership_request; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getLists + * + * Get Lists + * + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getLists() + { + list($response) = $this->getListsWithHttpInfo(); + return $response; + } + + /** + * Operation getListsWithHttpInfo + * + * Get Lists + * + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getListsWithHttpInfo() + { + $request = $this->getListsRequest(); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getListsAsync + * + * Get Lists + * + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListsAsync() + { + return $this->getListsAsyncWithHttpInfo() + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getListsAsyncWithHttpInfo + * + * Get Lists + * + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getListsAsyncWithHttpInfo() + { + $returnType = 'array'; + $request = $this->getListsRequest(); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getLists' + * + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getListsRequest() + { + + $resourcePath = '/v2/lists'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getMembers + * + * Get List and Segment Members + * + * @param string $list_or_segment_id list_or_segment_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getMembers($list_or_segment_id, $marker = null) + { + list($response) = $this->getMembersWithHttpInfo($list_or_segment_id, $marker); + return $response; + } + + /** + * Operation getMembersWithHttpInfo + * + * Get List and Segment Members + * + * @param string $list_or_segment_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getMembersWithHttpInfo($list_or_segment_id, $marker = null) + { + $request = $this->getMembersRequest($list_or_segment_id, $marker); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getMembersAsync + * + * Get List and Segment Members + * + * @param string $list_or_segment_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getMembersAsync($list_or_segment_id, $marker = null) + { + return $this->getMembersAsyncWithHttpInfo($list_or_segment_id, $marker) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getMembersAsyncWithHttpInfo + * + * Get List and Segment Members + * + * @param string $list_or_segment_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getMembersAsyncWithHttpInfo($list_or_segment_id, $marker = null) + { + $returnType = 'array'; + $request = $this->getMembersRequest($list_or_segment_id, $marker); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getMembers' + * + * @param string $list_or_segment_id (required) + * @param int $marker A marker value returned by a previous GET call. Use this to grab the next batch of records. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getMembersRequest($list_or_segment_id, $marker = null) + { + // verify the required parameter 'list_or_segment_id' is set + if ($list_or_segment_id === null || (is_array($list_or_segment_id) && count($list_or_segment_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_or_segment_id when calling getMembers' + ); + } + + $resourcePath = '/v2/group/{list_or_segment_id}/members/all'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($marker !== null) { + if('form' === 'form' && is_array($marker)) { + foreach($marker as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['marker'] = $marker; + } + } + + + // path params + if ($list_or_segment_id !== null) { + $resourcePath = str_replace( + '{' . 'list_or_segment_id' . '}', + ObjectSerializer::toPathValue($list_or_segment_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getSegmentMembers + * + * Check if Profiles Are in a Segment + * + * @param string $segment_id segment_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request check_membership_request (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getSegmentMembers($segment_id, $check_membership_request = null) + { + list($response) = $this->getSegmentMembersWithHttpInfo($segment_id, $check_membership_request); + return $response; + } + + /** + * Operation getSegmentMembersWithHttpInfo + * + * Check if Profiles Are in a Segment + * + * @param string $segment_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getSegmentMembersWithHttpInfo($segment_id, $check_membership_request = null) + { + $request = $this->getSegmentMembersRequest($segment_id, $check_membership_request); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getSegmentMembersAsync + * + * Check if Profiles Are in a Segment + * + * @param string $segment_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getSegmentMembersAsync($segment_id, $check_membership_request = null) + { + return $this->getSegmentMembersAsyncWithHttpInfo($segment_id, $check_membership_request) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getSegmentMembersAsyncWithHttpInfo + * + * Check if Profiles Are in a Segment + * + * @param string $segment_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getSegmentMembersAsyncWithHttpInfo($segment_id, $check_membership_request = null) + { + $returnType = 'array'; + $request = $this->getSegmentMembersRequest($segment_id, $check_membership_request); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getSegmentMembers' + * + * @param string $segment_id (required) + * @param \Klaviyo\Model\CheckMembershipRequest $check_membership_request (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getSegmentMembersRequest($segment_id, $check_membership_request = null) + { + // verify the required parameter 'segment_id' is set + if ($segment_id === null || (is_array($segment_id) && count($segment_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $segment_id when calling getSegmentMembers' + ); + } + + $resourcePath = '/v2/segment/{segment_id}/get-members'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($segment_id !== null) { + $resourcePath = str_replace( + '{' . 'segment_id' . '}', + ObjectSerializer::toPathValue($segment_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($check_membership_request)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($check_membership_request)); + } else { + $httpBody = $check_membership_request; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation removeMembers + * + * Remove Profiles From List + * + * @param string $list_id list_id (required) + * @param \Klaviyo\Model\InlineObject5 $inline_object5 inline_object5 (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return void + */ + public function removeMembers($list_id, $inline_object5 = null) + { + $this->removeMembersWithHttpInfo($list_id, $inline_object5); + } + + /** + * Operation removeMembersWithHttpInfo + * + * Remove Profiles From List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject5 $inline_object5 (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function removeMembersWithHttpInfo($list_id, $inline_object5 = null) + { + $request = $this->removeMembersRequest($list_id, $inline_object5); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation removeMembersAsync + * + * Remove Profiles From List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject5 $inline_object5 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function removeMembersAsync($list_id, $inline_object5 = null) + { + return $this->removeMembersAsyncWithHttpInfo($list_id, $inline_object5) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation removeMembersAsyncWithHttpInfo + * + * Remove Profiles From List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject5 $inline_object5 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function removeMembersAsyncWithHttpInfo($list_id, $inline_object5 = null) + { + $returnType = ''; + $request = $this->removeMembersRequest($list_id, $inline_object5); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'removeMembers' + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject5 $inline_object5 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function removeMembersRequest($list_id, $inline_object5 = null) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling removeMembers' + ); + } + + $resourcePath = '/v2/list/{list_id}/members'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + ['application/json'] + ); + } + + // for model (json/xml) + if (isset($inline_object5)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($inline_object5)); + } else { + $httpBody = $inline_object5; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'DELETE', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation subscribe + * + * Subscribe Profiles to List + * + * @param string $list_id list_id (required) + * @param \Klaviyo\Model\InlineObject3 $inline_object3 inline_object3 (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function subscribe($list_id, $inline_object3 = null) + { + list($response) = $this->subscribeWithHttpInfo($list_id, $inline_object3); + return $response; + } + + /** + * Operation subscribeWithHttpInfo + * + * Subscribe Profiles to List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject3 $inline_object3 (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function subscribeWithHttpInfo($list_id, $inline_object3 = null) + { + $request = $this->subscribeRequest($list_id, $inline_object3); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation subscribeAsync + * + * Subscribe Profiles to List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject3 $inline_object3 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function subscribeAsync($list_id, $inline_object3 = null) + { + return $this->subscribeAsyncWithHttpInfo($list_id, $inline_object3) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation subscribeAsyncWithHttpInfo + * + * Subscribe Profiles to List + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject3 $inline_object3 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function subscribeAsyncWithHttpInfo($list_id, $inline_object3 = null) + { + $returnType = 'array'; + $request = $this->subscribeRequest($list_id, $inline_object3); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'subscribe' + * + * @param string $list_id (required) + * @param \Klaviyo\Model\InlineObject3 $inline_object3 (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function subscribeRequest($list_id, $inline_object3 = null) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling subscribe' + ); + } + + $resourcePath = '/v2/list/{list_id}/subscribe'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_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($inline_object3)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($inline_object3)); + } else { + $httpBody = $inline_object3; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation unsubscribe + * + * Unsubscribe Profiles From List + * + * @param string $list_id list_id (required) + * @param array $request_body Unsubscribe and remove profiles from a list. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return void + */ + public function unsubscribe($list_id, $request_body = null) + { + $this->unsubscribeWithHttpInfo($list_id, $request_body); + } + + /** + * Operation unsubscribeWithHttpInfo + * + * Unsubscribe Profiles From List + * + * @param string $list_id (required) + * @param array $request_body Unsubscribe and remove profiles from a list. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function unsubscribeWithHttpInfo($list_id, $request_body = null) + { + $request = $this->unsubscribeRequest($list_id, $request_body); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation unsubscribeAsync + * + * Unsubscribe Profiles From List + * + * @param string $list_id (required) + * @param array $request_body Unsubscribe and remove profiles from a list. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function unsubscribeAsync($list_id, $request_body = null) + { + return $this->unsubscribeAsyncWithHttpInfo($list_id, $request_body) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation unsubscribeAsyncWithHttpInfo + * + * Unsubscribe Profiles From List + * + * @param string $list_id (required) + * @param array $request_body Unsubscribe and remove profiles from a list. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function unsubscribeAsyncWithHttpInfo($list_id, $request_body = null) + { + $returnType = ''; + $request = $this->unsubscribeRequest($list_id, $request_body); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'unsubscribe' + * + * @param string $list_id (required) + * @param array $request_body Unsubscribe and remove profiles from a list. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function unsubscribeRequest($list_id, $request_body = null) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling unsubscribe' + ); + } + + $resourcePath = '/v2/list/{list_id}/subscribe'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + ['application/json'] + ); + } + + // for model (json/xml) + if (isset($request_body)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($request_body)); + } else { + $httpBody = $request_body; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'DELETE', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation updateListName + * + * Update List Name + * + * @param string $list_id list_id (required) + * @param string $list_name list_name (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return void + */ + public function updateListName($list_id, $list_name) + { + $this->updateListNameWithHttpInfo($list_id, $list_name); + } + + /** + * Operation updateListNameWithHttpInfo + * + * Update List Name + * + * @param string $list_id (required) + * @param string $list_name (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of null, HTTP status code, HTTP response headers (array of strings) + */ + public function updateListNameWithHttpInfo($list_id, $list_name) + { + $request = $this->updateListNameRequest($list_id, $list_name); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return [null, $statusCode, $response->getHeaders()]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; + } + } + + /** + * Operation updateListNameAsync + * + * Update List Name + * + * @param string $list_id (required) + * @param string $list_name (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateListNameAsync($list_id, $list_name) + { + return $this->updateListNameAsyncWithHttpInfo($list_id, $list_name) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation updateListNameAsyncWithHttpInfo + * + * Update List Name + * + * @param string $list_id (required) + * @param string $list_name (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateListNameAsyncWithHttpInfo($list_id, $list_name) + { + $returnType = ''; + $request = $this->updateListNameRequest($list_id, $list_name); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + return [null, $response->getStatusCode(), $response->getHeaders()]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'updateListName' + * + * @param string $list_id (required) + * @param string $list_name (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function updateListNameRequest($list_id, $list_name) + { + // verify the required parameter 'list_id' is set + if ($list_id === null || (is_array($list_id) && count($list_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_id when calling updateListName' + ); + } + // verify the required parameter 'list_name' is set + if ($list_name === null || (is_array($list_name) && count($list_name) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $list_name when calling updateListName' + ); + } + + $resourcePath = '/v2/list/{list_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($list_id !== null) { + $resourcePath = str_replace( + '{' . 'list_id' . '}', + ObjectSerializer::toPathValue($list_id), + $resourcePath + ); + } + + // form params + if ($list_name !== null) { + $formParams['list_name'] = ObjectSerializer::toFormValue($list_name); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + [] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + [], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'PUT', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/lib/API/MetricsApi.php b/lib/API/MetricsApi.php new file mode 100644 index 0000000..950c9bf --- /dev/null +++ b/lib/API/MetricsApi.php @@ -0,0 +1,1518 @@ +client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation getMetrics + * + * Get Metrics Info + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Default = 50 ; Max = 100 (optional, default to 50) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getMetrics($page = 0, $count = 50) + { + list($response) = $this->getMetricsWithHttpInfo($page, $count); + return $response; + } + + /** + * Operation getMetricsWithHttpInfo + * + * Get Metrics Info + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Default = 50 ; Max = 100 (optional, default to 50) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getMetricsWithHttpInfo($page = 0, $count = 50) + { + $request = $this->getMetricsRequest($page, $count); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getMetricsAsync + * + * Get Metrics Info + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Default = 50 ; Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getMetricsAsync($page = 0, $count = 50) + { + return $this->getMetricsAsyncWithHttpInfo($page, $count) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getMetricsAsyncWithHttpInfo + * + * Get Metrics Info + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Default = 50 ; Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getMetricsAsyncWithHttpInfo($page = 0, $count = 50) + { + $returnType = 'array'; + $request = $this->getMetricsRequest($page, $count); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getMetrics' + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Default = 50 ; Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getMetricsRequest($page = 0, $count = 50) + { + if ($page !== null && $page < 0) { + throw new \InvalidArgumentException('invalid value for "$page" when calling MetricsApi.getMetrics, must be bigger than or equal to 0.'); + } + + if ($count !== null && $count > 100) { + throw new \InvalidArgumentException('invalid value for "$count" when calling MetricsApi.getMetrics, must be smaller than or equal to 100.'); + } + if ($count !== null && $count < 1) { + throw new \InvalidArgumentException('invalid value for "$count" when calling MetricsApi.getMetrics, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/v1/metrics'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($page !== null) { + if('form' === 'form' && is_array($page)) { + foreach($page as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['page'] = $page; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + + + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation metricExport + * + * Query Event Data + * + * @param string $metric_id metric_id (required) + * @param string $start_date Beginning of timeframe to pull event data for. The default value is 1 month ago. Can also accept a 10-digit UNIX timestamp. When sending a `start_date`, you must also send an `end_date` Ex: `1610524800` OR `2021-01-13` (optional) + * @param string $end_date End of timeframe to pull event data for. The default is the current day, or 1 month from start_date, whichever is sooner. Can also accept a 10-digit UNIX timestamp. When sending an `end_date`, you must also send a `start_date`. Must be *at most* 31 days after `start_date` Ex: `1612080000` OR `2021-01-31` (optional) + * @param string $unit Granularity to bucket data points into - one of `day`, `week`, or `month`. Defaults to `day`. (optional, default to 'day') + * @param string $measurement Type of metric to fetch - one of `unique`, `count`, `value`, or `sum`. Defaults to `count`. For `sum` a property name to operate on must be supplied as a JSON-encoded list like `[\"sum\",\"ItemCount\"]` (optional, default to 'count') + * @param string $where Optional, JSON-encoded list. Conditions to use to filter the set of events. A max of 1 condition can be given. `where` and `by` parameters cannot be specified at the same time. ex: `[[\"$attributed_flow\",\"=\",\"FLOW_ID\"]]` (optional) + * @param string $by The name of a property to segment the event data on. `where` and `by` parameters cannot be specified at the same time. Cannot be used alongside `where` parameter. (optional) + * @param int $count Maximum number of segments to return. Default = 25, **MAX = 1000** (optional, default to 25) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function metricExport($metric_id, $start_date = null, $end_date = null, $unit = 'day', $measurement = 'count', $where = null, $by = null, $count = 25) + { + list($response) = $this->metricExportWithHttpInfo($metric_id, $start_date, $end_date, $unit, $measurement, $where, $by, $count); + return $response; + } + + /** + * Operation metricExportWithHttpInfo + * + * Query Event Data + * + * @param string $metric_id (required) + * @param string $start_date Beginning of timeframe to pull event data for. The default value is 1 month ago. Can also accept a 10-digit UNIX timestamp. When sending a `start_date`, you must also send an `end_date` Ex: `1610524800` OR `2021-01-13` (optional) + * @param string $end_date End of timeframe to pull event data for. The default is the current day, or 1 month from start_date, whichever is sooner. Can also accept a 10-digit UNIX timestamp. When sending an `end_date`, you must also send a `start_date`. Must be *at most* 31 days after `start_date` Ex: `1612080000` OR `2021-01-31` (optional) + * @param string $unit Granularity to bucket data points into - one of `day`, `week`, or `month`. Defaults to `day`. (optional, default to 'day') + * @param string $measurement Type of metric to fetch - one of `unique`, `count`, `value`, or `sum`. Defaults to `count`. For `sum` a property name to operate on must be supplied as a JSON-encoded list like `[\"sum\",\"ItemCount\"]` (optional, default to 'count') + * @param string $where Optional, JSON-encoded list. Conditions to use to filter the set of events. A max of 1 condition can be given. `where` and `by` parameters cannot be specified at the same time. ex: `[[\"$attributed_flow\",\"=\",\"FLOW_ID\"]]` (optional) + * @param string $by The name of a property to segment the event data on. `where` and `by` parameters cannot be specified at the same time. Cannot be used alongside `where` parameter. (optional) + * @param int $count Maximum number of segments to return. Default = 25, **MAX = 1000** (optional, default to 25) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function metricExportWithHttpInfo($metric_id, $start_date = null, $end_date = null, $unit = 'day', $measurement = 'count', $where = null, $by = null, $count = 25) + { + $request = $this->metricExportRequest($metric_id, $start_date, $end_date, $unit, $measurement, $where, $by, $count); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation metricExportAsync + * + * Query Event Data + * + * @param string $metric_id (required) + * @param string $start_date Beginning of timeframe to pull event data for. The default value is 1 month ago. Can also accept a 10-digit UNIX timestamp. When sending a `start_date`, you must also send an `end_date` Ex: `1610524800` OR `2021-01-13` (optional) + * @param string $end_date End of timeframe to pull event data for. The default is the current day, or 1 month from start_date, whichever is sooner. Can also accept a 10-digit UNIX timestamp. When sending an `end_date`, you must also send a `start_date`. Must be *at most* 31 days after `start_date` Ex: `1612080000` OR `2021-01-31` (optional) + * @param string $unit Granularity to bucket data points into - one of `day`, `week`, or `month`. Defaults to `day`. (optional, default to 'day') + * @param string $measurement Type of metric to fetch - one of `unique`, `count`, `value`, or `sum`. Defaults to `count`. For `sum` a property name to operate on must be supplied as a JSON-encoded list like `[\"sum\",\"ItemCount\"]` (optional, default to 'count') + * @param string $where Optional, JSON-encoded list. Conditions to use to filter the set of events. A max of 1 condition can be given. `where` and `by` parameters cannot be specified at the same time. ex: `[[\"$attributed_flow\",\"=\",\"FLOW_ID\"]]` (optional) + * @param string $by The name of a property to segment the event data on. `where` and `by` parameters cannot be specified at the same time. Cannot be used alongside `where` parameter. (optional) + * @param int $count Maximum number of segments to return. Default = 25, **MAX = 1000** (optional, default to 25) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function metricExportAsync($metric_id, $start_date = null, $end_date = null, $unit = 'day', $measurement = 'count', $where = null, $by = null, $count = 25) + { + return $this->metricExportAsyncWithHttpInfo($metric_id, $start_date, $end_date, $unit, $measurement, $where, $by, $count) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation metricExportAsyncWithHttpInfo + * + * Query Event Data + * + * @param string $metric_id (required) + * @param string $start_date Beginning of timeframe to pull event data for. The default value is 1 month ago. Can also accept a 10-digit UNIX timestamp. When sending a `start_date`, you must also send an `end_date` Ex: `1610524800` OR `2021-01-13` (optional) + * @param string $end_date End of timeframe to pull event data for. The default is the current day, or 1 month from start_date, whichever is sooner. Can also accept a 10-digit UNIX timestamp. When sending an `end_date`, you must also send a `start_date`. Must be *at most* 31 days after `start_date` Ex: `1612080000` OR `2021-01-31` (optional) + * @param string $unit Granularity to bucket data points into - one of `day`, `week`, or `month`. Defaults to `day`. (optional, default to 'day') + * @param string $measurement Type of metric to fetch - one of `unique`, `count`, `value`, or `sum`. Defaults to `count`. For `sum` a property name to operate on must be supplied as a JSON-encoded list like `[\"sum\",\"ItemCount\"]` (optional, default to 'count') + * @param string $where Optional, JSON-encoded list. Conditions to use to filter the set of events. A max of 1 condition can be given. `where` and `by` parameters cannot be specified at the same time. ex: `[[\"$attributed_flow\",\"=\",\"FLOW_ID\"]]` (optional) + * @param string $by The name of a property to segment the event data on. `where` and `by` parameters cannot be specified at the same time. Cannot be used alongside `where` parameter. (optional) + * @param int $count Maximum number of segments to return. Default = 25, **MAX = 1000** (optional, default to 25) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function metricExportAsyncWithHttpInfo($metric_id, $start_date = null, $end_date = null, $unit = 'day', $measurement = 'count', $where = null, $by = null, $count = 25) + { + $returnType = 'array'; + $request = $this->metricExportRequest($metric_id, $start_date, $end_date, $unit, $measurement, $where, $by, $count); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'metricExport' + * + * @param string $metric_id (required) + * @param string $start_date Beginning of timeframe to pull event data for. The default value is 1 month ago. Can also accept a 10-digit UNIX timestamp. When sending a `start_date`, you must also send an `end_date` Ex: `1610524800` OR `2021-01-13` (optional) + * @param string $end_date End of timeframe to pull event data for. The default is the current day, or 1 month from start_date, whichever is sooner. Can also accept a 10-digit UNIX timestamp. When sending an `end_date`, you must also send a `start_date`. Must be *at most* 31 days after `start_date` Ex: `1612080000` OR `2021-01-31` (optional) + * @param string $unit Granularity to bucket data points into - one of `day`, `week`, or `month`. Defaults to `day`. (optional, default to 'day') + * @param string $measurement Type of metric to fetch - one of `unique`, `count`, `value`, or `sum`. Defaults to `count`. For `sum` a property name to operate on must be supplied as a JSON-encoded list like `[\"sum\",\"ItemCount\"]` (optional, default to 'count') + * @param string $where Optional, JSON-encoded list. Conditions to use to filter the set of events. A max of 1 condition can be given. `where` and `by` parameters cannot be specified at the same time. ex: `[[\"$attributed_flow\",\"=\",\"FLOW_ID\"]]` (optional) + * @param string $by The name of a property to segment the event data on. `where` and `by` parameters cannot be specified at the same time. Cannot be used alongside `where` parameter. (optional) + * @param int $count Maximum number of segments to return. Default = 25, **MAX = 1000** (optional, default to 25) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function metricExportRequest($metric_id, $start_date = null, $end_date = null, $unit = 'day', $measurement = 'count', $where = null, $by = null, $count = 25) + { + // verify the required parameter 'metric_id' is set + if ($metric_id === null || (is_array($metric_id) && count($metric_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $metric_id when calling metricExport' + ); + } + if ($count !== null && $count > 1000) { + throw new \InvalidArgumentException('invalid value for "$count" when calling MetricsApi.metricExport, must be smaller than or equal to 1000.'); + } + if ($count !== null && $count < 1) { + throw new \InvalidArgumentException('invalid value for "$count" when calling MetricsApi.metricExport, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/v1/metric/{metric_id}/export'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($start_date !== null) { + if('form' === 'form' && is_array($start_date)) { + foreach($start_date as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['start_date'] = $start_date; + } + } + // query params + if ($end_date !== null) { + if('form' === 'form' && is_array($end_date)) { + foreach($end_date as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['end_date'] = $end_date; + } + } + // query params + if ($unit !== null) { + if('form' === 'form' && is_array($unit)) { + foreach($unit as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['unit'] = $unit; + } + } + // query params + if ($measurement !== null) { + if('form' === 'form' && is_array($measurement)) { + foreach($measurement as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['measurement'] = $measurement; + } + } + // query params + if ($where !== null) { + if('form' === 'form' && is_array($where)) { + foreach($where as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['where'] = $where; + } + } + // query params + if ($by !== null) { + if('form' === 'form' && is_array($by)) { + foreach($by as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['by'] = $by; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + + + // path params + if ($metric_id !== null) { + $resourcePath = str_replace( + '{' . 'metric_id' . '}', + ObjectSerializer::toPathValue($metric_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation metricTimeline + * + * Get Events for a Specific Metric + * + * @param string $metric_id metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the `next` attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function metricTimeline($metric_id, $since = null, $count = 50, $sort = 'desc') + { + list($response) = $this->metricTimelineWithHttpInfo($metric_id, $since, $count, $sort); + return $response; + } + + /** + * Operation metricTimelineWithHttpInfo + * + * Get Events for a Specific Metric + * + * @param string $metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the `next` attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function metricTimelineWithHttpInfo($metric_id, $since = null, $count = 50, $sort = 'desc') + { + $request = $this->metricTimelineRequest($metric_id, $since, $count, $sort); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation metricTimelineAsync + * + * Get Events for a Specific Metric + * + * @param string $metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the `next` attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function metricTimelineAsync($metric_id, $since = null, $count = 50, $sort = 'desc') + { + return $this->metricTimelineAsyncWithHttpInfo($metric_id, $since, $count, $sort) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation metricTimelineAsyncWithHttpInfo + * + * Get Events for a Specific Metric + * + * @param string $metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the `next` attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function metricTimelineAsyncWithHttpInfo($metric_id, $since = null, $count = 50, $sort = 'desc') + { + $returnType = 'array'; + $request = $this->metricTimelineRequest($metric_id, $since, $count, $sort); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'metricTimeline' + * + * @param string $metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the `next` attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function metricTimelineRequest($metric_id, $since = null, $count = 50, $sort = 'desc') + { + // verify the required parameter 'metric_id' is set + if ($metric_id === null || (is_array($metric_id) && count($metric_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $metric_id when calling metricTimeline' + ); + } + if ($count !== null && $count > 100) { + throw new \InvalidArgumentException('invalid value for "$count" when calling MetricsApi.metricTimeline, must be smaller than or equal to 100.'); + } + if ($count !== null && $count < 1) { + throw new \InvalidArgumentException('invalid value for "$count" when calling MetricsApi.metricTimeline, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/v1/metric/{metric_id}/timeline'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($since !== null) { + if('form' === 'form' && is_array($since)) { + foreach($since as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['since'] = $since; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + // query params + if ($sort !== null) { + if('form' === 'form' && is_array($sort)) { + foreach($sort as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['sort'] = $sort; + } + } + + + // path params + if ($metric_id !== null) { + $resourcePath = str_replace( + '{' . 'metric_id' . '}', + ObjectSerializer::toPathValue($metric_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation metricsTimeline + * + * Get Events for All Metrics + * + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function metricsTimeline($since = null, $count = 50, $sort = 'desc') + { + list($response) = $this->metricsTimelineWithHttpInfo($since, $count, $sort); + return $response; + } + + /** + * Operation metricsTimelineWithHttpInfo + * + * Get Events for All Metrics + * + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function metricsTimelineWithHttpInfo($since = null, $count = 50, $sort = 'desc') + { + $request = $this->metricsTimelineRequest($since, $count, $sort); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation metricsTimelineAsync + * + * Get Events for All Metrics + * + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function metricsTimelineAsync($since = null, $count = 50, $sort = 'desc') + { + return $this->metricsTimelineAsyncWithHttpInfo($since, $count, $sort) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation metricsTimelineAsyncWithHttpInfo + * + * Get Events for All Metrics + * + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function metricsTimelineAsyncWithHttpInfo($since = null, $count = 50, $sort = 'desc') + { + $returnType = 'array'; + $request = $this->metricsTimelineRequest($since, $count, $sort); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'metricsTimeline' + * + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function metricsTimelineRequest($since = null, $count = 50, $sort = 'desc') + { + if ($count !== null && $count > 100) { + throw new \InvalidArgumentException('invalid value for "$count" when calling MetricsApi.metricsTimeline, must be smaller than or equal to 100.'); + } + if ($count !== null && $count < 1) { + throw new \InvalidArgumentException('invalid value for "$count" when calling MetricsApi.metricsTimeline, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/v1/metrics/timeline'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($since !== null) { + if('form' === 'form' && is_array($since)) { + foreach($since as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['since'] = $since; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + // query params + if ($sort !== null) { + if('form' === 'form' && is_array($sort)) { + foreach($sort as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['sort'] = $sort; + } + } + + + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/lib/API/ProfilesApi.php b/lib/API/ProfilesApi.php new file mode 100644 index 0000000..77a479f --- /dev/null +++ b/lib/API/ProfilesApi.php @@ -0,0 +1,1708 @@ +client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation exchange + * + * Exchange ID for Profile ID + * + * @param \Klaviyo\Model\InlineObject $inline_object inline_object (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function exchange($inline_object = null) + { + list($response) = $this->exchangeWithHttpInfo($inline_object); + return $response; + } + + /** + * Operation exchangeWithHttpInfo + * + * Exchange ID for Profile ID + * + * @param \Klaviyo\Model\InlineObject $inline_object (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function exchangeWithHttpInfo($inline_object = null) + { + $request = $this->exchangeRequest($inline_object); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation exchangeAsync + * + * Exchange ID for Profile ID + * + * @param \Klaviyo\Model\InlineObject $inline_object (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function exchangeAsync($inline_object = null) + { + return $this->exchangeAsyncWithHttpInfo($inline_object) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation exchangeAsyncWithHttpInfo + * + * Exchange ID for Profile ID + * + * @param \Klaviyo\Model\InlineObject $inline_object (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function exchangeAsyncWithHttpInfo($inline_object = null) + { + $returnType = 'array'; + $request = $this->exchangeRequest($inline_object); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'exchange' + * + * @param \Klaviyo\Model\InlineObject $inline_object (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function exchangeRequest($inline_object = null) + { + + $resourcePath = '/v2/people/exchange'; + $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($inline_object)) { + if ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($inline_object)); + } else { + $httpBody = $inline_object; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getProfile + * + * Get Profile + * + * @param string $person_id person_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getProfile($person_id) + { + list($response) = $this->getProfileWithHttpInfo($person_id); + return $response; + } + + /** + * Operation getProfileWithHttpInfo + * + * Get Profile + * + * @param string $person_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getProfileWithHttpInfo($person_id) + { + $request = $this->getProfileRequest($person_id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getProfileAsync + * + * Get Profile + * + * @param string $person_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getProfileAsync($person_id) + { + return $this->getProfileAsyncWithHttpInfo($person_id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getProfileAsyncWithHttpInfo + * + * Get Profile + * + * @param string $person_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getProfileAsyncWithHttpInfo($person_id) + { + $returnType = 'array'; + $request = $this->getProfileRequest($person_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getProfile' + * + * @param string $person_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getProfileRequest($person_id) + { + // verify the required parameter 'person_id' is set + if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $person_id when calling getProfile' + ); + } + + $resourcePath = '/v1/person/{person_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($person_id !== null) { + $resourcePath = str_replace( + '{' . 'person_id' . '}', + ObjectSerializer::toPathValue($person_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation profileMetricTimeline + * + * Get Profile's Events for a Specific Metric + * + * @param string $person_id person_id (required) + * @param string $metric_id metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. (optional, default to 'desc') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function profileMetricTimeline($person_id, $metric_id, $since = null, $count = 50, $sort = 'desc') + { + list($response) = $this->profileMetricTimelineWithHttpInfo($person_id, $metric_id, $since, $count, $sort); + return $response; + } + + /** + * Operation profileMetricTimelineWithHttpInfo + * + * Get Profile's Events for a Specific Metric + * + * @param string $person_id (required) + * @param string $metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. (optional, default to 'desc') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function profileMetricTimelineWithHttpInfo($person_id, $metric_id, $since = null, $count = 50, $sort = 'desc') + { + $request = $this->profileMetricTimelineRequest($person_id, $metric_id, $since, $count, $sort); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation profileMetricTimelineAsync + * + * Get Profile's Events for a Specific Metric + * + * @param string $person_id (required) + * @param string $metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function profileMetricTimelineAsync($person_id, $metric_id, $since = null, $count = 50, $sort = 'desc') + { + return $this->profileMetricTimelineAsyncWithHttpInfo($person_id, $metric_id, $since, $count, $sort) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation profileMetricTimelineAsyncWithHttpInfo + * + * Get Profile's Events for a Specific Metric + * + * @param string $person_id (required) + * @param string $metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function profileMetricTimelineAsyncWithHttpInfo($person_id, $metric_id, $since = null, $count = 50, $sort = 'desc') + { + $returnType = 'array'; + $request = $this->profileMetricTimelineRequest($person_id, $metric_id, $since, $count, $sort); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'profileMetricTimeline' + * + * @param string $person_id (required) + * @param string $metric_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function profileMetricTimelineRequest($person_id, $metric_id, $since = null, $count = 50, $sort = 'desc') + { + // verify the required parameter 'person_id' is set + if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $person_id when calling profileMetricTimeline' + ); + } + // verify the required parameter 'metric_id' is set + if ($metric_id === null || (is_array($metric_id) && count($metric_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $metric_id when calling profileMetricTimeline' + ); + } + if ($count !== null && $count > 100) { + throw new \InvalidArgumentException('invalid value for "$count" when calling ProfilesApi.profileMetricTimeline, must be smaller than or equal to 100.'); + } + if ($count !== null && $count < 1) { + throw new \InvalidArgumentException('invalid value for "$count" when calling ProfilesApi.profileMetricTimeline, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/v1/person/{person_id}/metric/{metric_id}/timeline'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($since !== null) { + if('form' === 'form' && is_array($since)) { + foreach($since as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['since'] = $since; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + // query params + if ($sort !== null) { + if('form' === 'form' && is_array($sort)) { + foreach($sort as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['sort'] = $sort; + } + } + + + // path params + if ($person_id !== null) { + $resourcePath = str_replace( + '{' . 'person_id' . '}', + ObjectSerializer::toPathValue($person_id), + $resourcePath + ); + } + // path params + if ($metric_id !== null) { + $resourcePath = str_replace( + '{' . 'metric_id' . '}', + ObjectSerializer::toPathValue($metric_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation profileMetricsTimeline + * + * Get Profile's Events for all Metrics + * + * @param string $person_id person_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function profileMetricsTimeline($person_id, $since = null, $count = 50, $sort = 'desc') + { + list($response) = $this->profileMetricsTimelineWithHttpInfo($person_id, $since, $count, $sort); + return $response; + } + + /** + * Operation profileMetricsTimelineWithHttpInfo + * + * Get Profile's Events for all Metrics + * + * @param string $person_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function profileMetricsTimelineWithHttpInfo($person_id, $since = null, $count = 50, $sort = 'desc') + { + $request = $this->profileMetricsTimelineRequest($person_id, $since, $count, $sort); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation profileMetricsTimelineAsync + * + * Get Profile's Events for all Metrics + * + * @param string $person_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function profileMetricsTimelineAsync($person_id, $since = null, $count = 50, $sort = 'desc') + { + return $this->profileMetricsTimelineAsyncWithHttpInfo($person_id, $since, $count, $sort) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation profileMetricsTimelineAsyncWithHttpInfo + * + * Get Profile's Events for all Metrics + * + * @param string $person_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function profileMetricsTimelineAsyncWithHttpInfo($person_id, $since = null, $count = 50, $sort = 'desc') + { + $returnType = 'array'; + $request = $this->profileMetricsTimelineRequest($person_id, $since, $count, $sort); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'profileMetricsTimeline' + * + * @param string $person_id (required) + * @param string $since Either a 10-digit Unix timestamp (UTC) to use as starting datetime, OR a pagination token obtained from the next attribute of a prior API call. For backwards compatibility, UUIDs will continue to be supported for a limited time. Defaults to current time. (optional) + * @param int $count Number of events to return in a batch. Default = 50, Max = 100 (optional, default to 50) + * @param string $sort Sort order to apply to timeline, either descending or ascending. Valid values are `desc` or `asc`. Defaults to `desc`. Always descending when `since` is not sent, as `since` defaults to current time. (optional, default to 'desc') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function profileMetricsTimelineRequest($person_id, $since = null, $count = 50, $sort = 'desc') + { + // verify the required parameter 'person_id' is set + if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $person_id when calling profileMetricsTimeline' + ); + } + if ($count !== null && $count > 100) { + throw new \InvalidArgumentException('invalid value for "$count" when calling ProfilesApi.profileMetricsTimeline, must be smaller than or equal to 100.'); + } + if ($count !== null && $count < 1) { + throw new \InvalidArgumentException('invalid value for "$count" when calling ProfilesApi.profileMetricsTimeline, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/v1/person/{person_id}/metrics/timeline'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($since !== null) { + if('form' === 'form' && is_array($since)) { + foreach($since as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['since'] = $since; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + // query params + if ($sort !== null) { + if('form' === 'form' && is_array($sort)) { + foreach($sort as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['sort'] = $sort; + } + } + + + // path params + if ($person_id !== null) { + $resourcePath = str_replace( + '{' . 'person_id' . '}', + ObjectSerializer::toPathValue($person_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation updateProfile + * + * Update Profile + * + * @param string $person_id person_id (required) + * @param array $params params (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function updateProfile($person_id, $params = null) + { + list($response) = $this->updateProfileWithHttpInfo($person_id, $params); + return $response; + } + + /** + * Operation updateProfileWithHttpInfo + * + * Update Profile + * + * @param string $person_id (required) + * @param array $params (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function updateProfileWithHttpInfo($person_id, $params = null) + { + $request = $this->updateProfileRequest($person_id, $params); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation updateProfileAsync + * + * Update Profile + * + * @param string $person_id (required) + * @param array $params (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateProfileAsync($person_id, $params = null) + { + return $this->updateProfileAsyncWithHttpInfo($person_id, $params) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation updateProfileAsyncWithHttpInfo + * + * Update Profile + * + * @param string $person_id (required) + * @param array $params (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateProfileAsyncWithHttpInfo($person_id, $params = null) + { + $returnType = 'array'; + $request = $this->updateProfileRequest($person_id, $params); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'updateProfile' + * + * @param string $person_id (required) + * @param array $params (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function updateProfileRequest($person_id, $params = null) + { + // verify the required parameter 'person_id' is set + if ($person_id === null || (is_array($person_id) && count($person_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $person_id when calling updateProfile' + ); + } + + $resourcePath = '/v1/person/{person_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($params !== null) { + if('form' === 'form' && is_array($params)) { + foreach($params as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['params'] = $params; + } + } + + + // path params + if ($person_id !== null) { + $resourcePath = str_replace( + '{' . 'person_id' . '}', + ObjectSerializer::toPathValue($person_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'PUT', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/lib/API/TemplatesApi.php b/lib/API/TemplatesApi.php new file mode 100644 index 0000000..fecd788 --- /dev/null +++ b/lib/API/TemplatesApi.php @@ -0,0 +1,2291 @@ +client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation cloneTemplate + * + * Clone Template + * + * @param string $template_id template_id (required) + * @param string $name The new name of the email template. (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function cloneTemplate($template_id, $name) + { + list($response) = $this->cloneTemplateWithHttpInfo($template_id, $name); + return $response; + } + + /** + * Operation cloneTemplateWithHttpInfo + * + * Clone Template + * + * @param string $template_id (required) + * @param string $name The new name of the email template. (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function cloneTemplateWithHttpInfo($template_id, $name) + { + $request = $this->cloneTemplateRequest($template_id, $name); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation cloneTemplateAsync + * + * Clone Template + * + * @param string $template_id (required) + * @param string $name The new name of the email template. (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function cloneTemplateAsync($template_id, $name) + { + return $this->cloneTemplateAsyncWithHttpInfo($template_id, $name) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation cloneTemplateAsyncWithHttpInfo + * + * Clone Template + * + * @param string $template_id (required) + * @param string $name The new name of the email template. (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function cloneTemplateAsyncWithHttpInfo($template_id, $name) + { + $returnType = 'array'; + $request = $this->cloneTemplateRequest($template_id, $name); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'cloneTemplate' + * + * @param string $template_id (required) + * @param string $name The new name of the email template. (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function cloneTemplateRequest($template_id, $name) + { + // verify the required parameter 'template_id' is set + if ($template_id === null || (is_array($template_id) && count($template_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $template_id when calling cloneTemplate' + ); + } + // verify the required parameter 'name' is set + if ($name === null || (is_array($name) && count($name) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $name when calling cloneTemplate' + ); + } + + $resourcePath = '/v1/email-template/{template_id}/clone'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($template_id !== null) { + $resourcePath = str_replace( + '{' . 'template_id' . '}', + ObjectSerializer::toPathValue($template_id), + $resourcePath + ); + } + + // form params + if ($name !== null) { + $formParams['name'] = ObjectSerializer::toFormValue($name); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation createTemplate + * + * Create New Template + * + * @param string $name The name of the email template. (required) + * @param string $html html (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function createTemplate($name, $html) + { + list($response) = $this->createTemplateWithHttpInfo($name, $html); + return $response; + } + + /** + * Operation createTemplateWithHttpInfo + * + * Create New Template + * + * @param string $name The name of the email template. (required) + * @param string $html (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function createTemplateWithHttpInfo($name, $html) + { + $request = $this->createTemplateRequest($name, $html); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation createTemplateAsync + * + * Create New Template + * + * @param string $name The name of the email template. (required) + * @param string $html (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createTemplateAsync($name, $html) + { + return $this->createTemplateAsyncWithHttpInfo($name, $html) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation createTemplateAsyncWithHttpInfo + * + * Create New Template + * + * @param string $name The name of the email template. (required) + * @param string $html (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function createTemplateAsyncWithHttpInfo($name, $html) + { + $returnType = 'array'; + $request = $this->createTemplateRequest($name, $html); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'createTemplate' + * + * @param string $name The name of the email template. (required) + * @param string $html (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function createTemplateRequest($name, $html) + { + // verify the required parameter 'name' is set + if ($name === null || (is_array($name) && count($name) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $name when calling createTemplate' + ); + } + // verify the required parameter 'html' is set + if ($html === null || (is_array($html) && count($html) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $html when calling createTemplate' + ); + } + + $resourcePath = '/v1/email-templates'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + // form params + if ($name !== null) { + $formParams['name'] = ObjectSerializer::toFormValue($name); + } + // form params + if ($html !== null) { + $formParams['html'] = ObjectSerializer::toFormValue($html); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation deleteTemplate + * + * Delete Template + * + * @param string $template_id template_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function deleteTemplate($template_id) + { + list($response) = $this->deleteTemplateWithHttpInfo($template_id); + return $response; + } + + /** + * Operation deleteTemplateWithHttpInfo + * + * Delete Template + * + * @param string $template_id (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function deleteTemplateWithHttpInfo($template_id) + { + $request = $this->deleteTemplateRequest($template_id); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation deleteTemplateAsync + * + * Delete Template + * + * @param string $template_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteTemplateAsync($template_id) + { + return $this->deleteTemplateAsyncWithHttpInfo($template_id) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation deleteTemplateAsyncWithHttpInfo + * + * Delete Template + * + * @param string $template_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function deleteTemplateAsyncWithHttpInfo($template_id) + { + $returnType = 'array'; + $request = $this->deleteTemplateRequest($template_id); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'deleteTemplate' + * + * @param string $template_id (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function deleteTemplateRequest($template_id) + { + // verify the required parameter 'template_id' is set + if ($template_id === null || (is_array($template_id) && count($template_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $template_id when calling deleteTemplate' + ); + } + + $resourcePath = '/v1/email-template/{template_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($template_id !== null) { + $resourcePath = str_replace( + '{' . 'template_id' . '}', + ObjectSerializer::toPathValue($template_id), + $resourcePath + ); + } + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'DELETE', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation getTemplates + * + * Get All Templates + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function getTemplates($page = 0, $count = 50) + { + list($response) = $this->getTemplatesWithHttpInfo($page, $count); + return $response; + } + + /** + * Operation getTemplatesWithHttpInfo + * + * Get All Templates + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function getTemplatesWithHttpInfo($page = 0, $count = 50) + { + $request = $this->getTemplatesRequest($page, $count); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation getTemplatesAsync + * + * Get All Templates + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getTemplatesAsync($page = 0, $count = 50) + { + return $this->getTemplatesAsyncWithHttpInfo($page, $count) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation getTemplatesAsyncWithHttpInfo + * + * Get All Templates + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function getTemplatesAsyncWithHttpInfo($page = 0, $count = 50) + { + $returnType = 'array'; + $request = $this->getTemplatesRequest($page, $count); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'getTemplates' + * + * @param int $page For pagination, which page of results to return. Default = 0 (optional, default to 0) + * @param int $count For pagination, the number of results to return. Max = 100 (optional, default to 50) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function getTemplatesRequest($page = 0, $count = 50) + { + if ($page !== null && $page < 0) { + throw new \InvalidArgumentException('invalid value for "$page" when calling TemplatesApi.getTemplates, must be bigger than or equal to 0.'); + } + + if ($count !== null && $count > 100) { + throw new \InvalidArgumentException('invalid value for "$count" when calling TemplatesApi.getTemplates, must be smaller than or equal to 100.'); + } + if ($count !== null && $count < 1) { + throw new \InvalidArgumentException('invalid value for "$count" when calling TemplatesApi.getTemplates, must be bigger than or equal to 1.'); + } + + + $resourcePath = '/v1/email-templates'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($page !== null) { + if('form' === 'form' && is_array($page)) { + foreach($page as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['page'] = $page; + } + } + // query params + if ($count !== null) { + if('form' === 'form' && is_array($count)) { + foreach($count as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['count'] = $count; + } + } + + + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation renderTemplate + * + * Render Template + * + * @param string $template_id template_id (required) + * @param string $context This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function renderTemplate($template_id, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + list($response) = $this->renderTemplateWithHttpInfo($template_id, $context); + return $response; + } + + /** + * Operation renderTemplateWithHttpInfo + * + * Render Template + * + * @param string $template_id (required) + * @param string $context This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function renderTemplateWithHttpInfo($template_id, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + $request = $this->renderTemplateRequest($template_id, $context); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation renderTemplateAsync + * + * Render Template + * + * @param string $template_id (required) + * @param string $context This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function renderTemplateAsync($template_id, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + return $this->renderTemplateAsyncWithHttpInfo($template_id, $context) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation renderTemplateAsyncWithHttpInfo + * + * Render Template + * + * @param string $template_id (required) + * @param string $context This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function renderTemplateAsyncWithHttpInfo($template_id, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + $returnType = 'array'; + $request = $this->renderTemplateRequest($template_id, $context); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'renderTemplate' + * + * @param string $template_id (required) + * @param string $context This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function renderTemplateRequest($template_id, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + // verify the required parameter 'template_id' is set + if ($template_id === null || (is_array($template_id) && count($template_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $template_id when calling renderTemplate' + ); + } + + $resourcePath = '/v1/email-template/{template_id}/render'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($template_id !== null) { + $resourcePath = str_replace( + '{' . 'template_id' . '}', + ObjectSerializer::toPathValue($template_id), + $resourcePath + ); + } + + // form params + if ($context !== null) { + $formParams['context'] = ObjectSerializer::toFormValue($context); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation sendTemplate + * + * Render and Send Template + * + * @param string $template_id template_id (required) + * @param string $from_email from_email (required) + * @param string $from_name from_name (required) + * @param string $subject subject (required) + * @param string $to **Mixed**. string, or JSON encoded array of objects with \\\"email\\\" and \\\"name\\\" keys. `abraham.lincoln@klaviyo.com` OR `[{\\\"name\\\":\\\"Abraham Lincoln\\\",\\\"email\\\":\\\"abraham.lincoln@klaviyo.com\\\"}]` (required) + * @param string $context Optional, JSON object. This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. ex: `{ \\\"name\\\" : \\\"George Washington\\\", \\\"state\\\" : \\\"VA\\\" }` (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function sendTemplate($template_id, $from_email, $from_name, $subject, $to, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + list($response) = $this->sendTemplateWithHttpInfo($template_id, $from_email, $from_name, $subject, $to, $context); + return $response; + } + + /** + * Operation sendTemplateWithHttpInfo + * + * Render and Send Template + * + * @param string $template_id (required) + * @param string $from_email (required) + * @param string $from_name (required) + * @param string $subject (required) + * @param string $to **Mixed**. string, or JSON encoded array of objects with \\\"email\\\" and \\\"name\\\" keys. `abraham.lincoln@klaviyo.com` OR `[{\\\"name\\\":\\\"Abraham Lincoln\\\",\\\"email\\\":\\\"abraham.lincoln@klaviyo.com\\\"}]` (required) + * @param string $context Optional, JSON object. This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. ex: `{ \\\"name\\\" : \\\"George Washington\\\", \\\"state\\\" : \\\"VA\\\" }` (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function sendTemplateWithHttpInfo($template_id, $from_email, $from_name, $subject, $to, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + $request = $this->sendTemplateRequest($template_id, $from_email, $from_name, $subject, $to, $context); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation sendTemplateAsync + * + * Render and Send Template + * + * @param string $template_id (required) + * @param string $from_email (required) + * @param string $from_name (required) + * @param string $subject (required) + * @param string $to **Mixed**. string, or JSON encoded array of objects with \\\"email\\\" and \\\"name\\\" keys. `abraham.lincoln@klaviyo.com` OR `[{\\\"name\\\":\\\"Abraham Lincoln\\\",\\\"email\\\":\\\"abraham.lincoln@klaviyo.com\\\"}]` (required) + * @param string $context Optional, JSON object. This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. ex: `{ \\\"name\\\" : \\\"George Washington\\\", \\\"state\\\" : \\\"VA\\\" }` (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function sendTemplateAsync($template_id, $from_email, $from_name, $subject, $to, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + return $this->sendTemplateAsyncWithHttpInfo($template_id, $from_email, $from_name, $subject, $to, $context) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation sendTemplateAsyncWithHttpInfo + * + * Render and Send Template + * + * @param string $template_id (required) + * @param string $from_email (required) + * @param string $from_name (required) + * @param string $subject (required) + * @param string $to **Mixed**. string, or JSON encoded array of objects with \\\"email\\\" and \\\"name\\\" keys. `abraham.lincoln@klaviyo.com` OR `[{\\\"name\\\":\\\"Abraham Lincoln\\\",\\\"email\\\":\\\"abraham.lincoln@klaviyo.com\\\"}]` (required) + * @param string $context Optional, JSON object. This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. ex: `{ \\\"name\\\" : \\\"George Washington\\\", \\\"state\\\" : \\\"VA\\\" }` (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function sendTemplateAsyncWithHttpInfo($template_id, $from_email, $from_name, $subject, $to, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + $returnType = 'array'; + $request = $this->sendTemplateRequest($template_id, $from_email, $from_name, $subject, $to, $context); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'sendTemplate' + * + * @param string $template_id (required) + * @param string $from_email (required) + * @param string $from_name (required) + * @param string $subject (required) + * @param string $to **Mixed**. string, or JSON encoded array of objects with \\\"email\\\" and \\\"name\\\" keys. `abraham.lincoln@klaviyo.com` OR `[{\\\"name\\\":\\\"Abraham Lincoln\\\",\\\"email\\\":\\\"abraham.lincoln@klaviyo.com\\\"}]` (required) + * @param string $context Optional, JSON object. This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. ex: `{ \\\"name\\\" : \\\"George Washington\\\", \\\"state\\\" : \\\"VA\\\" }` (optional, default to '{ "name" : "George Washington", "state" : "VA" }') + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function sendTemplateRequest($template_id, $from_email, $from_name, $subject, $to, $context = '{ "name" : "George Washington", "state" : "VA" }') + { + // verify the required parameter 'template_id' is set + if ($template_id === null || (is_array($template_id) && count($template_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $template_id when calling sendTemplate' + ); + } + // verify the required parameter 'from_email' is set + if ($from_email === null || (is_array($from_email) && count($from_email) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $from_email when calling sendTemplate' + ); + } + // verify the required parameter 'from_name' is set + if ($from_name === null || (is_array($from_name) && count($from_name) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $from_name when calling sendTemplate' + ); + } + // verify the required parameter 'subject' is set + if ($subject === null || (is_array($subject) && count($subject) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $subject when calling sendTemplate' + ); + } + // verify the required parameter 'to' is set + if ($to === null || (is_array($to) && count($to) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $to when calling sendTemplate' + ); + } + + $resourcePath = '/v1/email-template/{template_id}/send'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($template_id !== null) { + $resourcePath = str_replace( + '{' . 'template_id' . '}', + ObjectSerializer::toPathValue($template_id), + $resourcePath + ); + } + + // form params + if ($from_email !== null) { + $formParams['from_email'] = ObjectSerializer::toFormValue($from_email); + } + // form params + if ($from_name !== null) { + $formParams['from_name'] = ObjectSerializer::toFormValue($from_name); + } + // form params + if ($subject !== null) { + $formParams['subject'] = ObjectSerializer::toFormValue($subject); + } + // form params + if ($to !== null) { + $formParams['to'] = ObjectSerializer::toFormValue($to); + } + // form params + if ($context !== null) { + $formParams['context'] = ObjectSerializer::toFormValue($context); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation updateTemplate + * + * Update Template + * + * @param string $template_id template_id (required) + * @param string $name The new name of the email template. (optional) + * @param string $html The new HTML content for this template. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array + */ + public function updateTemplate($template_id, $name = null, $html = null) + { + list($response) = $this->updateTemplateWithHttpInfo($template_id, $name, $html); + return $response; + } + + /** + * Operation updateTemplateWithHttpInfo + * + * Update Template + * + * @param string $template_id (required) + * @param string $name The new name of the email template. (optional) + * @param string $html The new HTML content for this template. (optional) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of array, HTTP status code, HTTP response headers (array of strings) + */ + public function updateTemplateWithHttpInfo($template_id, $name = null, $html = null) + { + $request = $this->updateTemplateRequest($template_id, $name, $html); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('array' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'array'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'array', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation updateTemplateAsync + * + * Update Template + * + * @param string $template_id (required) + * @param string $name The new name of the email template. (optional) + * @param string $html The new HTML content for this template. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateTemplateAsync($template_id, $name = null, $html = null) + { + return $this->updateTemplateAsyncWithHttpInfo($template_id, $name, $html) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation updateTemplateAsyncWithHttpInfo + * + * Update Template + * + * @param string $template_id (required) + * @param string $name The new name of the email template. (optional) + * @param string $html The new HTML content for this template. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function updateTemplateAsyncWithHttpInfo($template_id, $name = null, $html = null) + { + $returnType = 'array'; + $request = $this->updateTemplateRequest($template_id, $name, $html); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'updateTemplate' + * + * @param string $template_id (required) + * @param string $name The new name of the email template. (optional) + * @param string $html The new HTML content for this template. (optional) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function updateTemplateRequest($template_id, $name = null, $html = null) + { + // verify the required parameter 'template_id' is set + if ($template_id === null || (is_array($template_id) && count($template_id) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $template_id when calling updateTemplate' + ); + } + + $resourcePath = '/v1/email-template/{template_id}'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + // path params + if ($template_id !== null) { + $resourcePath = str_replace( + '{' . 'template_id' . '}', + ObjectSerializer::toPathValue($template_id), + $resourcePath + ); + } + + // form params + if ($name !== null) { + $formParams['name'] = ObjectSerializer::toFormValue($name); + } + // form params + if ($html !== null) { + $formParams['html'] = ObjectSerializer::toFormValue($html); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + // this endpoint requires API key authentication + $apiKey = $this->config->getApiKeyWithPrefix('api_key'); + if ($apiKey !== null) { + $queryParams['api_key'] = $apiKey; + } + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'PUT', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/lib/API/TrackIdentifyApi.php b/lib/API/TrackIdentifyApi.php new file mode 100644 index 0000000..10ef2c0 --- /dev/null +++ b/lib/API/TrackIdentifyApi.php @@ -0,0 +1,1262 @@ +client = $client ?: new Client(); + $this->config = $config ?: new Configuration(); + $this->headerSelector = $selector ?: new HeaderSelector(); + $this->hostIndex = $hostIndex; + } + + /** + * Set the host index + * + * @param int $hostIndex Host index (required) + */ + public function setHostIndex($hostIndex): void + { + $this->hostIndex = $hostIndex; + } + + /** + * Get the host index + * + * @return int Host index + */ + public function getHostIndex() + { + return $this->hostIndex; + } + + /** + * @return Configuration + */ + public function getConfig() + { + return $this->config; + } + + /** + * Operation identifyGet + * + * Identify Profile (Legacy) + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return string + */ + public function identifyGet($data) + { + list($response) = $this->identifyGetWithHttpInfo($data); + return $response; + } + + /** + * Operation identifyGetWithHttpInfo + * + * Identify Profile (Legacy) + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of string, HTTP status code, HTTP response headers (array of strings) + */ + public function identifyGetWithHttpInfo($data) + { + $request = $this->identifyGetRequest($data); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('string' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'string'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'string', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation identifyGetAsync + * + * Identify Profile (Legacy) + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function identifyGetAsync($data) + { + return $this->identifyGetAsyncWithHttpInfo($data) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation identifyGetAsyncWithHttpInfo + * + * Identify Profile (Legacy) + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function identifyGetAsyncWithHttpInfo($data) + { + $returnType = 'string'; + $request = $this->identifyGetRequest($data); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'identifyGet' + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function identifyGetRequest($data) + { + // verify the required parameter 'data' is set + if ($data === null || (is_array($data) && count($data) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $data when calling identifyGet' + ); + } + + $resourcePath = '/identify'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($data !== null) { + if('form' === 'form' && is_array($data)) { + foreach($data as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['data'] = $data; + } + } + + + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['text/html'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['text/html'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation identifyPost + * + * Identify Profile + * + * @param string $data data (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return string + */ + public function identifyPost($data) + { + list($response) = $this->identifyPostWithHttpInfo($data); + return $response; + } + + /** + * Operation identifyPostWithHttpInfo + * + * Identify Profile + * + * @param string $data (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of string, HTTP status code, HTTP response headers (array of strings) + */ + public function identifyPostWithHttpInfo($data) + { + $request = $this->identifyPostRequest($data); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('string' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'string'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'string', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation identifyPostAsync + * + * Identify Profile + * + * @param string $data (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function identifyPostAsync($data) + { + return $this->identifyPostAsyncWithHttpInfo($data) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation identifyPostAsyncWithHttpInfo + * + * Identify Profile + * + * @param string $data (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function identifyPostAsyncWithHttpInfo($data) + { + $returnType = 'string'; + $request = $this->identifyPostRequest($data); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'identifyPost' + * + * @param string $data (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function identifyPostRequest($data) + { + // verify the required parameter 'data' is set + if ($data === null || (is_array($data) && count($data) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $data when calling identifyPost' + ); + } + + $resourcePath = '/identify'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + // form params + if ($data !== null) { + $formParams['data'] = ObjectSerializer::toFormValue($data); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['text/html'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['text/html'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation trackGet + * + * Track Profile Activity (Legacy) + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return string + */ + public function trackGet($data) + { + list($response) = $this->trackGetWithHttpInfo($data); + return $response; + } + + /** + * Operation trackGetWithHttpInfo + * + * Track Profile Activity (Legacy) + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of string, HTTP status code, HTTP response headers (array of strings) + */ + public function trackGetWithHttpInfo($data) + { + $request = $this->trackGetRequest($data); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('string' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'string'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'string', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation trackGetAsync + * + * Track Profile Activity (Legacy) + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function trackGetAsync($data) + { + return $this->trackGetAsyncWithHttpInfo($data) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation trackGetAsyncWithHttpInfo + * + * Track Profile Activity (Legacy) + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function trackGetAsyncWithHttpInfo($data) + { + $returnType = 'string'; + $request = $this->trackGetRequest($data); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'trackGet' + * + * @param string $data String representation of base64 encoded JSON object (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function trackGetRequest($data) + { + // verify the required parameter 'data' is set + if ($data === null || (is_array($data) && count($data) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $data when calling trackGet' + ); + } + + $resourcePath = '/track'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($data !== null) { + if('form' === 'form' && is_array($data)) { + foreach($data as $key => $value) { + $queryParams[$key] = $value; + } + } + else { + $queryParams['data'] = $data; + } + } + + + + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['text/html'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['text/html'], + [] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'GET', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation trackPost + * + * Track Profile Activity + * + * @param string $data data (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return string + */ + public function trackPost($data) + { + list($response) = $this->trackPostWithHttpInfo($data); + return $response; + } + + /** + * Operation trackPostWithHttpInfo + * + * Track Profile Activity + * + * @param string $data (required) + * + * @throws \Klaviyo\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of string, HTTP status code, HTTP response headers (array of strings) + */ + public function trackPostWithHttpInfo($data) + { + $request = $this->trackPostRequest($data); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + switch($statusCode) { + case 200: + if ('string' === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + } + + $returnType = 'string'; + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + $parsed_content = json_decode($content, TRUE); + if (json_last_error() != JSON_ERROR_NONE) { + $parsed_content = $content; + } + + + return [ + $parsed_content, + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + 'string', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation trackPostAsync + * + * Track Profile Activity + * + * @param string $data (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function trackPostAsync($data) + { + return $this->trackPostAsyncWithHttpInfo($data) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation trackPostAsyncWithHttpInfo + * + * Track Profile Activity + * + * @param string $data (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function trackPostAsyncWithHttpInfo($data) + { + $returnType = 'string'; + $request = $this->trackPostRequest($data); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if ($returnType === '\SplFileObject') { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'trackPost' + * + * @param string $data (required) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function trackPostRequest($data) + { + // verify the required parameter 'data' is set + if ($data === null || (is_array($data) && count($data) === 0)) { + throw new \InvalidArgumentException( + 'Missing the required parameter $data when calling trackPost' + ); + } + + $resourcePath = '/track'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + + + // form params + if ($data !== null) { + $formParams['data'] = ObjectSerializer::toFormValue($data); + } + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['text/html'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['text/html'], + ['application/x-www-form-urlencoded'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\Query::build($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Create http client option + * + * @throws \RuntimeException on file opening failure + * @return array of http client options + */ + protected function createHttpClientOption() + { + $options = []; + if ($this->config->getDebug()) { + $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); + if (!$options[RequestOptions::DEBUG]) { + throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); + } + } + + return $options; + } +} diff --git a/lib/ApiException.php b/lib/ApiException.php new file mode 100644 index 0000000..50477b2 --- /dev/null +++ b/lib/ApiException.php @@ -0,0 +1,120 @@ +responseHeaders = $responseHeaders; + $this->responseBody = $responseBody; + } + + /** + * Gets the HTTP response header + * + * @return string[]|null HTTP response header + */ + public function getResponseHeaders() + { + return $this->responseHeaders; + } + + /** + * Gets the HTTP body of the server response either as Json or string + * + * @return \stdClass|string|null HTTP body of the server response either as \stdClass or string + */ + public function getResponseBody() + { + return $this->responseBody; + } + + /** + * Sets the deserialized response object (during deserialization) + * + * @param mixed $obj Deserialized response object + * + * @return void + */ + public function setResponseObject($obj) + { + $this->responseObject = $obj; + } + + /** + * Gets the deserialized response object (during deserialization) + * + * @return mixed the deserialized response object + */ + public function getResponseObject() + { + return $this->responseObject; + } +} diff --git a/lib/Client.php b/lib/Client.php new file mode 100644 index 0000000..ba0fe81 --- /dev/null +++ b/lib/Client.php @@ -0,0 +1,50 @@ +api_key = $api_key; + $this->num_retries = $num_retries; + $this->wait_seconds = $wait_seconds; + + $this->config = Configuration::getDefaultConfiguration()->setApiKey('api_key', $this->api_key); + + foreach ($this->subclient_names as $subclient_name) { + eval("\$api_instance = new Klaviyo\API\\${subclient_name}Api(new GuzzleHttp\Client(),\$this->config);"); + + $this->$subclient_name = new Subclient( + $api_instance, + $wait_seconds = 3, + $num_retries = 3, + ); + } + } +} \ No newline at end of file diff --git a/lib/Configuration.php b/lib/Configuration.php new file mode 100644 index 0000000..732dfb1 --- /dev/null +++ b/lib/Configuration.php @@ -0,0 +1,486 @@ +tempFolderPath = sys_get_temp_dir(); + } + + /** + * Sets API key + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * @param string $key API key or token + * + * @return $this + */ + public function setApiKey($apiKeyIdentifier, $key) + { + $this->apiKeys[$apiKeyIdentifier] = $key; + return $this; + } + + /** + * Gets API key + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * + * @return null|string API key or token + */ + public function getApiKey($apiKeyIdentifier) + { + return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null; + } + + /** + * Sets the prefix for API key (e.g. Bearer) + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * @param string $prefix API key prefix, e.g. Bearer + * + * @return $this + */ + public function setApiKeyPrefix($apiKeyIdentifier, $prefix) + { + $this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix; + return $this; + } + + /** + * Gets API key prefix + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * + * @return null|string + */ + public function getApiKeyPrefix($apiKeyIdentifier) + { + return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; + } + + /** + * Sets the access token for OAuth + * + * @param string $accessToken Token for OAuth + * + * @return $this + */ + public function setAccessToken($accessToken) + { + $this->accessToken = $accessToken; + return $this; + } + + /** + * Gets the access token for OAuth + * + * @return string Access token for OAuth + */ + public function getAccessToken() + { + return $this->accessToken; + } + + /** + * Sets the username for HTTP basic authentication + * + * @param string $username Username for HTTP basic authentication + * + * @return $this + */ + public function setUsername($username) + { + $this->username = $username; + return $this; + } + + /** + * Gets the username for HTTP basic authentication + * + * @return string Username for HTTP basic authentication + */ + public function getUsername() + { + return $this->username; + } + + /** + * Sets the password for HTTP basic authentication + * + * @param string $password Password for HTTP basic authentication + * + * @return $this + */ + public function setPassword($password) + { + $this->password = $password; + return $this; + } + + /** + * Gets the password for HTTP basic authentication + * + * @return string Password for HTTP basic authentication + */ + public function getPassword() + { + return $this->password; + } + + /** + * Sets the host + * + * @param string $host Host + * + * @return $this + */ + public function setHost($host) + { + $this->host = $host; + return $this; + } + + /** + * Gets the host + * + * @return string Host + */ + public function getHost() + { + return $this->host; + } + + /** + * Sets the user agent of the api client + * + * @param string $userAgent the user agent of the api client + * + * @throws \InvalidArgumentException + * @return $this + */ + public function setUserAgent($userAgent) + { + if (!is_string($userAgent)) { + throw new \InvalidArgumentException('User-agent must be a string.'); + } + + $this->userAgent = $userAgent; + return $this; + } + + /** + * Gets the user agent of the api client + * + * @return string user agent + */ + public function getUserAgent() + { + return $this->userAgent; + } + + /** + * Sets debug flag + * + * @param bool $debug Debug flag + * + * @return $this + */ + public function setDebug($debug) + { + $this->debug = $debug; + return $this; + } + + /** + * Gets the debug flag + * + * @return bool + */ + public function getDebug() + { + return $this->debug; + } + + /** + * Sets the debug file + * + * @param string $debugFile Debug file + * + * @return $this + */ + public function setDebugFile($debugFile) + { + $this->debugFile = $debugFile; + return $this; + } + + /** + * Gets the debug file + * + * @return string + */ + public function getDebugFile() + { + return $this->debugFile; + } + + /** + * Sets the temp folder path + * + * @param string $tempFolderPath Temp folder path + * + * @return $this + */ + public function setTempFolderPath($tempFolderPath) + { + $this->tempFolderPath = $tempFolderPath; + return $this; + } + + /** + * Gets the temp folder path + * + * @return string Temp folder path + */ + public function getTempFolderPath() + { + return $this->tempFolderPath; + } + + /** + * Gets the default configuration instance + * + * @return Configuration + */ + public static function getDefaultConfiguration() + { + if (self::$defaultConfiguration === null) { + self::$defaultConfiguration = new Configuration(); + } + + return self::$defaultConfiguration; + } + + /** + * Sets the default configuration instance + * + * @param Configuration $config An instance of the Configuration Object + * + * @return void + */ + public static function setDefaultConfiguration(Configuration $config) + { + self::$defaultConfiguration = $config; + } + + /** + * Gets the essential information for debugging + * + * @return string The report for debugging + */ + public static function toDebugReport() + { + $report = 'PHP SDK (Klaviyo) Debug Report:' . PHP_EOL; + $report .= ' OS: ' . php_uname() . PHP_EOL; + $report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL; + $report .= ' The version of the OpenAPI document: 2022.03.29' . PHP_EOL; + $report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL; + + return $report; + } + + /** + * Get API key (with prefix if set) + * + * @param string $apiKeyIdentifier name of apikey + * + * @return null|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; + } + + /** + * Returns an array of host settings + * + * @return array an array of host settings + */ + public function getHostSettings() + { + return [ + [ + "url" => "https://a.klaviyo.com/api", + "description" => "Production", + ] + ]; + } + + /** + * Returns URL based on the index and variables + * + * @param int $index index of the host settings + * @param array|null $variables hash of variable and the corresponding value (optional) + * @return string URL based on host settings + */ + public function getHostFromSettings($index, $variables = null) + { + if (null === $variables) { + $variables = []; + } + + $hosts = $this->getHostSettings(); + + // check array index out of bound + if ($index < 0 || $index >= sizeof($hosts)) { + throw new \InvalidArgumentException("Invalid index $index when selecting the host. Must be less than ".sizeof($hosts)); + } + + $host = $hosts[$index]; + $url = $host["url"]; + + // go through variable and assign a value + foreach ($host["variables"] ?? [] as $name => $variable) { + if (array_key_exists($name, $variables)) { // check to see if it's in the variables provided by the user + if (in_array($variables[$name], $variable["enum_values"], true)) { // check to see if the value is in the enum + $url = str_replace("{".$name."}", $variables[$name], $url); + } else { + throw new \InvalidArgumentException("The variable `$name` in the host URL has invalid value ".$variables[$name].". Must be ".join(',', $variable["enum_values"])."."); + } + } else { + // use default value + $url = str_replace("{".$name."}", $variable["default_value"], $url); + } + } + + return $url; + } +} diff --git a/lib/HeaderSelector.php b/lib/HeaderSelector.php new file mode 100644 index 0000000..fca4b10 --- /dev/null +++ b/lib/HeaderSelector.php @@ -0,0 +1,108 @@ +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 null|string Accept (e.g. application/json) + */ + private function selectAcceptHeader($accept) + { + if (count($accept) === 0 || (count($accept) === 1 && $accept[0] === '')) { + return null; + } elseif ($jsonAccept = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept)) { + return implode(',', $jsonAccept); + } 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/Campaign.php b/lib/Model/Campaign.php new file mode 100644 index 0000000..181a3ea --- /dev/null +++ b/lib/Model/Campaign.php @@ -0,0 +1,620 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class Campaign implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'campaign'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'id' => 'string', + 'name' => 'string', + 'subject' => 'string', + 'from_email' => 'string', + 'from_name' => 'string', + 'list_id' => 'string', + 'template' => 'array', + 'status' => 'string', + 'sent_at' => 'string', + 'created' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'id' => null, + 'name' => null, + 'subject' => null, + 'from_email' => null, + 'from_name' => null, + 'list_id' => null, + 'template' => null, + 'status' => null, + 'sent_at' => null, + 'created' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'id' => 'id', + 'name' => 'name', + 'subject' => 'subject', + 'from_email' => 'from_email', + 'from_name' => 'from_name', + 'list_id' => 'list_id', + 'template' => 'template', + 'status' => 'status', + 'sent_at' => 'sent_at', + 'created' => 'created' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'id' => 'setId', + 'name' => 'setName', + 'subject' => 'setSubject', + 'from_email' => 'setFromEmail', + 'from_name' => 'setFromName', + 'list_id' => 'setListId', + 'template' => 'setTemplate', + 'status' => 'setStatus', + 'sent_at' => 'setSentAt', + 'created' => 'setCreated' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'id' => 'getId', + 'name' => 'getName', + 'subject' => 'getSubject', + 'from_email' => 'getFromEmail', + 'from_name' => 'getFromName', + 'list_id' => 'getListId', + 'template' => 'getTemplate', + 'status' => 'getStatus', + 'sent_at' => 'getSentAt', + 'created' => 'getCreated' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['id'] = $data['id'] ?? null; + $this->container['name'] = $data['name'] ?? null; + $this->container['subject'] = $data['subject'] ?? null; + $this->container['from_email'] = $data['from_email'] ?? null; + $this->container['from_name'] = $data['from_name'] ?? null; + $this->container['list_id'] = $data['list_id'] ?? null; + $this->container['template'] = $data['template'] ?? null; + $this->container['status'] = $data['status'] ?? null; + $this->container['sent_at'] = $data['sent_at'] ?? null; + $this->container['created'] = $data['created'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets id + * + * @return string|null + */ + public function getId() + { + return $this->container['id']; + } + + /** + * Sets id + * + * @param string|null $id id + * + * @return self + */ + public function setId($id) + { + $this->container['id'] = $id; + + return $this; + } + + /** + * Gets name + * + * @return string|null + */ + public function getName() + { + return $this->container['name']; + } + + /** + * Sets name + * + * @param string|null $name name + * + * @return self + */ + public function setName($name) + { + $this->container['name'] = $name; + + return $this; + } + + /** + * Gets subject + * + * @return string|null + */ + public function getSubject() + { + return $this->container['subject']; + } + + /** + * Sets subject + * + * @param string|null $subject subject + * + * @return self + */ + public function setSubject($subject) + { + $this->container['subject'] = $subject; + + return $this; + } + + /** + * Gets from_email + * + * @return string|null + */ + public function getFromEmail() + { + return $this->container['from_email']; + } + + /** + * Sets from_email + * + * @param string|null $from_email from_email + * + * @return self + */ + public function setFromEmail($from_email) + { + $this->container['from_email'] = $from_email; + + return $this; + } + + /** + * Gets from_name + * + * @return string|null + */ + public function getFromName() + { + return $this->container['from_name']; + } + + /** + * Sets from_name + * + * @param string|null $from_name from_name + * + * @return self + */ + public function setFromName($from_name) + { + $this->container['from_name'] = $from_name; + + return $this; + } + + /** + * Gets list_id + * + * @return string|null + */ + public function getListId() + { + return $this->container['list_id']; + } + + /** + * Sets list_id + * + * @param string|null $list_id list_id + * + * @return self + */ + public function setListId($list_id) + { + $this->container['list_id'] = $list_id; + + return $this; + } + + /** + * Gets template + * + * @return array|null + */ + public function getTemplate() + { + return $this->container['template']; + } + + /** + * Sets template + * + * @param array|null $template template + * + * @return self + */ + public function setTemplate($template) + { + $this->container['template'] = $template; + + return $this; + } + + /** + * Gets status + * + * @return string|null + */ + public function getStatus() + { + return $this->container['status']; + } + + /** + * Sets status + * + * @param string|null $status status + * + * @return self + */ + public function setStatus($status) + { + $this->container['status'] = $status; + + return $this; + } + + /** + * Gets sent_at + * + * @return string|null + */ + public function getSentAt() + { + return $this->container['sent_at']; + } + + /** + * Sets sent_at + * + * @param string|null $sent_at sent_at + * + * @return self + */ + public function setSentAt($sent_at) + { + $this->container['sent_at'] = $sent_at; + + return $this; + } + + /** + * Gets created + * + * @return string|null + */ + public function getCreated() + { + return $this->container['created']; + } + + /** + * Sets created + * + * @param string|null $created created + * + * @return self + */ + public function setCreated($created) + { + $this->container['created'] = $created; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/CheckMembershipRequest.php b/lib/Model/CheckMembershipRequest.php new file mode 100644 index 0000000..9f26cbd --- /dev/null +++ b/lib/Model/CheckMembershipRequest.php @@ -0,0 +1,380 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class CheckMembershipRequest implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'check_membership_request'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'emails' => 'string[]', + 'phone_numbers' => 'string[]', + 'push_tokens' => 'string[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'emails' => null, + 'phone_numbers' => null, + 'push_tokens' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'emails' => 'emails', + 'phone_numbers' => 'phone_numbers', + 'push_tokens' => 'push_tokens' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'emails' => 'setEmails', + 'phone_numbers' => 'setPhoneNumbers', + 'push_tokens' => 'setPushTokens' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'emails' => 'getEmails', + 'phone_numbers' => 'getPhoneNumbers', + 'push_tokens' => 'getPushTokens' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['emails'] = $data['emails'] ?? null; + $this->container['phone_numbers'] = $data['phone_numbers'] ?? null; + $this->container['push_tokens'] = $data['push_tokens'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets emails + * + * @return string[]|null + */ + public function getEmails() + { + return $this->container['emails']; + } + + /** + * Sets emails + * + * @param string[]|null $emails List of email addresses + * + * @return self + */ + public function setEmails($emails) + { + $this->container['emails'] = $emails; + + return $this; + } + + /** + * Gets phone_numbers + * + * @return string[]|null + */ + public function getPhoneNumbers() + { + return $this->container['phone_numbers']; + } + + /** + * Sets phone_numbers + * + * @param string[]|null $phone_numbers List of phone numbers + * + * @return self + */ + public function setPhoneNumbers($phone_numbers) + { + $this->container['phone_numbers'] = $phone_numbers; + + return $this; + } + + /** + * Gets push_tokens + * + * @return string[]|null + */ + public function getPushTokens() + { + return $this->container['push_tokens']; + } + + /** + * Sets push_tokens + * + * @param string[]|null $push_tokens push_tokens + * + * @return self + */ + public function setPushTokens($push_tokens) + { + $this->container['push_tokens'] = $push_tokens; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/DeleteEmail.php b/lib/Model/DeleteEmail.php new file mode 100644 index 0000000..15e3dab --- /dev/null +++ b/lib/Model/DeleteEmail.php @@ -0,0 +1,320 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class DeleteEmail implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'delete_email'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'email' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'email' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'email' => 'email' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'email' => 'setEmail' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'email' => 'getEmail' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['email'] = $data['email'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets email + * + * @return string|null + */ + public function getEmail() + { + return $this->container['email']; + } + + /** + * Sets email + * + * @param string|null $email email + * + * @return self + */ + public function setEmail($email) + { + $this->container['email'] = $email; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/DeletePerson.php b/lib/Model/DeletePerson.php new file mode 100644 index 0000000..34c0ace --- /dev/null +++ b/lib/Model/DeletePerson.php @@ -0,0 +1,320 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class DeletePerson implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'delete_person'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'person_id' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'person_id' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'person_id' => 'person_id' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'person_id' => 'setPersonId' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'person_id' => 'getPersonId' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['person_id'] = $data['person_id'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets person_id + * + * @return string|null + */ + public function getPersonId() + { + return $this->container['person_id']; + } + + /** + * Sets person_id + * + * @param string|null $person_id person_id + * + * @return self + */ + public function setPersonId($person_id) + { + $this->container['person_id'] = $person_id; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/DeletePhone.php b/lib/Model/DeletePhone.php new file mode 100644 index 0000000..8bb55ec --- /dev/null +++ b/lib/Model/DeletePhone.php @@ -0,0 +1,320 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class DeletePhone implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'delete_phone'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'phone_number' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'phone_number' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'phone_number' => 'phone_number' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'phone_number' => 'setPhoneNumber' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'phone_number' => 'getPhoneNumber' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['phone_number'] = $data['phone_number'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets phone_number + * + * @return string|null + */ + public function getPhoneNumber() + { + return $this->container['phone_number']; + } + + /** + * Sets phone_number + * + * @param string|null $phone_number Phone Number + * + * @return self + */ + public function setPhoneNumber($phone_number) + { + $this->container['phone_number'] = $phone_number; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/DeprecatedGetListResponse.php b/lib/Model/DeprecatedGetListResponse.php new file mode 100644 index 0000000..4cdd1da --- /dev/null +++ b/lib/Model/DeprecatedGetListResponse.php @@ -0,0 +1,515 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class DeprecatedGetListResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'deprecated_get_list_response'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'start' => 'int', + 'end' => 'int', + 'page' => 'int', + 'size' => 'int', + 'total' => 'int', + 'data' => '\Klaviyo\Model\DeprecatedGetListResponseData[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'start' => null, + 'end' => null, + 'page' => null, + 'size' => null, + 'total' => null, + 'data' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'start' => 'start', + 'end' => 'end', + 'page' => 'page', + 'size' => 'size', + 'total' => 'total', + 'data' => 'data' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'start' => 'setStart', + 'end' => 'setEnd', + 'page' => 'setPage', + 'size' => 'setSize', + 'total' => 'setTotal', + 'data' => 'setData' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'start' => 'getStart', + 'end' => 'getEnd', + 'page' => 'getPage', + 'size' => 'getSize', + 'total' => 'getTotal', + 'data' => 'getData' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['start'] = $data['start'] ?? null; + $this->container['end'] = $data['end'] ?? null; + $this->container['page'] = $data['page'] ?? null; + $this->container['size'] = $data['size'] ?? null; + $this->container['total'] = $data['total'] ?? null; + $this->container['data'] = $data['data'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if (!is_null($this->container['data']) && (count($this->container['data']) > 100)) { + $invalidProperties[] = "invalid value for 'data', number of items must be less than or equal to 100."; + } + + if (!is_null($this->container['data']) && (count($this->container['data']) < 1)) { + $invalidProperties[] = "invalid value for 'data', number of items must be greater than or equal to 1."; + } + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets start + * + * @return int|null + */ + public function getStart() + { + return $this->container['start']; + } + + /** + * Sets start + * + * @param int|null $start start + * + * @return self + */ + public function setStart($start) + { + $this->container['start'] = $start; + + return $this; + } + + /** + * Gets end + * + * @return int|null + */ + public function getEnd() + { + return $this->container['end']; + } + + /** + * Sets end + * + * @param int|null $end end + * + * @return self + */ + public function setEnd($end) + { + $this->container['end'] = $end; + + return $this; + } + + /** + * Gets page + * + * @return int|null + */ + public function getPage() + { + return $this->container['page']; + } + + /** + * Sets page + * + * @param int|null $page page + * + * @return self + */ + public function setPage($page) + { + $this->container['page'] = $page; + + return $this; + } + + /** + * Gets size + * + * @return int|null + */ + public function getSize() + { + return $this->container['size']; + } + + /** + * Sets size + * + * @param int|null $size size + * + * @return self + */ + public function setSize($size) + { + $this->container['size'] = $size; + + return $this; + } + + /** + * Gets total + * + * @return int|null + */ + public function getTotal() + { + return $this->container['total']; + } + + /** + * Sets total + * + * @param int|null $total total + * + * @return self + */ + public function setTotal($total) + { + $this->container['total'] = $total; + + return $this; + } + + /** + * Gets data + * + * @return \Klaviyo\Model\DeprecatedGetListResponseData[]|null + */ + public function getData() + { + return $this->container['data']; + } + + /** + * Sets data + * + * @param \Klaviyo\Model\DeprecatedGetListResponseData[]|null $data data + * + * @return self + */ + public function setData($data) + { + + if (!is_null($data) && (count($data) > 100)) { + throw new \InvalidArgumentException('invalid value for $data when calling DeprecatedGetListResponse., number of items must be less than or equal to 100.'); + } + if (!is_null($data) && (count($data) < 1)) { + throw new \InvalidArgumentException('invalid length for $data when calling DeprecatedGetListResponse., number of items must be greater than or equal to 1.'); + } + $this->container['data'] = $data; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/DeprecatedGetListResponseData.php b/lib/Model/DeprecatedGetListResponseData.php new file mode 100644 index 0000000..2f65365 --- /dev/null +++ b/lib/Model/DeprecatedGetListResponseData.php @@ -0,0 +1,470 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class DeprecatedGetListResponseData implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'deprecated_get_list_response_data'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'id' => 'string', + 'type' => 'string', + 'created' => 'string', + 'updated' => 'string', + 'person_count' => 'int' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'id' => null, + 'type' => null, + 'created' => null, + 'updated' => null, + 'person_count' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'id' => 'id', + 'type' => 'type', + 'created' => 'created', + 'updated' => 'updated', + 'person_count' => 'person_count' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'id' => 'setId', + 'type' => 'setType', + 'created' => 'setCreated', + 'updated' => 'setUpdated', + 'person_count' => 'setPersonCount' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'id' => 'getId', + 'type' => 'getType', + 'created' => 'getCreated', + 'updated' => 'getUpdated', + 'person_count' => 'getPersonCount' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['id'] = $data['id'] ?? null; + $this->container['type'] = $data['type'] ?? null; + $this->container['created'] = $data['created'] ?? null; + $this->container['updated'] = $data['updated'] ?? null; + $this->container['person_count'] = $data['person_count'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets id + * + * @return string|null + */ + public function getId() + { + return $this->container['id']; + } + + /** + * Sets id + * + * @param string|null $id id + * + * @return self + */ + public function setId($id) + { + $this->container['id'] = $id; + + return $this; + } + + /** + * Gets type + * + * @return string|null + */ + public function getType() + { + return $this->container['type']; + } + + /** + * Sets type + * + * @param string|null $type type + * + * @return self + */ + public function setType($type) + { + $this->container['type'] = $type; + + return $this; + } + + /** + * Gets created + * + * @return string|null + */ + public function getCreated() + { + return $this->container['created']; + } + + /** + * Sets created + * + * @param string|null $created created + * + * @return self + */ + public function setCreated($created) + { + $this->container['created'] = $created; + + return $this; + } + + /** + * Gets updated + * + * @return string|null + */ + public function getUpdated() + { + return $this->container['updated']; + } + + /** + * Sets updated + * + * @param string|null $updated updated + * + * @return self + */ + public function setUpdated($updated) + { + $this->container['updated'] = $updated; + + return $this; + } + + /** + * Gets person_count + * + * @return int|null + */ + public function getPersonCount() + { + return $this->container['person_count']; + } + + /** + * Sets person_count + * + * @param int|null $person_count person_count + * + * @return self + */ + public function setPersonCount($person_count) + { + $this->container['person_count'] = $person_count; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/GlobalExclusionResponseData.php b/lib/Model/GlobalExclusionResponseData.php new file mode 100644 index 0000000..df4391c --- /dev/null +++ b/lib/Model/GlobalExclusionResponseData.php @@ -0,0 +1,500 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class GlobalExclusionResponseData implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'global_exclusion_response_data'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'data' => 'array[]', + 'page' => 'int', + 'start' => 'int', + 'end' => 'int', + 'total' => 'int', + 'page_size' => 'int' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'data' => null, + 'page' => null, + 'start' => null, + 'end' => null, + 'total' => null, + 'page_size' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'data' => 'data', + 'page' => 'page', + 'start' => 'start', + 'end' => 'end', + 'total' => 'total', + 'page_size' => 'page_size' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'data' => 'setData', + 'page' => 'setPage', + 'start' => 'setStart', + 'end' => 'setEnd', + 'total' => 'setTotal', + 'page_size' => 'setPageSize' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'data' => 'getData', + 'page' => 'getPage', + 'start' => 'getStart', + 'end' => 'getEnd', + 'total' => 'getTotal', + 'page_size' => 'getPageSize' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['data'] = $data['data'] ?? null; + $this->container['page'] = $data['page'] ?? null; + $this->container['start'] = $data['start'] ?? null; + $this->container['end'] = $data['end'] ?? null; + $this->container['total'] = $data['total'] ?? null; + $this->container['page_size'] = $data['page_size'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets data + * + * @return array[]|null + */ + public function getData() + { + return $this->container['data']; + } + + /** + * Sets data + * + * @param array[]|null $data data + * + * @return self + */ + public function setData($data) + { + $this->container['data'] = $data; + + return $this; + } + + /** + * Gets page + * + * @return int|null + */ + public function getPage() + { + return $this->container['page']; + } + + /** + * Sets page + * + * @param int|null $page page + * + * @return self + */ + public function setPage($page) + { + $this->container['page'] = $page; + + return $this; + } + + /** + * Gets start + * + * @return int|null + */ + public function getStart() + { + return $this->container['start']; + } + + /** + * Sets start + * + * @param int|null $start start + * + * @return self + */ + public function setStart($start) + { + $this->container['start'] = $start; + + return $this; + } + + /** + * Gets end + * + * @return int|null + */ + public function getEnd() + { + return $this->container['end']; + } + + /** + * Sets end + * + * @param int|null $end end + * + * @return self + */ + public function setEnd($end) + { + $this->container['end'] = $end; + + return $this; + } + + /** + * Gets total + * + * @return int|null + */ + public function getTotal() + { + return $this->container['total']; + } + + /** + * Sets total + * + * @param int|null $total total + * + * @return self + */ + public function setTotal($total) + { + $this->container['total'] = $total; + + return $this; + } + + /** + * Gets page_size + * + * @return int|null + */ + public function getPageSize() + { + return $this->container['page_size']; + } + + /** + * Sets page_size + * + * @param int|null $page_size page_size + * + * @return self + */ + public function setPageSize($page_size) + { + $this->container['page_size'] = $page_size; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/IdentifyPayload.php b/lib/Model/IdentifyPayload.php new file mode 100644 index 0000000..17eecc4 --- /dev/null +++ b/lib/Model/IdentifyPayload.php @@ -0,0 +1,356 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class IdentifyPayload implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'identify_payload'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'token' => 'string', + 'properties' => '\Klaviyo\Model\IdentifyPayloadProperties' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'token' => null, + 'properties' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'token' => 'token', + 'properties' => 'properties' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'token' => 'setToken', + 'properties' => 'setProperties' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'token' => 'getToken', + 'properties' => 'getProperties' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['token'] = $data['token'] ?? null; + $this->container['properties'] = $data['properties'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['token'] === null) { + $invalidProperties[] = "'token' can't be null"; + } + if ($this->container['properties'] === null) { + $invalidProperties[] = "'properties' can't be null"; + } + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets token + * + * @return string + */ + public function getToken() + { + return $this->container['token']; + } + + /** + * Sets token + * + * @param string $token token + * + * @return self + */ + public function setToken($token) + { + $this->container['token'] = $token; + + return $this; + } + + /** + * Gets properties + * + * @return \Klaviyo\Model\IdentifyPayloadProperties + */ + public function getProperties() + { + return $this->container['properties']; + } + + /** + * Sets properties + * + * @param \Klaviyo\Model\IdentifyPayloadProperties $properties properties + * + * @return self + */ + public function setProperties($properties) + { + $this->container['properties'] = $properties; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/IdentifyPayloadProperties.php b/lib/Model/IdentifyPayloadProperties.php new file mode 100644 index 0000000..6c19412 --- /dev/null +++ b/lib/Model/IdentifyPayloadProperties.php @@ -0,0 +1,680 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class IdentifyPayloadProperties implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'identify_payload_properties'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'email' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'phone_number' => 'string', + 'title' => 'string', + 'organization' => 'string', + 'city' => 'string', + 'region' => 'string', + 'country' => 'string', + 'zip' => 'string', + 'image' => 'string', + 'consent' => 'string', + 'your_custom_field' => 'OneOfStringIntegerNumberBooleanArray' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'email' => null, + 'first_name' => null, + 'last_name' => null, + 'phone_number' => null, + 'title' => null, + 'organization' => null, + 'city' => null, + 'region' => null, + 'country' => null, + 'zip' => null, + 'image' => null, + 'consent' => null, + 'your_custom_field' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'email' => '$email', + 'first_name' => '$first_name', + 'last_name' => '$last_name', + 'phone_number' => '$phone_number', + 'title' => '$title', + 'organization' => '$organization', + 'city' => '$city', + 'region' => '$region', + 'country' => '$country', + 'zip' => '$zip', + 'image' => '$image', + 'consent' => '$consent', + 'your_custom_field' => 'YOUR_CUSTOM_FIELD' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'email' => 'setEmail', + 'first_name' => 'setFirstName', + 'last_name' => 'setLastName', + 'phone_number' => 'setPhoneNumber', + 'title' => 'setTitle', + 'organization' => 'setOrganization', + 'city' => 'setCity', + 'region' => 'setRegion', + 'country' => 'setCountry', + 'zip' => 'setZip', + 'image' => 'setImage', + 'consent' => 'setConsent', + 'your_custom_field' => 'setYourCustomField' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'email' => 'getEmail', + 'first_name' => 'getFirstName', + 'last_name' => 'getLastName', + 'phone_number' => 'getPhoneNumber', + 'title' => 'getTitle', + 'organization' => 'getOrganization', + 'city' => 'getCity', + 'region' => 'getRegion', + 'country' => 'getCountry', + 'zip' => 'getZip', + 'image' => 'getImage', + 'consent' => 'getConsent', + 'your_custom_field' => 'getYourCustomField' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['email'] = $data['email'] ?? null; + $this->container['first_name'] = $data['first_name'] ?? null; + $this->container['last_name'] = $data['last_name'] ?? null; + $this->container['phone_number'] = $data['phone_number'] ?? null; + $this->container['title'] = $data['title'] ?? null; + $this->container['organization'] = $data['organization'] ?? null; + $this->container['city'] = $data['city'] ?? null; + $this->container['region'] = $data['region'] ?? null; + $this->container['country'] = $data['country'] ?? null; + $this->container['zip'] = $data['zip'] ?? null; + $this->container['image'] = $data['image'] ?? null; + $this->container['consent'] = $data['consent'] ?? null; + $this->container['your_custom_field'] = $data['your_custom_field'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets email + * + * @return string|null + */ + public function getEmail() + { + return $this->container['email']; + } + + /** + * Sets email + * + * @param string|null $email email + * + * @return self + */ + public function setEmail($email) + { + $this->container['email'] = $email; + + return $this; + } + + /** + * Gets first_name + * + * @return string|null + */ + public function getFirstName() + { + return $this->container['first_name']; + } + + /** + * Sets first_name + * + * @param string|null $first_name first_name + * + * @return self + */ + public function setFirstName($first_name) + { + $this->container['first_name'] = $first_name; + + return $this; + } + + /** + * Gets last_name + * + * @return string|null + */ + public function getLastName() + { + return $this->container['last_name']; + } + + /** + * Sets last_name + * + * @param string|null $last_name last_name + * + * @return self + */ + public function setLastName($last_name) + { + $this->container['last_name'] = $last_name; + + return $this; + } + + /** + * Gets phone_number + * + * @return string|null + */ + public function getPhoneNumber() + { + return $this->container['phone_number']; + } + + /** + * Sets phone_number + * + * @param string|null $phone_number phone_number + * + * @return self + */ + public function setPhoneNumber($phone_number) + { + $this->container['phone_number'] = $phone_number; + + return $this; + } + + /** + * Gets title + * + * @return string|null + */ + public function getTitle() + { + return $this->container['title']; + } + + /** + * Sets title + * + * @param string|null $title title + * + * @return self + */ + public function setTitle($title) + { + $this->container['title'] = $title; + + return $this; + } + + /** + * Gets organization + * + * @return string|null + */ + public function getOrganization() + { + return $this->container['organization']; + } + + /** + * Sets organization + * + * @param string|null $organization organization + * + * @return self + */ + public function setOrganization($organization) + { + $this->container['organization'] = $organization; + + return $this; + } + + /** + * Gets city + * + * @return string|null + */ + public function getCity() + { + return $this->container['city']; + } + + /** + * Sets city + * + * @param string|null $city city + * + * @return self + */ + public function setCity($city) + { + $this->container['city'] = $city; + + return $this; + } + + /** + * Gets region + * + * @return string|null + */ + public function getRegion() + { + return $this->container['region']; + } + + /** + * Sets region + * + * @param string|null $region region + * + * @return self + */ + public function setRegion($region) + { + $this->container['region'] = $region; + + return $this; + } + + /** + * Gets country + * + * @return string|null + */ + public function getCountry() + { + return $this->container['country']; + } + + /** + * Sets country + * + * @param string|null $country country + * + * @return self + */ + public function setCountry($country) + { + $this->container['country'] = $country; + + return $this; + } + + /** + * Gets zip + * + * @return string|null + */ + public function getZip() + { + return $this->container['zip']; + } + + /** + * Sets zip + * + * @param string|null $zip zip + * + * @return self + */ + public function setZip($zip) + { + $this->container['zip'] = $zip; + + return $this; + } + + /** + * Gets image + * + * @return string|null + */ + public function getImage() + { + return $this->container['image']; + } + + /** + * Sets image + * + * @param string|null $image image + * + * @return self + */ + public function setImage($image) + { + $this->container['image'] = $image; + + return $this; + } + + /** + * Gets consent + * + * @return string|null + */ + public function getConsent() + { + return $this->container['consent']; + } + + /** + * Sets consent + * + * @param string|null $consent consent + * + * @return self + */ + public function setConsent($consent) + { + $this->container['consent'] = $consent; + + return $this; + } + + /** + * Gets your_custom_field + * + * @return OneOfStringIntegerNumberBooleanArray|null + */ + public function getYourCustomField() + { + return $this->container['your_custom_field']; + } + + /** + * Sets your_custom_field + * + * @param OneOfStringIntegerNumberBooleanArray|null $your_custom_field your_custom_field + * + * @return self + */ + public function setYourCustomField($your_custom_field) + { + $this->container['your_custom_field'] = $your_custom_field; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/InlineObject.php b/lib/Model/InlineObject.php new file mode 100644 index 0000000..2ec53e3 --- /dev/null +++ b/lib/Model/InlineObject.php @@ -0,0 +1,320 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class InlineObject implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'inline_object'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'exchange_id' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'exchange_id' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'exchange_id' => 'exchange_id' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'exchange_id' => 'setExchangeId' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'exchange_id' => 'getExchangeId' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['exchange_id'] = $data['exchange_id'] ?? 'EXCHANGE_ID'; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets exchange_id + * + * @return string|null + */ + public function getExchangeId() + { + return $this->container['exchange_id']; + } + + /** + * Sets exchange_id + * + * @param string|null $exchange_id exchange_id + * + * @return self + */ + public function setExchangeId($exchange_id) + { + $this->container['exchange_id'] = $exchange_id; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/InlineObject3.php b/lib/Model/InlineObject3.php new file mode 100644 index 0000000..5bb6623 --- /dev/null +++ b/lib/Model/InlineObject3.php @@ -0,0 +1,324 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class InlineObject3 implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'inline_object_3'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'profiles' => 'array[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'profiles' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'profiles' => 'profiles' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'profiles' => 'setProfiles' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'profiles' => 'getProfiles' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['profiles'] = $data['profiles'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['profiles'] === null) { + $invalidProperties[] = "'profiles' can't be null"; + } + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets profiles + * + * @return array[] + */ + public function getProfiles() + { + return $this->container['profiles']; + } + + /** + * Sets profiles + * + * @param array[] $profiles profiles + * + * @return self + */ + public function setProfiles($profiles) + { + $this->container['profiles'] = $profiles; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/InlineObject4.php b/lib/Model/InlineObject4.php new file mode 100644 index 0000000..cdba39c --- /dev/null +++ b/lib/Model/InlineObject4.php @@ -0,0 +1,339 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class InlineObject4 implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'inline_object_4'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'profiles' => 'array[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'profiles' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'profiles' => 'profiles' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'profiles' => 'setProfiles' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'profiles' => 'getProfiles' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['profiles'] = $data['profiles'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['profiles'] === null) { + $invalidProperties[] = "'profiles' can't be null"; + } + if ((count($this->container['profiles']) > 100)) { + $invalidProperties[] = "invalid value for 'profiles', number of items must be less than or equal to 100."; + } + + if ((count($this->container['profiles']) < 0)) { + $invalidProperties[] = "invalid value for 'profiles', number of items must be greater than or equal to 0."; + } + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets profiles + * + * @return array[] + */ + public function getProfiles() + { + return $this->container['profiles']; + } + + /** + * Sets profiles + * + * @param array[] $profiles profiles + * + * @return self + */ + public function setProfiles($profiles) + { + + if ((count($profiles) > 100)) { + throw new \InvalidArgumentException('invalid value for $profiles when calling InlineObject4., number of items must be less than or equal to 100.'); + } + if ((count($profiles) < 0)) { + throw new \InvalidArgumentException('invalid length for $profiles when calling InlineObject4., number of items must be greater than or equal to 0.'); + } + $this->container['profiles'] = $profiles; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/InlineObject5.php b/lib/Model/InlineObject5.php new file mode 100644 index 0000000..dd07ede --- /dev/null +++ b/lib/Model/InlineObject5.php @@ -0,0 +1,408 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class InlineObject5 implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'inline_object_5'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'emails' => 'string[]', + 'phone_numbers' => 'string[]', + 'push_tokens' => 'string[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'emails' => null, + 'phone_numbers' => null, + 'push_tokens' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'emails' => 'emails', + 'phone_numbers' => 'phone_numbers', + 'push_tokens' => 'push_tokens' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'emails' => 'setEmails', + 'phone_numbers' => 'setPhoneNumbers', + 'push_tokens' => 'setPushTokens' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'emails' => 'getEmails', + 'phone_numbers' => 'getPhoneNumbers', + 'push_tokens' => 'getPushTokens' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['emails'] = $data['emails'] ?? null; + $this->container['phone_numbers'] = $data['phone_numbers'] ?? null; + $this->container['push_tokens'] = $data['push_tokens'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if (!is_null($this->container['emails']) && (count($this->container['emails']) < 0)) { + $invalidProperties[] = "invalid value for 'emails', number of items must be greater than or equal to 0."; + } + + if (!is_null($this->container['phone_numbers']) && (count($this->container['phone_numbers']) < 0)) { + $invalidProperties[] = "invalid value for 'phone_numbers', number of items must be greater than or equal to 0."; + } + + if (!is_null($this->container['push_tokens']) && (count($this->container['push_tokens']) < 0)) { + $invalidProperties[] = "invalid value for 'push_tokens', number of items must be greater than or equal to 0."; + } + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets emails + * + * @return string[]|null + */ + public function getEmails() + { + return $this->container['emails']; + } + + /** + * Sets emails + * + * @param string[]|null $emails emails + * + * @return self + */ + public function setEmails($emails) + { + + + if (!is_null($emails) && (count($emails) < 0)) { + throw new \InvalidArgumentException('invalid length for $emails when calling InlineObject5., number of items must be greater than or equal to 0.'); + } + $this->container['emails'] = $emails; + + return $this; + } + + /** + * Gets phone_numbers + * + * @return string[]|null + */ + public function getPhoneNumbers() + { + return $this->container['phone_numbers']; + } + + /** + * Sets phone_numbers + * + * @param string[]|null $phone_numbers phone_numbers + * + * @return self + */ + public function setPhoneNumbers($phone_numbers) + { + + + if (!is_null($phone_numbers) && (count($phone_numbers) < 0)) { + throw new \InvalidArgumentException('invalid length for $phone_numbers when calling InlineObject5., number of items must be greater than or equal to 0.'); + } + $this->container['phone_numbers'] = $phone_numbers; + + return $this; + } + + /** + * Gets push_tokens + * + * @return string[]|null + */ + public function getPushTokens() + { + return $this->container['push_tokens']; + } + + /** + * Sets push_tokens + * + * @param string[]|null $push_tokens push_tokens + * + * @return self + */ + public function setPushTokens($push_tokens) + { + + + if (!is_null($push_tokens) && (count($push_tokens) < 0)) { + throw new \InvalidArgumentException('invalid length for $push_tokens when calling InlineObject5., number of items must be greater than or equal to 0.'); + } + $this->container['push_tokens'] = $push_tokens; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/Metric.php b/lib/Model/Metric.php new file mode 100644 index 0000000..8e130c5 --- /dev/null +++ b/lib/Model/Metric.php @@ -0,0 +1,470 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class Metric implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'metric'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'id' => 'string', + 'name' => 'string', + 'integration' => 'array', + 'created' => 'string', + 'updated' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'id' => null, + 'name' => null, + 'integration' => null, + 'created' => null, + 'updated' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'id' => 'id', + 'name' => 'name', + 'integration' => 'integration', + 'created' => 'created', + 'updated' => 'updated' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'id' => 'setId', + 'name' => 'setName', + 'integration' => 'setIntegration', + 'created' => 'setCreated', + 'updated' => 'setUpdated' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'id' => 'getId', + 'name' => 'getName', + 'integration' => 'getIntegration', + 'created' => 'getCreated', + 'updated' => 'getUpdated' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['id'] = $data['id'] ?? null; + $this->container['name'] = $data['name'] ?? null; + $this->container['integration'] = $data['integration'] ?? null; + $this->container['created'] = $data['created'] ?? null; + $this->container['updated'] = $data['updated'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets id + * + * @return string|null + */ + public function getId() + { + return $this->container['id']; + } + + /** + * Sets id + * + * @param string|null $id id + * + * @return self + */ + public function setId($id) + { + $this->container['id'] = $id; + + return $this; + } + + /** + * Gets name + * + * @return string|null + */ + public function getName() + { + return $this->container['name']; + } + + /** + * Sets name + * + * @param string|null $name name + * + * @return self + */ + public function setName($name) + { + $this->container['name'] = $name; + + return $this; + } + + /** + * Gets integration + * + * @return array|null + */ + public function getIntegration() + { + return $this->container['integration']; + } + + /** + * Sets integration + * + * @param array|null $integration integration + * + * @return self + */ + public function setIntegration($integration) + { + $this->container['integration'] = $integration; + + return $this; + } + + /** + * Gets created + * + * @return string|null + */ + public function getCreated() + { + return $this->container['created']; + } + + /** + * Sets created + * + * @param string|null $created created + * + * @return self + */ + public function setCreated($created) + { + $this->container['created'] = $created; + + return $this; + } + + /** + * Gets updated + * + * @return string|null + */ + public function getUpdated() + { + return $this->container['updated']; + } + + /** + * Sets updated + * + * @param string|null $updated updated + * + * @return self + */ + public function setUpdated($updated) + { + $this->container['updated'] = $updated; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/MetricExport.php b/lib/Model/MetricExport.php new file mode 100644 index 0000000..3602d01 --- /dev/null +++ b/lib/Model/MetricExport.php @@ -0,0 +1,530 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class MetricExport implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'metric_export'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'metric' => 'array', + 'start_date' => 'string', + 'end_date' => 'string', + 'unit' => 'string', + 'measurement' => 'string', + 'by' => 'string', + 'where' => 'string', + 'results' => 'array[]' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'metric' => null, + 'start_date' => null, + 'end_date' => null, + 'unit' => null, + 'measurement' => null, + 'by' => null, + 'where' => null, + 'results' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'metric' => 'metric', + 'start_date' => 'start_date', + 'end_date' => 'end_date', + 'unit' => 'unit', + 'measurement' => 'measurement', + 'by' => 'by', + 'where' => 'where', + 'results' => 'results' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'metric' => 'setMetric', + 'start_date' => 'setStartDate', + 'end_date' => 'setEndDate', + 'unit' => 'setUnit', + 'measurement' => 'setMeasurement', + 'by' => 'setBy', + 'where' => 'setWhere', + 'results' => 'setResults' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'metric' => 'getMetric', + 'start_date' => 'getStartDate', + 'end_date' => 'getEndDate', + 'unit' => 'getUnit', + 'measurement' => 'getMeasurement', + 'by' => 'getBy', + 'where' => 'getWhere', + 'results' => 'getResults' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['metric'] = $data['metric'] ?? null; + $this->container['start_date'] = $data['start_date'] ?? null; + $this->container['end_date'] = $data['end_date'] ?? null; + $this->container['unit'] = $data['unit'] ?? null; + $this->container['measurement'] = $data['measurement'] ?? null; + $this->container['by'] = $data['by'] ?? null; + $this->container['where'] = $data['where'] ?? null; + $this->container['results'] = $data['results'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets metric + * + * @return array|null + */ + public function getMetric() + { + return $this->container['metric']; + } + + /** + * Sets metric + * + * @param array|null $metric metric + * + * @return self + */ + public function setMetric($metric) + { + $this->container['metric'] = $metric; + + return $this; + } + + /** + * Gets start_date + * + * @return string|null + */ + public function getStartDate() + { + return $this->container['start_date']; + } + + /** + * Sets start_date + * + * @param string|null $start_date start_date + * + * @return self + */ + public function setStartDate($start_date) + { + $this->container['start_date'] = $start_date; + + return $this; + } + + /** + * Gets end_date + * + * @return string|null + */ + public function getEndDate() + { + return $this->container['end_date']; + } + + /** + * Sets end_date + * + * @param string|null $end_date end_date + * + * @return self + */ + public function setEndDate($end_date) + { + $this->container['end_date'] = $end_date; + + return $this; + } + + /** + * Gets unit + * + * @return string|null + */ + public function getUnit() + { + return $this->container['unit']; + } + + /** + * Sets unit + * + * @param string|null $unit unit + * + * @return self + */ + public function setUnit($unit) + { + $this->container['unit'] = $unit; + + return $this; + } + + /** + * Gets measurement + * + * @return string|null + */ + public function getMeasurement() + { + return $this->container['measurement']; + } + + /** + * Sets measurement + * + * @param string|null $measurement measurement + * + * @return self + */ + public function setMeasurement($measurement) + { + $this->container['measurement'] = $measurement; + + return $this; + } + + /** + * Gets by + * + * @return string|null + */ + public function getBy() + { + return $this->container['by']; + } + + /** + * Sets by + * + * @param string|null $by by + * + * @return self + */ + public function setBy($by) + { + $this->container['by'] = $by; + + return $this; + } + + /** + * Gets where + * + * @return string|null + */ + public function getWhere() + { + return $this->container['where']; + } + + /** + * Sets where + * + * @param string|null $where where + * + * @return self + */ + public function setWhere($where) + { + $this->container['where'] = $where; + + return $this; + } + + /** + * Gets results + * + * @return array[]|null + */ + public function getResults() + { + return $this->container['results']; + } + + /** + * Sets results + * + * @param array[]|null $results results + * + * @return self + */ + public function setResults($results) + { + $this->container['results'] = $results; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/MetricTimeline.php b/lib/Model/MetricTimeline.php new file mode 100644 index 0000000..699162f --- /dev/null +++ b/lib/Model/MetricTimeline.php @@ -0,0 +1,425 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class MetricTimeline implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'metric_timeline'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'count' => 'int', + 'data' => '\Klaviyo\Model\MetricTimelineData[]', + 'next' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'count' => null, + 'data' => null, + 'next' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'count' => 'count', + 'data' => 'data', + 'next' => 'next' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'count' => 'setCount', + 'data' => 'setData', + 'next' => 'setNext' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'count' => 'getCount', + 'data' => 'getData', + 'next' => 'getNext' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['count'] = $data['count'] ?? null; + $this->container['data'] = $data['data'] ?? null; + $this->container['next'] = $data['next'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if (!is_null($this->container['data']) && (count($this->container['data']) > 100)) { + $invalidProperties[] = "invalid value for 'data', number of items must be less than or equal to 100."; + } + + if (!is_null($this->container['data']) && (count($this->container['data']) < 0)) { + $invalidProperties[] = "invalid value for 'data', number of items must be greater than or equal to 0."; + } + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets count + * + * @return int|null + */ + public function getCount() + { + return $this->container['count']; + } + + /** + * Sets count + * + * @param int|null $count count + * + * @return self + */ + public function setCount($count) + { + $this->container['count'] = $count; + + return $this; + } + + /** + * Gets data + * + * @return \Klaviyo\Model\MetricTimelineData[]|null + */ + public function getData() + { + return $this->container['data']; + } + + /** + * Sets data + * + * @param \Klaviyo\Model\MetricTimelineData[]|null $data data + * + * @return self + */ + public function setData($data) + { + + if (!is_null($data) && (count($data) > 100)) { + throw new \InvalidArgumentException('invalid value for $data when calling MetricTimeline., number of items must be less than or equal to 100.'); + } + if (!is_null($data) && (count($data) < 0)) { + throw new \InvalidArgumentException('invalid length for $data when calling MetricTimeline., number of items must be greater than or equal to 0.'); + } + $this->container['data'] = $data; + + return $this; + } + + /** + * Gets next + * + * @return string|null + */ + public function getNext() + { + return $this->container['next']; + } + + /** + * Sets next + * + * @param string|null $next next + * + * @return self + */ + public function setNext($next) + { + $this->container['next'] = $next; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/MetricTimelineData.php b/lib/Model/MetricTimelineData.php new file mode 100644 index 0000000..27a04f6 --- /dev/null +++ b/lib/Model/MetricTimelineData.php @@ -0,0 +1,560 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class MetricTimelineData implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'metric_timeline_data'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'id' => 'string', + 'statistic_id' => 'string', + 'timestamp' => 'int', + 'event_name' => 'string', + 'event_properties' => 'array', + 'datetime' => 'string', + 'uuid' => 'string', + 'person' => 'array' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'id' => null, + 'statistic_id' => null, + 'timestamp' => null, + 'event_name' => null, + 'event_properties' => null, + 'datetime' => null, + 'uuid' => null, + 'person' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'id' => 'id', + 'statistic_id' => 'statistic_id', + 'timestamp' => 'timestamp', + 'event_name' => 'event_name', + 'event_properties' => 'event_properties', + 'datetime' => 'datetime', + 'uuid' => 'uuid', + 'person' => 'person' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'id' => 'setId', + 'statistic_id' => 'setStatisticId', + 'timestamp' => 'setTimestamp', + 'event_name' => 'setEventName', + 'event_properties' => 'setEventProperties', + 'datetime' => 'setDatetime', + 'uuid' => 'setUuid', + 'person' => 'setPerson' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'id' => 'getId', + 'statistic_id' => 'getStatisticId', + 'timestamp' => 'getTimestamp', + 'event_name' => 'getEventName', + 'event_properties' => 'getEventProperties', + 'datetime' => 'getDatetime', + 'uuid' => 'getUuid', + 'person' => 'getPerson' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['id'] = $data['id'] ?? null; + $this->container['statistic_id'] = $data['statistic_id'] ?? null; + $this->container['timestamp'] = $data['timestamp'] ?? null; + $this->container['event_name'] = $data['event_name'] ?? null; + $this->container['event_properties'] = $data['event_properties'] ?? null; + $this->container['datetime'] = $data['datetime'] ?? null; + $this->container['uuid'] = $data['uuid'] ?? null; + $this->container['person'] = $data['person'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets id + * + * @return string|null + */ + public function getId() + { + return $this->container['id']; + } + + /** + * Sets id + * + * @param string|null $id id + * + * @return self + */ + public function setId($id) + { + $this->container['id'] = $id; + + return $this; + } + + /** + * Gets statistic_id + * + * @return string|null + */ + public function getStatisticId() + { + return $this->container['statistic_id']; + } + + /** + * Sets statistic_id + * + * @param string|null $statistic_id statistic_id + * + * @return self + */ + public function setStatisticId($statistic_id) + { + $this->container['statistic_id'] = $statistic_id; + + return $this; + } + + /** + * Gets timestamp + * + * @return int|null + */ + public function getTimestamp() + { + return $this->container['timestamp']; + } + + /** + * Sets timestamp + * + * @param int|null $timestamp timestamp + * + * @return self + */ + public function setTimestamp($timestamp) + { + $this->container['timestamp'] = $timestamp; + + return $this; + } + + /** + * Gets event_name + * + * @return string|null + */ + public function getEventName() + { + return $this->container['event_name']; + } + + /** + * Sets event_name + * + * @param string|null $event_name event_name + * + * @return self + */ + public function setEventName($event_name) + { + $this->container['event_name'] = $event_name; + + return $this; + } + + /** + * Gets event_properties + * + * @return array|null + */ + public function getEventProperties() + { + return $this->container['event_properties']; + } + + /** + * Sets event_properties + * + * @param array|null $event_properties event_properties + * + * @return self + */ + public function setEventProperties($event_properties) + { + $this->container['event_properties'] = $event_properties; + + return $this; + } + + /** + * Gets datetime + * + * @return string|null + */ + public function getDatetime() + { + return $this->container['datetime']; + } + + /** + * Sets datetime + * + * @param string|null $datetime datetime + * + * @return self + */ + public function setDatetime($datetime) + { + $this->container['datetime'] = $datetime; + + return $this; + } + + /** + * Gets uuid + * + * @return string|null + */ + public function getUuid() + { + return $this->container['uuid']; + } + + /** + * Sets uuid + * + * @param string|null $uuid uuid + * + * @return self + */ + public function setUuid($uuid) + { + $this->container['uuid'] = $uuid; + + return $this; + } + + /** + * Gets person + * + * @return array|null + */ + public function getPerson() + { + return $this->container['person']; + } + + /** + * Sets person + * + * @param array|null $person person + * + * @return self + */ + public function setPerson($person) + { + $this->container['person'] = $person; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/ModelInterface.php b/lib/Model/ModelInterface.php new file mode 100644 index 0000000..26eb0b9 --- /dev/null +++ b/lib/Model/ModelInterface.php @@ -0,0 +1,95 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class Person implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'person'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'id' => 'string', + 'address1' => 'string', + 'address2' => 'string', + 'city' => 'string', + 'country' => 'string', + 'latitude' => 'string', + 'longitude' => 'string', + 'region' => 'string', + 'zip' => 'string', + 'email' => 'string', + 'title' => 'string', + 'phone_number' => 'string', + 'organization' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'timezone' => 'string', + 'created' => 'string', + 'updated' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'id' => null, + 'address1' => null, + 'address2' => null, + 'city' => null, + 'country' => null, + 'latitude' => null, + 'longitude' => null, + 'region' => null, + 'zip' => null, + 'email' => null, + 'title' => null, + 'phone_number' => null, + 'organization' => null, + 'first_name' => null, + 'last_name' => null, + 'timezone' => null, + 'created' => null, + 'updated' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'id' => 'id', + 'address1' => '$address1', + 'address2' => '$address2', + 'city' => '$city', + 'country' => '$country', + 'latitude' => '$latitude', + 'longitude' => '$longitude', + 'region' => '$region', + 'zip' => '$zip', + 'email' => '$email', + 'title' => '$title', + 'phone_number' => '$phone_number', + 'organization' => '$organization', + 'first_name' => '$first_name', + 'last_name' => '$last_name', + 'timezone' => '$timezone', + 'created' => 'created', + 'updated' => 'updated' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'id' => 'setId', + 'address1' => 'setAddress1', + 'address2' => 'setAddress2', + 'city' => 'setCity', + 'country' => 'setCountry', + 'latitude' => 'setLatitude', + 'longitude' => 'setLongitude', + 'region' => 'setRegion', + 'zip' => 'setZip', + 'email' => 'setEmail', + 'title' => 'setTitle', + 'phone_number' => 'setPhoneNumber', + 'organization' => 'setOrganization', + 'first_name' => 'setFirstName', + 'last_name' => 'setLastName', + 'timezone' => 'setTimezone', + 'created' => 'setCreated', + 'updated' => 'setUpdated' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'id' => 'getId', + 'address1' => 'getAddress1', + 'address2' => 'getAddress2', + 'city' => 'getCity', + 'country' => 'getCountry', + 'latitude' => 'getLatitude', + 'longitude' => 'getLongitude', + 'region' => 'getRegion', + 'zip' => 'getZip', + 'email' => 'getEmail', + 'title' => 'getTitle', + 'phone_number' => 'getPhoneNumber', + 'organization' => 'getOrganization', + 'first_name' => 'getFirstName', + 'last_name' => 'getLastName', + 'timezone' => 'getTimezone', + 'created' => 'getCreated', + 'updated' => 'getUpdated' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['id'] = $data['id'] ?? null; + $this->container['address1'] = $data['address1'] ?? null; + $this->container['address2'] = $data['address2'] ?? null; + $this->container['city'] = $data['city'] ?? null; + $this->container['country'] = $data['country'] ?? null; + $this->container['latitude'] = $data['latitude'] ?? null; + $this->container['longitude'] = $data['longitude'] ?? null; + $this->container['region'] = $data['region'] ?? null; + $this->container['zip'] = $data['zip'] ?? null; + $this->container['email'] = $data['email'] ?? null; + $this->container['title'] = $data['title'] ?? null; + $this->container['phone_number'] = $data['phone_number'] ?? null; + $this->container['organization'] = $data['organization'] ?? null; + $this->container['first_name'] = $data['first_name'] ?? null; + $this->container['last_name'] = $data['last_name'] ?? null; + $this->container['timezone'] = $data['timezone'] ?? null; + $this->container['created'] = $data['created'] ?? null; + $this->container['updated'] = $data['updated'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets id + * + * @return string|null + */ + public function getId() + { + return $this->container['id']; + } + + /** + * Sets id + * + * @param string|null $id id + * + * @return self + */ + public function setId($id) + { + $this->container['id'] = $id; + + return $this; + } + + /** + * Gets address1 + * + * @return string|null + */ + public function getAddress1() + { + return $this->container['address1']; + } + + /** + * Sets address1 + * + * @param string|null $address1 address1 + * + * @return self + */ + public function setAddress1($address1) + { + $this->container['address1'] = $address1; + + return $this; + } + + /** + * Gets address2 + * + * @return string|null + */ + public function getAddress2() + { + return $this->container['address2']; + } + + /** + * Sets address2 + * + * @param string|null $address2 address2 + * + * @return self + */ + public function setAddress2($address2) + { + $this->container['address2'] = $address2; + + return $this; + } + + /** + * Gets city + * + * @return string|null + */ + public function getCity() + { + return $this->container['city']; + } + + /** + * Sets city + * + * @param string|null $city city + * + * @return self + */ + public function setCity($city) + { + $this->container['city'] = $city; + + return $this; + } + + /** + * Gets country + * + * @return string|null + */ + public function getCountry() + { + return $this->container['country']; + } + + /** + * Sets country + * + * @param string|null $country country + * + * @return self + */ + public function setCountry($country) + { + $this->container['country'] = $country; + + return $this; + } + + /** + * Gets latitude + * + * @return string|null + */ + public function getLatitude() + { + return $this->container['latitude']; + } + + /** + * Sets latitude + * + * @param string|null $latitude latitude + * + * @return self + */ + public function setLatitude($latitude) + { + $this->container['latitude'] = $latitude; + + return $this; + } + + /** + * Gets longitude + * + * @return string|null + */ + public function getLongitude() + { + return $this->container['longitude']; + } + + /** + * Sets longitude + * + * @param string|null $longitude longitude + * + * @return self + */ + public function setLongitude($longitude) + { + $this->container['longitude'] = $longitude; + + return $this; + } + + /** + * Gets region + * + * @return string|null + */ + public function getRegion() + { + return $this->container['region']; + } + + /** + * Sets region + * + * @param string|null $region region + * + * @return self + */ + public function setRegion($region) + { + $this->container['region'] = $region; + + return $this; + } + + /** + * Gets zip + * + * @return string|null + */ + public function getZip() + { + return $this->container['zip']; + } + + /** + * Sets zip + * + * @param string|null $zip zip + * + * @return self + */ + public function setZip($zip) + { + $this->container['zip'] = $zip; + + return $this; + } + + /** + * Gets email + * + * @return string|null + */ + public function getEmail() + { + return $this->container['email']; + } + + /** + * Sets email + * + * @param string|null $email email + * + * @return self + */ + public function setEmail($email) + { + $this->container['email'] = $email; + + return $this; + } + + /** + * Gets title + * + * @return string|null + */ + public function getTitle() + { + return $this->container['title']; + } + + /** + * Sets title + * + * @param string|null $title title + * + * @return self + */ + public function setTitle($title) + { + $this->container['title'] = $title; + + return $this; + } + + /** + * Gets phone_number + * + * @return string|null + */ + public function getPhoneNumber() + { + return $this->container['phone_number']; + } + + /** + * Sets phone_number + * + * @param string|null $phone_number phone_number + * + * @return self + */ + public function setPhoneNumber($phone_number) + { + $this->container['phone_number'] = $phone_number; + + return $this; + } + + /** + * Gets organization + * + * @return string|null + */ + public function getOrganization() + { + return $this->container['organization']; + } + + /** + * Sets organization + * + * @param string|null $organization organization + * + * @return self + */ + public function setOrganization($organization) + { + $this->container['organization'] = $organization; + + return $this; + } + + /** + * Gets first_name + * + * @return string|null + */ + public function getFirstName() + { + return $this->container['first_name']; + } + + /** + * Sets first_name + * + * @param string|null $first_name first_name + * + * @return self + */ + public function setFirstName($first_name) + { + $this->container['first_name'] = $first_name; + + return $this; + } + + /** + * Gets last_name + * + * @return string|null + */ + public function getLastName() + { + return $this->container['last_name']; + } + + /** + * Sets last_name + * + * @param string|null $last_name last_name + * + * @return self + */ + public function setLastName($last_name) + { + $this->container['last_name'] = $last_name; + + return $this; + } + + /** + * Gets timezone + * + * @return string|null + */ + public function getTimezone() + { + return $this->container['timezone']; + } + + /** + * Sets timezone + * + * @param string|null $timezone timezone + * + * @return self + */ + public function setTimezone($timezone) + { + $this->container['timezone'] = $timezone; + + return $this; + } + + /** + * Gets created + * + * @return string|null + */ + public function getCreated() + { + return $this->container['created']; + } + + /** + * Sets created + * + * @param string|null $created created + * + * @return self + */ + public function setCreated($created) + { + $this->container['created'] = $created; + + return $this; + } + + /** + * Gets updated + * + * @return string|null + */ + public function getUpdated() + { + return $this->container['updated']; + } + + /** + * Sets updated + * + * @param string|null $updated updated + * + * @return self + */ + public function setUpdated($updated) + { + $this->container['updated'] = $updated; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/PrivacyEmail.php b/lib/Model/PrivacyEmail.php new file mode 100644 index 0000000..3ffcd14 --- /dev/null +++ b/lib/Model/PrivacyEmail.php @@ -0,0 +1,320 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class PrivacyEmail implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'privacy_email'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'email' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'email' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'email' => 'email' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'email' => 'setEmail' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'email' => 'getEmail' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['email'] = $data['email'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets email + * + * @return string|null + */ + public function getEmail() + { + return $this->container['email']; + } + + /** + * Sets email + * + * @param string|null $email email + * + * @return self + */ + public function setEmail($email) + { + $this->container['email'] = $email; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/PrivacyId.php b/lib/Model/PrivacyId.php new file mode 100644 index 0000000..697290c --- /dev/null +++ b/lib/Model/PrivacyId.php @@ -0,0 +1,320 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class PrivacyId implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'privacy_id'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'person_id' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'person_id' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'person_id' => 'person_id' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'person_id' => 'setPersonId' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'person_id' => 'getPersonId' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['person_id'] = $data['person_id'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets person_id + * + * @return string|null + */ + public function getPersonId() + { + return $this->container['person_id']; + } + + /** + * Sets person_id + * + * @param string|null $person_id person_id + * + * @return self + */ + public function setPersonId($person_id) + { + $this->container['person_id'] = $person_id; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/PrivacyPhone.php b/lib/Model/PrivacyPhone.php new file mode 100644 index 0000000..14eb15c --- /dev/null +++ b/lib/Model/PrivacyPhone.php @@ -0,0 +1,320 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class PrivacyPhone implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'privacy_phone'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'phone_number' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'phone_number' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'phone_number' => 'phone_number' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'phone_number' => 'setPhoneNumber' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'phone_number' => 'getPhoneNumber' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['phone_number'] = $data['phone_number'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets phone_number + * + * @return string|null + */ + public function getPhoneNumber() + { + return $this->container['phone_number']; + } + + /** + * Sets phone_number + * + * @param string|null $phone_number phone_number + * + * @return self + */ + public function setPhoneNumber($phone_number) + { + $this->container['phone_number'] = $phone_number; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/RenderedTemplate.php b/lib/Model/RenderedTemplate.php new file mode 100644 index 0000000..64e6e8d --- /dev/null +++ b/lib/Model/RenderedTemplate.php @@ -0,0 +1,410 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class RenderedTemplate implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'rendered-template'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'id' => 'string', + 'name' => 'string', + 'data' => 'array' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'id' => null, + 'name' => null, + 'data' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'id' => 'id', + 'name' => 'name', + 'data' => 'data' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'id' => 'setId', + 'name' => 'setName', + 'data' => 'setData' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'id' => 'getId', + 'name' => 'getName', + 'data' => 'getData' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['id'] = $data['id'] ?? null; + $this->container['name'] = $data['name'] ?? null; + $this->container['data'] = $data['data'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets id + * + * @return string|null + */ + public function getId() + { + return $this->container['id']; + } + + /** + * Sets id + * + * @param string|null $id id + * + * @return self + */ + public function setId($id) + { + $this->container['id'] = $id; + + return $this; + } + + /** + * Gets name + * + * @return string|null + */ + public function getName() + { + return $this->container['name']; + } + + /** + * Sets name + * + * @param string|null $name name + * + * @return self + */ + public function setName($name) + { + $this->container['name'] = $name; + + return $this; + } + + /** + * Gets data + * + * @return array|null + */ + public function getData() + { + return $this->container['data']; + } + + /** + * Sets data + * + * @param array|null $data data + * + * @return self + */ + public function setData($data) + { + $this->container['data'] = $data; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/Template.php b/lib/Model/Template.php new file mode 100644 index 0000000..0b0bcef --- /dev/null +++ b/lib/Model/Template.php @@ -0,0 +1,500 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class Template implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'template'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'object' => 'string', + 'id' => 'string', + 'name' => 'string', + 'html' => 'string', + 'is_writeable' => 'bool', + 'created' => 'string', + 'updated' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'object' => null, + 'id' => null, + 'name' => null, + 'html' => null, + 'is_writeable' => null, + 'created' => null, + 'updated' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'object' => 'object', + 'id' => 'id', + 'name' => 'name', + 'html' => 'html', + 'is_writeable' => 'is_writeable', + 'created' => 'created', + 'updated' => 'updated' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'object' => 'setObject', + 'id' => 'setId', + 'name' => 'setName', + 'html' => 'setHtml', + 'is_writeable' => 'setIsWriteable', + 'created' => 'setCreated', + 'updated' => 'setUpdated' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'object' => 'getObject', + 'id' => 'getId', + 'name' => 'getName', + 'html' => 'getHtml', + 'is_writeable' => 'getIsWriteable', + 'created' => 'getCreated', + 'updated' => 'getUpdated' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['object'] = $data['object'] ?? null; + $this->container['id'] = $data['id'] ?? null; + $this->container['name'] = $data['name'] ?? null; + $this->container['html'] = $data['html'] ?? null; + $this->container['is_writeable'] = $data['is_writeable'] ?? null; + $this->container['created'] = $data['created'] ?? null; + $this->container['updated'] = $data['updated'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets object + * + * @return string|null + */ + public function getObject() + { + return $this->container['object']; + } + + /** + * Sets object + * + * @param string|null $object object + * + * @return self + */ + public function setObject($object) + { + $this->container['object'] = $object; + + return $this; + } + + /** + * Gets id + * + * @return string|null + */ + public function getId() + { + return $this->container['id']; + } + + /** + * Sets id + * + * @param string|null $id id + * + * @return self + */ + public function setId($id) + { + $this->container['id'] = $id; + + return $this; + } + + /** + * Gets name + * + * @return string|null + */ + public function getName() + { + return $this->container['name']; + } + + /** + * Sets name + * + * @param string|null $name name + * + * @return self + */ + public function setName($name) + { + $this->container['name'] = $name; + + return $this; + } + + /** + * Gets html + * + * @return string|null + */ + public function getHtml() + { + return $this->container['html']; + } + + /** + * Sets html + * + * @param string|null $html html + * + * @return self + */ + public function setHtml($html) + { + $this->container['html'] = $html; + + return $this; + } + + /** + * Gets is_writeable + * + * @return bool|null + */ + public function getIsWriteable() + { + return $this->container['is_writeable']; + } + + /** + * Sets is_writeable + * + * @param bool|null $is_writeable is_writeable + * + * @return self + */ + public function setIsWriteable($is_writeable) + { + $this->container['is_writeable'] = $is_writeable; + + return $this; + } + + /** + * Gets created + * + * @return string|null + */ + public function getCreated() + { + return $this->container['created']; + } + + /** + * Sets created + * + * @param string|null $created created + * + * @return self + */ + public function setCreated($created) + { + $this->container['created'] = $created; + + return $this; + } + + /** + * Gets updated + * + * @return string|null + */ + public function getUpdated() + { + return $this->container['updated']; + } + + /** + * Sets updated + * + * @param string|null $updated updated + * + * @return self + */ + public function setUpdated($updated) + { + $this->container['updated'] = $updated; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/TrackPayload.php b/lib/Model/TrackPayload.php new file mode 100644 index 0000000..25026fb --- /dev/null +++ b/lib/Model/TrackPayload.php @@ -0,0 +1,419 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class TrackPayload implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'track_payload'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'token' => 'string', + 'customer_properties' => '\Klaviyo\Model\TrackPayloadCustomerProperties', + 'properties' => '\Klaviyo\Model\TrackPayloadProperties', + 'time' => 'OneOfStringInteger' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'token' => null, + 'customer_properties' => null, + 'properties' => null, + 'time' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'token' => 'token', + 'customer_properties' => 'customer_properties', + 'properties' => 'properties', + 'time' => 'time' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'token' => 'setToken', + 'customer_properties' => 'setCustomerProperties', + 'properties' => 'setProperties', + 'time' => 'setTime' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'token' => 'getToken', + 'customer_properties' => 'getCustomerProperties', + 'properties' => 'getProperties', + 'time' => 'getTime' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['token'] = $data['token'] ?? null; + $this->container['customer_properties'] = $data['customer_properties'] ?? null; + $this->container['properties'] = $data['properties'] ?? null; + $this->container['time'] = $data['time'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + if ($this->container['token'] === null) { + $invalidProperties[] = "'token' can't be null"; + } + if ($this->container['customer_properties'] === null) { + $invalidProperties[] = "'customer_properties' can't be null"; + } + if ($this->container['properties'] === null) { + $invalidProperties[] = "'properties' can't be null"; + } + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets token + * + * @return string + */ + public function getToken() + { + return $this->container['token']; + } + + /** + * Sets token + * + * @param string $token token + * + * @return self + */ + public function setToken($token) + { + $this->container['token'] = $token; + + return $this; + } + + /** + * Gets customer_properties + * + * @return \Klaviyo\Model\TrackPayloadCustomerProperties + */ + public function getCustomerProperties() + { + return $this->container['customer_properties']; + } + + /** + * Sets customer_properties + * + * @param \Klaviyo\Model\TrackPayloadCustomerProperties $customer_properties customer_properties + * + * @return self + */ + public function setCustomerProperties($customer_properties) + { + $this->container['customer_properties'] = $customer_properties; + + return $this; + } + + /** + * Gets properties + * + * @return \Klaviyo\Model\TrackPayloadProperties + */ + public function getProperties() + { + return $this->container['properties']; + } + + /** + * Sets properties + * + * @param \Klaviyo\Model\TrackPayloadProperties $properties properties + * + * @return self + */ + public function setProperties($properties) + { + $this->container['properties'] = $properties; + + return $this; + } + + /** + * Gets time + * + * @return OneOfStringInteger|null + */ + public function getTime() + { + return $this->container['time']; + } + + /** + * Sets time + * + * @param OneOfStringInteger|null $time time + * + * @return self + */ + public function setTime($time) + { + $this->container['time'] = $time; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/TrackPayloadCustomerProperties.php b/lib/Model/TrackPayloadCustomerProperties.php new file mode 100644 index 0000000..42f5f38 --- /dev/null +++ b/lib/Model/TrackPayloadCustomerProperties.php @@ -0,0 +1,350 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class TrackPayloadCustomerProperties implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'track_payload_customer_properties'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'email' => 'string', + 'phone_number' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'email' => null, + 'phone_number' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'email' => '$email', + 'phone_number' => '$phone_number' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'email' => 'setEmail', + 'phone_number' => 'setPhoneNumber' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'email' => 'getEmail', + 'phone_number' => 'getPhoneNumber' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['email'] = $data['email'] ?? null; + $this->container['phone_number'] = $data['phone_number'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets email + * + * @return string|null + */ + public function getEmail() + { + return $this->container['email']; + } + + /** + * Sets email + * + * @param string|null $email email + * + * @return self + */ + public function setEmail($email) + { + $this->container['email'] = $email; + + return $this; + } + + /** + * Gets phone_number + * + * @return string|null + */ + public function getPhoneNumber() + { + return $this->container['phone_number']; + } + + /** + * Sets phone_number + * + * @param string|null $phone_number phone_number + * + * @return self + */ + public function setPhoneNumber($phone_number) + { + $this->container['phone_number'] = $phone_number; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/Model/TrackPayloadProperties.php b/lib/Model/TrackPayloadProperties.php new file mode 100644 index 0000000..0db0ba7 --- /dev/null +++ b/lib/Model/TrackPayloadProperties.php @@ -0,0 +1,380 @@ + + * @template TKey int|null + * @template TValue mixed|null + */ +class TrackPayloadProperties implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'track_payload_properties'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'event_id' => 'string', + 'value' => 'string', + 'your_custom_field' => 'OneOfStringIntegerNumberBooleanArray' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'event_id' => null, + 'value' => null, + 'your_custom_field' => null + ]; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'event_id' => '$event_id', + 'value' => '$value', + 'your_custom_field' => 'YOUR_CUSTOM_FIELD' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'event_id' => 'setEventId', + 'value' => 'setValue', + 'your_custom_field' => 'setYourCustomField' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'event_id' => 'getEventId', + 'value' => 'getValue', + 'your_custom_field' => 'getYourCustomField' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * 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['event_id'] = $data['event_id'] ?? null; + $this->container['value'] = $data['value'] ?? null; + $this->container['your_custom_field'] = $data['your_custom_field'] ?? null; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets event_id + * + * @return string|null + */ + public function getEventId() + { + return $this->container['event_id']; + } + + /** + * Sets event_id + * + * @param string|null $event_id event_id + * + * @return self + */ + public function setEventId($event_id) + { + $this->container['event_id'] = $event_id; + + return $this; + } + + /** + * Gets value + * + * @return string|null + */ + public function getValue() + { + return $this->container['value']; + } + + /** + * Sets value + * + * @param string|null $value value + * + * @return self + */ + public function setValue($value) + { + $this->container['value'] = $value; + + return $this; + } + + /** + * Gets your_custom_field + * + * @return OneOfStringIntegerNumberBooleanArray|null + */ + public function getYourCustomField() + { + return $this->container['your_custom_field']; + } + + /** + * Sets your_custom_field + * + * @param OneOfStringIntegerNumberBooleanArray|null $your_custom_field your_custom_field + * + * @return self + */ + public function setYourCustomField($your_custom_field) + { + $this->container['your_custom_field'] = $your_custom_field; + + 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|null + */ + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $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]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue() + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/lib/ObjectSerializer.php b/lib/ObjectSerializer.php new file mode 100644 index 0000000..92a61a7 --- /dev/null +++ b/lib/ObjectSerializer.php @@ -0,0 +1,415 @@ +format('Y-m-d') : $data->format(self::$dateTimeFormat); + } + + if (is_array($data)) { + foreach ($data as $property => $value) { + $data[$property] = self::sanitizeForSerialization($value); + } + return $data; + } + + if (is_object($data)) { + $values = []; + if ($data instanceof ModelInterface) { + $formats = $data::openAPIFormats(); + foreach ($data::openAPITypes() as $property => $openAPIType) { + $getter = $data::getters()[$property]; + $value = $data->$getter(); + if ($value !== null && !in_array($openAPIType, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + $callable = [$openAPIType, 'getAllowableEnumValues']; + if (is_callable($callable)) { + /** array $callable */ + $allowedEnumTypes = $callable(); + if (!in_array($value, $allowedEnumTypes, true)) { + $imploded = implode("', '", $allowedEnumTypes); + throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + } + } + } + if ($value !== null) { + $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + } + } + } else { + foreach($data as $property => $value) { + $values[$property] = self::sanitizeForSerialization($value); + } + } + return (object)$values; + } else { + return (string)$data; + } + } + + /** + * Sanitize filename by removing path. + * e.g. ../../sun.gif becomes sun.gif + * + * @param string $filename filename to be sanitized + * + * @return string the sanitized filename + */ + public static function sanitizeFilename($filename) + { + if (preg_match("/.*[\/\\\\](.*)$/", $filename, $match)) { + return $match[1]; + } else { + return $filename; + } + } + + /** + * Shorter timestamp microseconds to 6 digits length. + * + * @param string $timestamp Original timestamp + * + * @return string the shorten timestamp + */ + public static function sanitizeTimestamp($timestamp) + { + if (!is_string($timestamp)) return $timestamp; + + return preg_replace('/(:\d{2}.\d{6})\d*/', '$1', $timestamp); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the path, by url-encoding. + * + * @param string $value a string which will be part of the path + * + * @return string the serialized object + */ + public static function toPathValue($value) + { + return rawurlencode(self::toString($value)); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the query, by imploding comma-separated if it's an object. + * If it's a string, pass through unchanged. It will be url-encoded + * later. + * + * @param string[]|string|\DateTime $object an object to be serialized to a string + * + * @return string the serialized object + */ + public static function toQueryValue($object) + { + if (is_array($object)) { + return implode(',', $object); + } else { + return self::toString($object); + } + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the header. If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * + * @param string $value a string which will be part of the header + * + * @return string the header string + */ + public static function toHeaderValue($value) + { + $callable = [$value, 'toHeaderValue']; + if (is_callable($callable)) { + return $callable(); + } + + return self::toString($value); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the http body (form parameter). If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * + * @param string|\SplFileObject $value the value of the form parameter + * + * @return string the form string + */ + public static function toFormValue($value) + { + if ($value instanceof \SplFileObject) { + return $value->getRealPath(); + } else { + return self::toString($value); + } + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the parameter. If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * If it's a boolean, convert it to "true" or "false". + * + * @param string|bool|\DateTime $value the value of the parameter + * + * @return string the header string + */ + public static function toString($value) + { + if ($value instanceof \DateTime) { // datetime in ISO8601 format + return $value->format(self::$dateTimeFormat); + } elseif (is_bool($value)) { + return $value ? 'true' : 'false'; + } else { + return $value; + } + } + + /** + * Serialize an array to a string. + * + * @param array $collection collection to serialize to a string + * @param string $style the format use for serialization (csv, + * ssv, tsv, pipes, multi) + * @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array + * + * @return string + */ + public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false) + { + if ($allowCollectionFormatMulti && ('multi' === $style)) { + // http_build_query() almost does the job for us. We just + // need to fix the result of multidimensional arrays. + return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&')); + } + switch ($style) { + case 'pipeDelimited': + case 'pipes': + return implode('|', $collection); + + case 'tsv': + return implode("\t", $collection); + + case 'spaceDelimited': + case 'ssv': + return implode(' ', $collection); + + case 'simple': + case 'csv': + // Deliberate fall through. CSV is default format. + default: + return implode(',', $collection); + } + } + + /** + * Deserialize a JSON string into an object + * + * @param mixed $data object or primitive to be deserialized + * @param string $class class name is passed as a string + * @param string[] $httpHeaders HTTP headers + * @param string $discriminator discriminator if polymorphism is used + * + * @return object|array|null a single or an array of $class instances + */ + public static function deserialize($data, $class, $httpHeaders = null) + { + if (null === $data) { + return null; + } + + if (strcasecmp(substr($class, -2), '[]') === 0) { + $data = is_string($data) ? json_decode($data) : $data; + + if (!is_array($data)) { + throw new \InvalidArgumentException("Invalid array '$class'"); + } + + $subClass = substr($class, 0, -2); + $values = []; + foreach ($data as $key => $value) { + $values[] = self::deserialize($value, $subClass, null); + } + return $values; + } + + if (preg_match('/^(array<|map\[)/', $class)) { // for associative array e.g. array + $data = is_string($data) ? json_decode($data) : $data; + settype($data, 'array'); + $inner = substr($class, 4, -1); + $deserialized = []; + if (strrpos($inner, ",") !== false) { + $subClass_array = explode(',', $inner, 2); + $subClass = $subClass_array[1]; + foreach ($data as $key => $value) { + $deserialized[$key] = self::deserialize($value, $subClass, null); + } + } + return $deserialized; + } + + if ($class === 'object') { + settype($data, 'array'); + return $data; + } else if ($class === 'mixed') { + settype($data, gettype($data)); + return $data; + } + + if ($class === '\DateTime') { + // Some API's return an invalid, empty string as a + // date-time property. DateTime::__construct() will return + // the current time for empty input which is probably not + // what is meant. The invalid empty string is probably to + // be interpreted as a missing field/value. Let's handle + // this graceful. + if (!empty($data)) { + try { + return new \DateTime($data); + } catch (\Exception $exception) { + // Some API's return a date-time with too high nanosecond + // precision for php's DateTime to handle. + // With provided regexp 6 digits of microseconds saved + return new \DateTime(self::sanitizeTimestamp($data)); + } + } else { + return null; + } + } + + if ($class === '\SplFileObject') { + $data = Utils::streamFor($data); + + /** @var \Psr\Http\Message\StreamInterface $data */ + + // determine file name + if ( + is_array($httpHeaders) + && array_key_exists('Content-Disposition', $httpHeaders) + && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match) + ) { + $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]); + } else { + $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); + } + + $file = fopen($filename, 'w'); + while ($chunk = $data->read(200)) { + fwrite($file, $chunk); + } + fclose($file); + + return new \SplFileObject($filename, 'r'); + } + + /** @psalm-suppress ParadoxicalCondition */ + if (in_array($class, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + settype($data, $class); + return $data; + } + + + if (method_exists($class, 'getAllowableEnumValues')) { + if (!in_array($data, $class::getAllowableEnumValues(), true)) { + $imploded = implode("', '", $class::getAllowableEnumValues()); + throw new \InvalidArgumentException("Invalid value for enum '$class', must be one of: '$imploded'"); + } + return $data; + } else { + $data = is_string($data) ? json_decode($data) : $data; + // If a discriminator is defined and points to a valid subclass, use it. + $discriminator = $class::DISCRIMINATOR; + if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { + $subclass = '\Klaviyo\Model\\' . $data->{$discriminator}; + if (is_subclass_of($subclass, $class)) { + $class = $subclass; + } + } + + /** @var ModelInterface $instance */ + $instance = new $class(); + foreach ($instance::openAPITypes() as $property => $type) { + $propertySetter = $instance::setters()[$property]; + + if (!isset($propertySetter) || !isset($data->{$instance::attributeMap()[$property]})) { + continue; + } + + if (isset($data->{$instance::attributeMap()[$property]})) { + $propertyValue = $data->{$instance::attributeMap()[$property]}; + $instance->$propertySetter(self::deserialize($propertyValue, $type, null)); + } + } + return $instance; + } + } +} diff --git a/lib/Subclient.php b/lib/Subclient.php new file mode 100644 index 0000000..6bd3c94 --- /dev/null +++ b/lib/Subclient.php @@ -0,0 +1,74 @@ +api_instance = $api_instance; + $this->wait_seconds = $wait_seconds; + $this->num_retries = $num_retries; + $this->retry_codes = $retry_codes; + $this->json_string_function_names = ['trackPost','identifyPost']; + $this->base64_function_names = ['trackGet','identifyGet']; + } + + public function __call($name, $args) { + + # to json string + if (gettype(array_search($name,$this->json_string_function_names,$strict=True)) == "integer") { + + if (gettype($args[0]) == "array") { + $args[0] = json_encode($args[0]); + } + } + + # to base64 + if (gettype(array_search($name,$this->base64_function_names,$strict=True)) == "integer") { + + if (gettype($args[0]) == "string") { + + json_decode($args[0], TRUE); + + if (json_last_error() == JSON_ERROR_NONE) { + $args[0] = base64_encode($args[0]); + } + } else { + $args[0] = base64_encode(json_encode($args[0])); + } + } + + + $attempts = 0; + + do { + + try { + $result = $this->api_instance->$name(...$args); + return $result; + } catch (Exception $e) { + + if ( ! in_array($e->getCode(),$this->retry_codes)) { + throw $e; + } + else { + echo "\nretrying...\n"; + $attempts++; + sleep($this->wait_seconds); + continue; + + } + } + + break; + + } while($attempts < ($this->num_retries)); + + throw $e; + } + +} \ No newline at end of file