2658 lines
99 KiB
PHP
2658 lines
99 KiB
PHP
<?php
|
|
/**
|
|
* WhatsAppCampaignsApi
|
|
* PHP version 5
|
|
*
|
|
* @category Class
|
|
* @package Brevo\Client
|
|
* @author Swagger Codegen team
|
|
* @link https://github.com/swagger-api/swagger-codegen
|
|
*/
|
|
|
|
/**
|
|
* Brevo API
|
|
*
|
|
* Brevo provide a RESTFul API that can be used with any languages. With this API, you will be able to : - Manage your campaigns and get the statistics - Manage your contacts - Send transactional Emails and SMS - and much more... You can download our wrappers at https://github.com/orgs/brevo **Possible responses** | Code | Message | | :-------------: | ------------- | | 200 | OK. Successful Request | | 201 | OK. Successful Creation | | 202 | OK. Request accepted | | 204 | OK. Successful Update/Deletion | | 400 | Error. Bad Request | | 401 | Error. Authentication Needed | | 402 | Error. Not enough credit, plan upgrade needed | | 403 | Error. Permission denied | | 404 | Error. Object does not exist | | 405 | Error. Method not allowed | | 406 | Error. Not Acceptable |
|
|
*
|
|
* OpenAPI spec version: 3.0.0
|
|
* Contact: contact@brevo.com
|
|
* Generated by: https://github.com/swagger-api/swagger-codegen.git
|
|
* Swagger Codegen version: 2.4.29
|
|
*/
|
|
|
|
/**
|
|
* NOTE: This class is auto generated by the swagger code generator program.
|
|
* https://github.com/swagger-api/swagger-codegen
|
|
* Do not edit the class manually.
|
|
*/
|
|
|
|
namespace Brevo\Client\Api;
|
|
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\ClientInterface;
|
|
use GuzzleHttp\Exception\RequestException;
|
|
use GuzzleHttp\Psr7\MultipartStream;
|
|
use GuzzleHttp\Psr7\Request;
|
|
use GuzzleHttp\RequestOptions;
|
|
use Brevo\Client\ApiException;
|
|
use Brevo\Client\Configuration;
|
|
use Brevo\Client\HeaderSelector;
|
|
use Brevo\Client\ObjectSerializer;
|
|
|
|
/**
|
|
* WhatsAppCampaignsApi Class Doc Comment
|
|
*
|
|
* @category Class
|
|
* @package Brevo\Client
|
|
* @author Swagger Codegen team
|
|
* @link https://github.com/swagger-api/swagger-codegen
|
|
*/
|
|
class WhatsAppCampaignsApi
|
|
{
|
|
/**
|
|
* @var ClientInterface
|
|
*/
|
|
protected $client;
|
|
|
|
/**
|
|
* @var Configuration
|
|
*/
|
|
protected $config;
|
|
|
|
/**
|
|
* @var HeaderSelector
|
|
*/
|
|
protected $headerSelector;
|
|
|
|
/**
|
|
* @param ClientInterface $client
|
|
* @param Configuration $config
|
|
* @param HeaderSelector $selector
|
|
*/
|
|
public function __construct(
|
|
ClientInterface $client = null,
|
|
Configuration $config = null,
|
|
HeaderSelector $selector = null
|
|
) {
|
|
$this->client = $client ?: new Client();
|
|
$this->config = $config ?: new Configuration();
|
|
$this->headerSelector = $selector ?: new HeaderSelector();
|
|
}
|
|
|
|
/**
|
|
* @return Configuration
|
|
*/
|
|
public function getConfig()
|
|
{
|
|
return $this->config;
|
|
}
|
|
|
|
/**
|
|
* Operation createWhatsAppCampaign
|
|
*
|
|
* Create and Send a WhatsApp campaign
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppCampaign $whatsAppCampaigns Values to create a campaign (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return \Brevo\Client\Model\CreateModel
|
|
*/
|
|
public function createWhatsAppCampaign($whatsAppCampaigns)
|
|
{
|
|
list($response) = $this->createWhatsAppCampaignWithHttpInfo($whatsAppCampaigns);
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Operation createWhatsAppCampaignWithHttpInfo
|
|
*
|
|
* Create and Send a WhatsApp campaign
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppCampaign $whatsAppCampaigns Values to create a campaign (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of \Brevo\Client\Model\CreateModel, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function createWhatsAppCampaignWithHttpInfo($whatsAppCampaigns)
|
|
{
|
|
$returnType = '\Brevo\Client\Model\CreateModel';
|
|
$request = $this->createWhatsAppCampaignRequest($whatsAppCampaigns);
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 201:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\CreateModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation createWhatsAppCampaignAsync
|
|
*
|
|
* Create and Send a WhatsApp campaign
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppCampaign $whatsAppCampaigns Values to create a campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function createWhatsAppCampaignAsync($whatsAppCampaigns)
|
|
{
|
|
return $this->createWhatsAppCampaignAsyncWithHttpInfo($whatsAppCampaigns)
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation createWhatsAppCampaignAsyncWithHttpInfo
|
|
*
|
|
* Create and Send a WhatsApp campaign
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppCampaign $whatsAppCampaigns Values to create a campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function createWhatsAppCampaignAsyncWithHttpInfo($whatsAppCampaigns)
|
|
{
|
|
$returnType = '\Brevo\Client\Model\CreateModel';
|
|
$request = $this->createWhatsAppCampaignRequest($whatsAppCampaigns);
|
|
|
|
return $this->client
|
|
->sendAsync($request, $this->createHttpClientOption())
|
|
->then(
|
|
function ($response) use ($returnType) {
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
},
|
|
function ($exception) {
|
|
$response = $exception->getResponse();
|
|
$statusCode = $response->getStatusCode();
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$exception->getRequest()->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'createWhatsAppCampaign'
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppCampaign $whatsAppCampaigns Values to create a campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function createWhatsAppCampaignRequest($whatsAppCampaigns)
|
|
{
|
|
// verify the required parameter 'whatsAppCampaigns' is set
|
|
if ($whatsAppCampaigns === null || (is_array($whatsAppCampaigns) && count($whatsAppCampaigns) === 0)) {
|
|
throw new \InvalidArgumentException(
|
|
'Missing the required parameter $whatsAppCampaigns when calling createWhatsAppCampaign'
|
|
);
|
|
}
|
|
|
|
$resourcePath = '/whatsappCampaigns';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
if (isset($whatsAppCampaigns)) {
|
|
$_tempBody = $whatsAppCampaigns;
|
|
}
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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 createWhatsAppTemplate
|
|
*
|
|
* Create a WhatsApp template
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppTemplate $whatsAppTemplates Values to create a template (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return \Brevo\Client\Model\CreateModel
|
|
*/
|
|
public function createWhatsAppTemplate($whatsAppTemplates)
|
|
{
|
|
list($response) = $this->createWhatsAppTemplateWithHttpInfo($whatsAppTemplates);
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Operation createWhatsAppTemplateWithHttpInfo
|
|
*
|
|
* Create a WhatsApp template
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppTemplate $whatsAppTemplates Values to create a template (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of \Brevo\Client\Model\CreateModel, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function createWhatsAppTemplateWithHttpInfo($whatsAppTemplates)
|
|
{
|
|
$returnType = '\Brevo\Client\Model\CreateModel';
|
|
$request = $this->createWhatsAppTemplateRequest($whatsAppTemplates);
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 201:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\CreateModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation createWhatsAppTemplateAsync
|
|
*
|
|
* Create a WhatsApp template
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppTemplate $whatsAppTemplates Values to create a template (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function createWhatsAppTemplateAsync($whatsAppTemplates)
|
|
{
|
|
return $this->createWhatsAppTemplateAsyncWithHttpInfo($whatsAppTemplates)
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation createWhatsAppTemplateAsyncWithHttpInfo
|
|
*
|
|
* Create a WhatsApp template
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppTemplate $whatsAppTemplates Values to create a template (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function createWhatsAppTemplateAsyncWithHttpInfo($whatsAppTemplates)
|
|
{
|
|
$returnType = '\Brevo\Client\Model\CreateModel';
|
|
$request = $this->createWhatsAppTemplateRequest($whatsAppTemplates);
|
|
|
|
return $this->client
|
|
->sendAsync($request, $this->createHttpClientOption())
|
|
->then(
|
|
function ($response) use ($returnType) {
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
},
|
|
function ($exception) {
|
|
$response = $exception->getResponse();
|
|
$statusCode = $response->getStatusCode();
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$exception->getRequest()->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'createWhatsAppTemplate'
|
|
*
|
|
* @param \Brevo\Client\Model\CreateWhatsAppTemplate $whatsAppTemplates Values to create a template (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function createWhatsAppTemplateRequest($whatsAppTemplates)
|
|
{
|
|
// verify the required parameter 'whatsAppTemplates' is set
|
|
if ($whatsAppTemplates === null || (is_array($whatsAppTemplates) && count($whatsAppTemplates) === 0)) {
|
|
throw new \InvalidArgumentException(
|
|
'Missing the required parameter $whatsAppTemplates when calling createWhatsAppTemplate'
|
|
);
|
|
}
|
|
|
|
$resourcePath = '/whatsppCampaigns/template';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
if (isset($whatsAppTemplates)) {
|
|
$_tempBody = $whatsAppTemplates;
|
|
}
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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 deleteWhatsAppCampaign
|
|
*
|
|
* Delete a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId id of the campaign (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return void
|
|
*/
|
|
public function deleteWhatsAppCampaign($campaignId)
|
|
{
|
|
$this->deleteWhatsAppCampaignWithHttpInfo($campaignId);
|
|
}
|
|
|
|
/**
|
|
* Operation deleteWhatsAppCampaignWithHttpInfo
|
|
*
|
|
* Delete a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId id of the campaign (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of null, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function deleteWhatsAppCampaignWithHttpInfo($campaignId)
|
|
{
|
|
$returnType = '';
|
|
$request = $this->deleteWhatsAppCampaignRequest($campaignId);
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
return [null, $statusCode, $response->getHeaders()];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 404:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation deleteWhatsAppCampaignAsync
|
|
*
|
|
* Delete a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function deleteWhatsAppCampaignAsync($campaignId)
|
|
{
|
|
return $this->deleteWhatsAppCampaignAsyncWithHttpInfo($campaignId)
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation deleteWhatsAppCampaignAsyncWithHttpInfo
|
|
*
|
|
* Delete a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function deleteWhatsAppCampaignAsyncWithHttpInfo($campaignId)
|
|
{
|
|
$returnType = '';
|
|
$request = $this->deleteWhatsAppCampaignRequest($campaignId);
|
|
|
|
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(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'deleteWhatsAppCampaign'
|
|
*
|
|
* @param int $campaignId id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function deleteWhatsAppCampaignRequest($campaignId)
|
|
{
|
|
// verify the required parameter 'campaignId' is set
|
|
if ($campaignId === null || (is_array($campaignId) && count($campaignId) === 0)) {
|
|
throw new \InvalidArgumentException(
|
|
'Missing the required parameter $campaignId when calling deleteWhatsAppCampaign'
|
|
);
|
|
}
|
|
|
|
$resourcePath = '/whatsappCampaigns/{campaignId}';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
|
|
// path params
|
|
if ($campaignId !== null) {
|
|
$resourcePath = str_replace(
|
|
'{' . 'campaignId' . '}',
|
|
ObjectSerializer::toPathValue($campaignId),
|
|
$resourcePath
|
|
);
|
|
}
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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 getWhatsAppCampaign
|
|
*
|
|
* Get a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return \Brevo\Client\Model\GetWhatsappCampaignOverview
|
|
*/
|
|
public function getWhatsAppCampaign($campaignId)
|
|
{
|
|
list($response) = $this->getWhatsAppCampaignWithHttpInfo($campaignId);
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppCampaignWithHttpInfo
|
|
*
|
|
* Get a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of \Brevo\Client\Model\GetWhatsappCampaignOverview, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function getWhatsAppCampaignWithHttpInfo($campaignId)
|
|
{
|
|
$returnType = '\Brevo\Client\Model\GetWhatsappCampaignOverview';
|
|
$request = $this->getWhatsAppCampaignRequest($campaignId);
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 200:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\GetWhatsappCampaignOverview',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 404:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppCampaignAsync
|
|
*
|
|
* Get a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function getWhatsAppCampaignAsync($campaignId)
|
|
{
|
|
return $this->getWhatsAppCampaignAsyncWithHttpInfo($campaignId)
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppCampaignAsyncWithHttpInfo
|
|
*
|
|
* Get a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function getWhatsAppCampaignAsyncWithHttpInfo($campaignId)
|
|
{
|
|
$returnType = '\Brevo\Client\Model\GetWhatsappCampaignOverview';
|
|
$request = $this->getWhatsAppCampaignRequest($campaignId);
|
|
|
|
return $this->client
|
|
->sendAsync($request, $this->createHttpClientOption())
|
|
->then(
|
|
function ($response) use ($returnType) {
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
},
|
|
function ($exception) {
|
|
$response = $exception->getResponse();
|
|
$statusCode = $response->getStatusCode();
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$exception->getRequest()->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'getWhatsAppCampaign'
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function getWhatsAppCampaignRequest($campaignId)
|
|
{
|
|
// verify the required parameter 'campaignId' is set
|
|
if ($campaignId === null || (is_array($campaignId) && count($campaignId) === 0)) {
|
|
throw new \InvalidArgumentException(
|
|
'Missing the required parameter $campaignId when calling getWhatsAppCampaign'
|
|
);
|
|
}
|
|
|
|
$resourcePath = '/whatsappCampaigns/{campaignId}';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
|
|
// path params
|
|
if ($campaignId !== null) {
|
|
$resourcePath = str_replace(
|
|
'{' . 'campaignId' . '}',
|
|
ObjectSerializer::toPathValue($campaignId),
|
|
$resourcePath
|
|
);
|
|
}
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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 getWhatsAppCampaigns
|
|
*
|
|
* Return all your created WhatsApp campaigns
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return \Brevo\Client\Model\GetWhatsappCampaigns
|
|
*/
|
|
public function getWhatsAppCampaigns($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc')
|
|
{
|
|
list($response) = $this->getWhatsAppCampaignsWithHttpInfo($startDate, $endDate, $limit, $offset, $sort);
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppCampaignsWithHttpInfo
|
|
*
|
|
* Return all your created WhatsApp campaigns
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of \Brevo\Client\Model\GetWhatsappCampaigns, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function getWhatsAppCampaignsWithHttpInfo($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc')
|
|
{
|
|
$returnType = '\Brevo\Client\Model\GetWhatsappCampaigns';
|
|
$request = $this->getWhatsAppCampaignsRequest($startDate, $endDate, $limit, $offset, $sort);
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 200:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\GetWhatsappCampaigns',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppCampaignsAsync
|
|
*
|
|
* Return all your created WhatsApp campaigns
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function getWhatsAppCampaignsAsync($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc')
|
|
{
|
|
return $this->getWhatsAppCampaignsAsyncWithHttpInfo($startDate, $endDate, $limit, $offset, $sort)
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppCampaignsAsyncWithHttpInfo
|
|
*
|
|
* Return all your created WhatsApp campaigns
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function getWhatsAppCampaignsAsyncWithHttpInfo($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc')
|
|
{
|
|
$returnType = '\Brevo\Client\Model\GetWhatsappCampaigns';
|
|
$request = $this->getWhatsAppCampaignsRequest($startDate, $endDate, $limit, $offset, $sort);
|
|
|
|
return $this->client
|
|
->sendAsync($request, $this->createHttpClientOption())
|
|
->then(
|
|
function ($response) use ($returnType) {
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
},
|
|
function ($exception) {
|
|
$response = $exception->getResponse();
|
|
$statusCode = $response->getStatusCode();
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$exception->getRequest()->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'getWhatsAppCampaigns'
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the campaigns created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function getWhatsAppCampaignsRequest($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc')
|
|
{
|
|
if ($limit !== null && $limit > 100) {
|
|
throw new \InvalidArgumentException('invalid value for "$limit" when calling WhatsAppCampaignsApi.getWhatsAppCampaigns, must be smaller than or equal to 100.');
|
|
}
|
|
if ($limit !== null && $limit < 0) {
|
|
throw new \InvalidArgumentException('invalid value for "$limit" when calling WhatsAppCampaignsApi.getWhatsAppCampaigns, must be bigger than or equal to 0.');
|
|
}
|
|
|
|
|
|
$resourcePath = '/whatsappCampaigns';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
// query params
|
|
if ($startDate !== null) {
|
|
$queryParams['startDate'] = ObjectSerializer::toQueryValue($startDate);
|
|
}
|
|
// query params
|
|
if ($endDate !== null) {
|
|
$queryParams['endDate'] = ObjectSerializer::toQueryValue($endDate);
|
|
}
|
|
// query params
|
|
if ($limit !== null) {
|
|
$queryParams['limit'] = ObjectSerializer::toQueryValue($limit);
|
|
}
|
|
// query params
|
|
if ($offset !== null) {
|
|
$queryParams['offset'] = ObjectSerializer::toQueryValue($offset);
|
|
}
|
|
// query params
|
|
if ($sort !== null) {
|
|
$queryParams['sort'] = ObjectSerializer::toQueryValue($sort);
|
|
}
|
|
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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 getWhatsAppConfig
|
|
*
|
|
* Get your WhatsApp API account information
|
|
*
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return \Brevo\Client\Model\GetWhatsAppConfig
|
|
*/
|
|
public function getWhatsAppConfig()
|
|
{
|
|
list($response) = $this->getWhatsAppConfigWithHttpInfo();
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppConfigWithHttpInfo
|
|
*
|
|
* Get your WhatsApp API account information
|
|
*
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of \Brevo\Client\Model\GetWhatsAppConfig, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function getWhatsAppConfigWithHttpInfo()
|
|
{
|
|
$returnType = '\Brevo\Client\Model\GetWhatsAppConfig';
|
|
$request = $this->getWhatsAppConfigRequest();
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 200:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\GetWhatsAppConfig',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppConfigAsync
|
|
*
|
|
* Get your WhatsApp API account information
|
|
*
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function getWhatsAppConfigAsync()
|
|
{
|
|
return $this->getWhatsAppConfigAsyncWithHttpInfo()
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppConfigAsyncWithHttpInfo
|
|
*
|
|
* Get your WhatsApp API account information
|
|
*
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function getWhatsAppConfigAsyncWithHttpInfo()
|
|
{
|
|
$returnType = '\Brevo\Client\Model\GetWhatsAppConfig';
|
|
$request = $this->getWhatsAppConfigRequest();
|
|
|
|
return $this->client
|
|
->sendAsync($request, $this->createHttpClientOption())
|
|
->then(
|
|
function ($response) use ($returnType) {
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
},
|
|
function ($exception) {
|
|
$response = $exception->getResponse();
|
|
$statusCode = $response->getStatusCode();
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$exception->getRequest()->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'getWhatsAppConfig'
|
|
*
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function getWhatsAppConfigRequest()
|
|
{
|
|
|
|
$resourcePath = '/whatsappCampaigns/config';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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 getWhatsAppTemplates
|
|
*
|
|
* Return all your created WhatsApp templates
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
* @param string $source source of the template (optional)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return \Brevo\Client\Model\GetWATemplates
|
|
*/
|
|
public function getWhatsAppTemplates($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc', $source = null)
|
|
{
|
|
list($response) = $this->getWhatsAppTemplatesWithHttpInfo($startDate, $endDate, $limit, $offset, $sort, $source);
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppTemplatesWithHttpInfo
|
|
*
|
|
* Return all your created WhatsApp templates
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
* @param string $source source of the template (optional)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of \Brevo\Client\Model\GetWATemplates, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function getWhatsAppTemplatesWithHttpInfo($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc', $source = null)
|
|
{
|
|
$returnType = '\Brevo\Client\Model\GetWATemplates';
|
|
$request = $this->getWhatsAppTemplatesRequest($startDate, $endDate, $limit, $offset, $sort, $source);
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 200:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\GetWATemplates',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppTemplatesAsync
|
|
*
|
|
* Return all your created WhatsApp templates
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
* @param string $source source of the template (optional)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function getWhatsAppTemplatesAsync($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc', $source = null)
|
|
{
|
|
return $this->getWhatsAppTemplatesAsyncWithHttpInfo($startDate, $endDate, $limit, $offset, $sort, $source)
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation getWhatsAppTemplatesAsyncWithHttpInfo
|
|
*
|
|
* Return all your created WhatsApp templates
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
* @param string $source source of the template (optional)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function getWhatsAppTemplatesAsyncWithHttpInfo($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc', $source = null)
|
|
{
|
|
$returnType = '\Brevo\Client\Model\GetWATemplates';
|
|
$request = $this->getWhatsAppTemplatesRequest($startDate, $endDate, $limit, $offset, $sort, $source);
|
|
|
|
return $this->client
|
|
->sendAsync($request, $this->createHttpClientOption())
|
|
->then(
|
|
function ($response) use ($returnType) {
|
|
$responseBody = $response->getBody();
|
|
if ($returnType === '\SplFileObject') {
|
|
$content = $responseBody; //stream goes to serializer
|
|
} else {
|
|
$content = $responseBody->getContents();
|
|
if ($returnType !== 'string') {
|
|
$content = json_decode($content);
|
|
}
|
|
}
|
|
|
|
return [
|
|
ObjectSerializer::deserialize($content, $returnType, []),
|
|
$response->getStatusCode(),
|
|
$response->getHeaders()
|
|
];
|
|
},
|
|
function ($exception) {
|
|
$response = $exception->getResponse();
|
|
$statusCode = $response->getStatusCode();
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$exception->getRequest()->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'getWhatsAppTemplates'
|
|
*
|
|
* @param string $startDate **Mandatory if endDate is used**. Starting (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param string $endDate **Mandatory if startDate is used**. Ending (urlencoded) UTC date-time (YYYY-MM-DDTHH:mm:ss.SSSZ) to filter the templates created. **Prefer to pass your timezone in date-time format for accurate result** (optional)
|
|
* @param int $limit Number of documents per page (optional, default to 50)
|
|
* @param int $offset Index of the first document in the page (optional, default to 0)
|
|
* @param string $sort Sort the results in the ascending/descending order of record modification. Default order is **descending** if `sort` is not passed (optional, default to desc)
|
|
* @param string $source source of the template (optional)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function getWhatsAppTemplatesRequest($startDate = null, $endDate = null, $limit = '50', $offset = '0', $sort = 'desc', $source = null)
|
|
{
|
|
if ($limit !== null && $limit > 100) {
|
|
throw new \InvalidArgumentException('invalid value for "$limit" when calling WhatsAppCampaignsApi.getWhatsAppTemplates, must be smaller than or equal to 100.');
|
|
}
|
|
if ($limit !== null && $limit < 0) {
|
|
throw new \InvalidArgumentException('invalid value for "$limit" when calling WhatsAppCampaignsApi.getWhatsAppTemplates, must be bigger than or equal to 0.');
|
|
}
|
|
|
|
|
|
$resourcePath = '/whatsappCampaigns/template-list';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
// query params
|
|
if ($startDate !== null) {
|
|
$queryParams['startDate'] = ObjectSerializer::toQueryValue($startDate);
|
|
}
|
|
// query params
|
|
if ($endDate !== null) {
|
|
$queryParams['endDate'] = ObjectSerializer::toQueryValue($endDate);
|
|
}
|
|
// query params
|
|
if ($limit !== null) {
|
|
$queryParams['limit'] = ObjectSerializer::toQueryValue($limit);
|
|
}
|
|
// query params
|
|
if ($offset !== null) {
|
|
$queryParams['offset'] = ObjectSerializer::toQueryValue($offset);
|
|
}
|
|
// query params
|
|
if ($sort !== null) {
|
|
$queryParams['sort'] = ObjectSerializer::toQueryValue($sort);
|
|
}
|
|
// query params
|
|
if ($source !== null) {
|
|
$queryParams['source'] = ObjectSerializer::toQueryValue($source);
|
|
}
|
|
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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 sendWhatsAppTemplateApproval
|
|
*
|
|
* Send your WhatsApp template for approval
|
|
*
|
|
* @param int $templateId id of the campaign (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return void
|
|
*/
|
|
public function sendWhatsAppTemplateApproval($templateId)
|
|
{
|
|
$this->sendWhatsAppTemplateApprovalWithHttpInfo($templateId);
|
|
}
|
|
|
|
/**
|
|
* Operation sendWhatsAppTemplateApprovalWithHttpInfo
|
|
*
|
|
* Send your WhatsApp template for approval
|
|
*
|
|
* @param int $templateId id of the campaign (required)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of null, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function sendWhatsAppTemplateApprovalWithHttpInfo($templateId)
|
|
{
|
|
$returnType = '';
|
|
$request = $this->sendWhatsAppTemplateApprovalRequest($templateId);
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
return [null, $statusCode, $response->getHeaders()];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation sendWhatsAppTemplateApprovalAsync
|
|
*
|
|
* Send your WhatsApp template for approval
|
|
*
|
|
* @param int $templateId id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function sendWhatsAppTemplateApprovalAsync($templateId)
|
|
{
|
|
return $this->sendWhatsAppTemplateApprovalAsyncWithHttpInfo($templateId)
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation sendWhatsAppTemplateApprovalAsyncWithHttpInfo
|
|
*
|
|
* Send your WhatsApp template for approval
|
|
*
|
|
* @param int $templateId id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function sendWhatsAppTemplateApprovalAsyncWithHttpInfo($templateId)
|
|
{
|
|
$returnType = '';
|
|
$request = $this->sendWhatsAppTemplateApprovalRequest($templateId);
|
|
|
|
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(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'sendWhatsAppTemplateApproval'
|
|
*
|
|
* @param int $templateId id of the campaign (required)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function sendWhatsAppTemplateApprovalRequest($templateId)
|
|
{
|
|
// verify the required parameter 'templateId' is set
|
|
if ($templateId === null || (is_array($templateId) && count($templateId) === 0)) {
|
|
throw new \InvalidArgumentException(
|
|
'Missing the required parameter $templateId when calling sendWhatsAppTemplateApproval'
|
|
);
|
|
}
|
|
|
|
$resourcePath = '/whatsappCampaigns/template/approval/{templateId}';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
|
|
// path params
|
|
if ($templateId !== null) {
|
|
$resourcePath = str_replace(
|
|
'{' . 'templateId' . '}',
|
|
ObjectSerializer::toPathValue($templateId),
|
|
$resourcePath
|
|
);
|
|
}
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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 updateWhatsAppCampaign
|
|
*
|
|
* Update a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
* @param \Brevo\Client\Model\UpdateWhatsAppCampaign $whatsAppCampaign values to update WhatsApp Campaign (optional)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return void
|
|
*/
|
|
public function updateWhatsAppCampaign($campaignId, $whatsAppCampaign = null)
|
|
{
|
|
$this->updateWhatsAppCampaignWithHttpInfo($campaignId, $whatsAppCampaign);
|
|
}
|
|
|
|
/**
|
|
* Operation updateWhatsAppCampaignWithHttpInfo
|
|
*
|
|
* Update a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
* @param \Brevo\Client\Model\UpdateWhatsAppCampaign $whatsAppCampaign values to update WhatsApp Campaign (optional)
|
|
*
|
|
* @throws \Brevo\Client\ApiException on non-2xx response
|
|
* @throws \InvalidArgumentException
|
|
* @return array of null, HTTP status code, HTTP response headers (array of strings)
|
|
*/
|
|
public function updateWhatsAppCampaignWithHttpInfo($campaignId, $whatsAppCampaign = null)
|
|
{
|
|
$returnType = '';
|
|
$request = $this->updateWhatsAppCampaignRequest($campaignId, $whatsAppCampaign);
|
|
|
|
try {
|
|
$options = $this->createHttpClientOption();
|
|
try {
|
|
$response = $this->client->send($request, $options);
|
|
} catch (RequestException $e) {
|
|
throw new ApiException(
|
|
"[{$e->getCode()}] {$e->getMessage()}",
|
|
$e->getCode(),
|
|
$e->getResponse() ? $e->getResponse()->getHeaders() : null,
|
|
$e->getResponse() ? $e->getResponse()->getBody()->getContents() : null
|
|
);
|
|
}
|
|
|
|
$statusCode = $response->getStatusCode();
|
|
|
|
if ($statusCode < 200 || $statusCode > 299) {
|
|
throw new ApiException(
|
|
sprintf(
|
|
'[%d] Error connecting to the API (%s)',
|
|
$statusCode,
|
|
$request->getUri()
|
|
),
|
|
$statusCode,
|
|
$response->getHeaders(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
|
|
return [null, $statusCode, $response->getHeaders()];
|
|
|
|
} catch (ApiException $e) {
|
|
switch ($e->getCode()) {
|
|
case 400:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
case 404:
|
|
$data = ObjectSerializer::deserialize(
|
|
$e->getResponseBody(),
|
|
'\Brevo\Client\Model\ErrorModel',
|
|
$e->getResponseHeaders()
|
|
);
|
|
$e->setResponseObject($data);
|
|
break;
|
|
}
|
|
throw $e;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Operation updateWhatsAppCampaignAsync
|
|
*
|
|
* Update a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
* @param \Brevo\Client\Model\UpdateWhatsAppCampaign $whatsAppCampaign values to update WhatsApp Campaign (optional)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function updateWhatsAppCampaignAsync($campaignId, $whatsAppCampaign = null)
|
|
{
|
|
return $this->updateWhatsAppCampaignAsyncWithHttpInfo($campaignId, $whatsAppCampaign)
|
|
->then(
|
|
function ($response) {
|
|
return $response[0];
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Operation updateWhatsAppCampaignAsyncWithHttpInfo
|
|
*
|
|
* Update a WhatsApp campaign
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
* @param \Brevo\Client\Model\UpdateWhatsAppCampaign $whatsAppCampaign values to update WhatsApp Campaign (optional)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Promise\PromiseInterface
|
|
*/
|
|
public function updateWhatsAppCampaignAsyncWithHttpInfo($campaignId, $whatsAppCampaign = null)
|
|
{
|
|
$returnType = '';
|
|
$request = $this->updateWhatsAppCampaignRequest($campaignId, $whatsAppCampaign);
|
|
|
|
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(),
|
|
$response->getBody()
|
|
);
|
|
}
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create request for operation 'updateWhatsAppCampaign'
|
|
*
|
|
* @param int $campaignId Id of the campaign (required)
|
|
* @param \Brevo\Client\Model\UpdateWhatsAppCampaign $whatsAppCampaign values to update WhatsApp Campaign (optional)
|
|
*
|
|
* @throws \InvalidArgumentException
|
|
* @return \GuzzleHttp\Psr7\Request
|
|
*/
|
|
protected function updateWhatsAppCampaignRequest($campaignId, $whatsAppCampaign = null)
|
|
{
|
|
// verify the required parameter 'campaignId' is set
|
|
if ($campaignId === null || (is_array($campaignId) && count($campaignId) === 0)) {
|
|
throw new \InvalidArgumentException(
|
|
'Missing the required parameter $campaignId when calling updateWhatsAppCampaign'
|
|
);
|
|
}
|
|
|
|
$resourcePath = '/whatsappCampaigns/{campaignId}';
|
|
$formParams = [];
|
|
$queryParams = [];
|
|
$headerParams = [];
|
|
$httpBody = '';
|
|
$multipart = false;
|
|
|
|
|
|
// path params
|
|
if ($campaignId !== null) {
|
|
$resourcePath = str_replace(
|
|
'{' . 'campaignId' . '}',
|
|
ObjectSerializer::toPathValue($campaignId),
|
|
$resourcePath
|
|
);
|
|
}
|
|
|
|
// body params
|
|
$_tempBody = null;
|
|
if (isset($whatsAppCampaign)) {
|
|
$_tempBody = $whatsAppCampaign;
|
|
}
|
|
|
|
if ($multipart) {
|
|
$headers = $this->headerSelector->selectHeadersForMultipart(
|
|
['application/json']
|
|
);
|
|
} else {
|
|
$headers = $this->headerSelector->selectHeaders(
|
|
['application/json'],
|
|
['application/json']
|
|
);
|
|
}
|
|
|
|
// for model (json/xml)
|
|
if (isset($_tempBody)) {
|
|
// $_tempBody is the method argument, if present
|
|
$httpBody = $_tempBody;
|
|
|
|
if($headers['Content-Type'] === 'application/json') {
|
|
// \stdClass has no __toString(), so we should encode it manually
|
|
if ($httpBody instanceof \stdClass) {
|
|
$httpBody = \GuzzleHttp\json_encode($httpBody);
|
|
}
|
|
// array has no __toString(), so we should encode it manually
|
|
if(is_array($httpBody)) {
|
|
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($httpBody));
|
|
}
|
|
}
|
|
} elseif (count($formParams) > 0) {
|
|
if ($multipart) {
|
|
$multipartContents = [];
|
|
foreach ($formParams as $formParamName => $formParamValue) {
|
|
$multipartContents[] = [
|
|
'name' => $formParamName,
|
|
'contents' => $formParamValue
|
|
];
|
|
}
|
|
// 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) {
|
|
$headers['api-key'] = $apiKey;
|
|
}
|
|
// this endpoint requires API key authentication
|
|
$apiKey = $this->config->getApiKeyWithPrefix('partner-key');
|
|
if ($apiKey !== null) {
|
|
$headers['partner-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;
|
|
}
|
|
}
|