Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(php): Add remaining php clients #106

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/algoliasearch-client-php/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "algolia/algoliasearch-client-php",
"description": "API powering the Search feature of Algolia.",
"description": "API powering the features of Algolia.",
"keywords": [
"openapitools",
"openapi-generator",
Expand Down
374 changes: 374 additions & 0 deletions clients/algoliasearch-client-php/lib/Api/AbtestingApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,374 @@
<?php

namespace Algolia\AlgoliaSearch\Api;

use Algolia\AlgoliaSearch\Algolia;
use Algolia\AlgoliaSearch\Configuration\AbTestingConfig;
use Algolia\AlgoliaSearch\HeaderSelector;
use Algolia\AlgoliaSearch\ObjectSerializer;
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapper;
use Algolia\AlgoliaSearch\RetryStrategy\ApiWrapperInterface;
use Algolia\AlgoliaSearch\RetryStrategy\ClusterHosts;

/**
* AbtestingApi Class Doc Comment
*
* @category Class
* @package Algolia\AlgoliaSearch
*/
class AbtestingApi
{
/**
* @var ApiWrapperInterface
*/
protected $api;

/**
* @var AbTestingConfig
*/
protected $config;

/**
* @var HeaderSelector
*/
protected $headerSelector;

/**
* @param AbTestingConfig $config
* @param ApiWrapperInterface $apiWrapper
*/
public function __construct(ApiWrapperInterface $apiWrapper, AbTestingConfig $config)
{
$this->config = $config;

$this->api = $apiWrapper;
$this->headerSelector = new HeaderSelector();
}

/**
* Instantiate the client with basic credentials and region
*
* @param string $appId Application ID
* @param string $apiKey Algolia API Key
* @param string $region Region
*/
public static function create($appId = null, $apiKey = null, $region = null)
{
$allowedRegions = explode('-', 'us-de');
$config = AbTestingConfig::create($appId, $apiKey, $region, $allowedRegions);

return static::createWithConfig($config);
}

/**
* Instantiate the client with congiguration
*
* @param AbTestingConfig $config Configuration
*/
public static function createWithConfig(AbTestingConfig $config)
{
$config = clone $config;

if ($hosts = $config->getHosts()) {
// If a list of hosts was passed, we ignore the cache
$clusterHosts = ClusterHosts::create($hosts);
} else {
$clusterHosts = ClusterHosts::createForAnalytics($config->getAppId());
}

$apiWrapper = new ApiWrapper(
Algolia::getHttpClient(),
$config,
$clusterHosts
);

return new static($apiWrapper, $config);
}

/**
* @return AbTestingConfig
*/
public function getClientConfig()
{
return $this->config;
}

/**
* Operation addABTests
*
* Creates a new A/B test with provided configuration.
*
* @param \Algolia\AlgoliaSearch\Model\AddABTestsRequest $addABTestsRequest addABTestsRequest (required)
*
* @throws \Algolia\AlgoliaSearch\ApiException on non-2xx response
* @throws \InvalidArgumentException
*
* @return \Algolia\AlgoliaSearch\Model\ABTestResponse|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase
*/
public function addABTests($addABTestsRequest)
{
// verify the required parameter 'addABTestsRequest' is set
if ($addABTestsRequest === null || (is_array($addABTestsRequest) && count($addABTestsRequest) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $addABTestsRequest when calling addABTests'
);
}

$resourcePath = '/2/abtests';
$queryParams = [];
$headerParams = [];
$httpBody = [];
$headers = $this->headerSelector->selectHeaders(
['application/json'],
['application/json']
);
if (isset($addABTestsRequest)) {
$httpBody = $addABTestsRequest;
}

$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}

$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);

$query = \GuzzleHttp\Psr7\Query::build($queryParams);

return $this->sendRequest('POST', $resourcePath, $query, $httpBody);
}
/**
* Operation deleteABTest
*
* Deletes the A/B Test.
*
* @param int $id The A/B test ID. (required)
*
* @throws \Algolia\AlgoliaSearch\ApiException on non-2xx response
* @throws \InvalidArgumentException
*
* @return \Algolia\AlgoliaSearch\Model\ABTestResponse|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase
*/
public function deleteABTest($id)
{
// verify the required parameter 'id' is set
if ($id === null || (is_array($id) && count($id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $id when calling deleteABTest'
);
}

$resourcePath = '/2/abtests/{id}';
$queryParams = [];
$headerParams = [];
$httpBody = [];
// path params
if ($id !== null) {
$resourcePath = str_replace(
'{' . 'id' . '}',
ObjectSerializer::toPathValue($id),
$resourcePath
);
}
$headers = $this->headerSelector->selectHeaders(
['application/json'],
[]
);

$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}

$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);

$query = \GuzzleHttp\Psr7\Query::build($queryParams);

return $this->sendRequest('DELETE', $resourcePath, $query, $httpBody);
}
/**
* Operation getABTest
*
* Returns metadata and metrics for A/B test id.
*
* @param int $id The A/B test ID. (required)
*
* @throws \Algolia\AlgoliaSearch\ApiException on non-2xx response
* @throws \InvalidArgumentException
*
* @return \Algolia\AlgoliaSearch\Model\ABTest|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase
*/
public function getABTest($id)
{
// verify the required parameter 'id' is set
if ($id === null || (is_array($id) && count($id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $id when calling getABTest'
);
}

$resourcePath = '/2/abtests/{id}';
$queryParams = [];
$headerParams = [];
$httpBody = [];
// path params
if ($id !== null) {
$resourcePath = str_replace(
'{' . 'id' . '}',
ObjectSerializer::toPathValue($id),
$resourcePath
);
}
$headers = $this->headerSelector->selectHeaders(
['application/json'],
[]
);

$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}

$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);

$query = \GuzzleHttp\Psr7\Query::build($queryParams);

return $this->sendRequest('GET', $resourcePath, $query, $httpBody);
}
/**
* Operation listABTests
*
* Fetch all existing A/B tests for App that are available for the current API Key.
*
* @param int $offset Position of the starting record. Used for paging. 0 is the first record. (optional, default to 0)
* @param int $limit Number of records to return. Limit is the size of the page. (optional, default to 10)
*
* @throws \Algolia\AlgoliaSearch\ApiException on non-2xx response
* @throws \InvalidArgumentException
*
* @return \Algolia\AlgoliaSearch\Model\ListABTestsResponse|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase
*/
public function listABTests($offset = 0, $limit = 10)
{
$resourcePath = '/2/abtests';
$queryParams = [];
$headerParams = [];
$httpBody = [];
// query params
if (is_array($offset)) {
$offset = ObjectSerializer::serializeCollection($offset, '', true);
}
if ($offset !== null) {
$queryParams['offset'] = $offset;
}
// query params
if (is_array($limit)) {
$limit = ObjectSerializer::serializeCollection($limit, '', true);
}
if ($limit !== null) {
$queryParams['limit'] = $limit;
}
$headers = $this->headerSelector->selectHeaders(
['application/json'],
[]
);

$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}

$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);

$query = \GuzzleHttp\Psr7\Query::build($queryParams);

return $this->sendRequest('GET', $resourcePath, $query, $httpBody);
}
/**
* Operation stopABTest
*
* Marks the A/B test as stopped.
*
* @param int $id The A/B test ID. (required)
*
* @throws \Algolia\AlgoliaSearch\ApiException on non-2xx response
* @throws \InvalidArgumentException
*
* @return \Algolia\AlgoliaSearch\Model\ABTestResponse|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase|\Algolia\AlgoliaSearch\Model\ErrorBase
*/
public function stopABTest($id)
{
// verify the required parameter 'id' is set
if ($id === null || (is_array($id) && count($id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $id when calling stopABTest'
);
}

$resourcePath = '/2/abtests/{id}/stop';
$queryParams = [];
$headerParams = [];
$httpBody = [];
// path params
if ($id !== null) {
$resourcePath = str_replace(
'{' . 'id' . '}',
ObjectSerializer::toPathValue($id),
$resourcePath
);
}
$headers = $this->headerSelector->selectHeaders(
['application/json'],
[]
);

$defaultHeaders = [];
if ($this->config->getUserAgent()) {
$defaultHeaders['User-Agent'] = $this->config->getUserAgent();
}

$headers = array_merge(
$defaultHeaders,
$headerParams,
$headers
);

$query = \GuzzleHttp\Psr7\Query::build($queryParams);

return $this->sendRequest('POST', $resourcePath, $query, $httpBody);
}

private function sendRequest($method, $resourcePath, $query, $httpBody)
{
if ($method === 'GET') {
$request = $this->api->read(
$method,
$resourcePath . ($query ? "?{$query}" : '')
);
} else {
$request = $this->api->write(
$method,
$resourcePath . ($query ? "?{$query}" : ''),
$httpBody
);
}

return $request;
}
}
Loading