Skip to content

Commit

Permalink
fix(php): Remove header handling in clients (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
damcou authored Feb 10, 2022
1 parent a26d4b5 commit 5854261
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 1,784 deletions.
2 changes: 1 addition & 1 deletion clients/algoliasearch-client-php/lib/Algolia.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class Algolia
{
const VERSION = '1.0.0';
const VERSION = '4.0.0';

/**
* Holds an instance of the simple cache repository (PSR-16).
Expand Down
103 changes: 8 additions & 95 deletions clients/algoliasearch-client-php/lib/Api/AbtestingApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,13 @@ public function addABTests($addABTestsRequest)

$resourcePath = '/2/abtests';
$queryParams = [];
$headerParams = [];
$httpBody = [];

$headers = [];
$headers['Accept'] = 'application/json';
$headers['Content-Type'] = '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);
return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody);
}
/**
* Operation deleteABTest
Expand All @@ -157,7 +140,6 @@ public function deleteABTest($id)

$resourcePath = '/2/abtests/{id}';
$queryParams = [];
$headerParams = [];
$httpBody = [];
// path params
if ($id !== null) {
Expand All @@ -168,24 +150,7 @@ public function deleteABTest($id)
);
}

$headers = [];
$headers['Accept'] = 'application/json';
$headers['Content-Type'] = '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);
return $this->sendRequest('DELETE', $resourcePath, $queryParams, $httpBody);
}
/**
* Operation getABTest
Expand All @@ -210,7 +175,6 @@ public function getABTest($id)

$resourcePath = '/2/abtests/{id}';
$queryParams = [];
$headerParams = [];
$httpBody = [];
// path params
if ($id !== null) {
Expand All @@ -221,24 +185,7 @@ public function getABTest($id)
);
}

$headers = [];
$headers['Accept'] = 'application/json';
$headers['Content-Type'] = '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);
return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody);
}
/**
* Operation listABTests
Expand All @@ -257,7 +204,6 @@ public function listABTests($offset = 0, $limit = 10)
{
$resourcePath = '/2/abtests';
$queryParams = [];
$headerParams = [];
$httpBody = [];

if ($offset !== null) {
Expand All @@ -280,24 +226,7 @@ public function listABTests($offset = 0, $limit = 10)
}
}

$headers = [];
$headers['Accept'] = 'application/json';
$headers['Content-Type'] = '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);
return $this->sendRequest('GET', $resourcePath, $queryParams, $httpBody);
}
/**
* Operation stopABTest
Expand All @@ -322,7 +251,6 @@ public function stopABTest($id)

$resourcePath = '/2/abtests/{id}/stop';
$queryParams = [];
$headerParams = [];
$httpBody = [];
// path params
if ($id !== null) {
Expand All @@ -333,28 +261,13 @@ public function stopABTest($id)
);
}

$headers = [];
$headers['Accept'] = 'application/json';
$headers['Content-Type'] = '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);
return $this->sendRequest('POST', $resourcePath, $queryParams, $httpBody);
}

private function sendRequest($method, $resourcePath, $query, $httpBody)
private function sendRequest($method, $resourcePath, $queryParams, $httpBody)
{
$query = \GuzzleHttp\Psr7\Query::build($queryParams);

if ($method === 'GET') {
$request = $this->api->read(
$method,
Expand Down
Loading

0 comments on commit 5854261

Please sign in to comment.