Skip to content

Commit

Permalink
Merge pull request #1 from AlissonCorrea/master
Browse files Browse the repository at this point in the history
Deixando mais flexível os métodos que utilizam o método resourcePostR…
  • Loading branch information
idealizetecnologia authored Mar 24, 2022
2 parents e536103 + 04dd7d1 commit 6230bf4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ $apiInstance = new Meli\Api\RestClientApi(
);
$resource = 'resource_example'; // string | for example: items
$access_token = 'access_token_example'; // string |
$options = ['headers' => ['access_token' => $access_token]]; // array |
$body = new \stdClass; // object |

try {
$apiInstance->resourcePost($resource, $access_token, $body);
$apiInstance->resourcePost($resource, $options, $body);
} catch (Exception $e) {
echo 'Exception when calling RestClientApi->resourcePost: ', $e->getMessage(), PHP_EOL;
}
Expand Down
3 changes: 2 additions & 1 deletion docs/Api/RestClientApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ $apiInstance = new Meli\Api\RestClientApi(
);
$resource = 'resource_example'; // string |
$access_token = 'access_token_example'; // string |
$options = ['headers' => ['access_token' => $access_token]]; // array |
$body = new \stdClass; // object |

try {
$result = $apiInstance->resourcePost($resource, $access_token, $body);
$result = $apiInstance->resourcePost($resource, $options, $body);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling RestClientApi->resourcePost: ', $e->getMessage(), PHP_EOL;
Expand Down
4 changes: 2 additions & 2 deletions examples/restClientPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
);
$resource = 'items'; // A resource example like items, search, category, etc.
$access_token = 'access_token_example'; // Your access token.

$options = ['headers' => ['access_token' => $access_token]];
$body = json_decode('{
"title": "Item de test - No Ofertar",
"category_id": "MLA5991",
Expand Down Expand Up @@ -72,7 +72,7 @@
}');

try {
$result = $apiInstance->resourcePost($resource, $access_token, $body);
$result = $apiInstance->resourcePost($resource, $options, $body);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling RestClientApi->resourcePost: ', $e->getMessage(), PHP_EOL;
Expand Down
40 changes: 21 additions & 19 deletions lib/Api/RestClientApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,16 +709,16 @@ protected function resourceGetRequest($resource, $access_token)
* Resourse path POST
*
* @param string $resource resource (required)
* @param string $access_token access_token (required)
* @param array $options options (required)
* @param object $body body (required)
*
* @throws \Meli\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return object
*/
public function resourcePost($resource, $access_token, $body)
public function resourcePost($resource, $options, $body)
{
list($response) = $this->resourcePostWithHttpInfo($resource, $access_token, $body);
list($response) = $this->resourcePostWithHttpInfo($resource, $options, $body);
return $response;
}

Expand All @@ -728,16 +728,16 @@ public function resourcePost($resource, $access_token, $body)
* Resourse path POST
*
* @param string $resource (required)
* @param string $access_token (required)
* @param array $options (required)
* @param object $body (required)
*
* @throws \Meli\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return array of object, HTTP status code, HTTP response headers (array of strings)
*/
public function resourcePostWithHttpInfo($resource, $access_token, $body)
public function resourcePostWithHttpInfo($resource, $options, $body)
{
$request = $this->resourcePostRequest($resource, $access_token, $body);
$request = $this->resourcePostRequest($resource, $options, $body);

try {
$options = $this->createHttpClientOption();
Expand Down Expand Up @@ -818,15 +818,15 @@ public function resourcePostWithHttpInfo($resource, $access_token, $body)
* Resourse path POST
*
* @param string $resource (required)
* @param string $access_token (required)
* @param array $options (required)
* @param object $body (required)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function resourcePostAsync($resource, $access_token, $body)
public function resourcePostAsync($resource, $options, $body)
{
return $this->resourcePostAsyncWithHttpInfo($resource, $access_token, $body)
return $this->resourcePostAsyncWithHttpInfo($resource, $options, $body)
->then(
function ($response) {
return $response[0];
Expand All @@ -840,16 +840,16 @@ function ($response) {
* Resourse path POST
*
* @param string $resource (required)
* @param string $access_token (required)
* @param array $options (required)
* @param object $body (required)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function resourcePostAsyncWithHttpInfo($resource, $access_token, $body)
public function resourcePostAsyncWithHttpInfo($resource, $options, $body)
{
$returnType = 'object';
$request = $this->resourcePostRequest($resource, $access_token, $body);
$request = $this->resourcePostRequest($resource, $options, $body);

return $this->client
->sendAsync($request, $this->createHttpClientOption())
Expand Down Expand Up @@ -889,22 +889,25 @@ function ($exception) {
* Create request for operation 'resourcePost'
*
* @param string $resource (required)
* @param string $access_token (required)
* @param array $options (required)
* @param object $body (required)
*
* @throws \InvalidArgumentException
* @return \GuzzleHttp\Psr7\Request
*/
protected function resourcePostRequest($resource, $access_token, $body)
protected function resourcePostRequest($resource, $options, $body)
{
$headers = isset($options['headers']) ? $options['headers'] : [];
$queryParams = isset($options['queryParams']) ? $options['queryParams'] : [];

// verify the required parameter 'resource' is set
if ($resource === null || (is_array($resource) && count($resource) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $resource when calling resourcePost'
);
}
// verify the required parameter 'access_token' is set
if ($access_token === null || (is_array($access_token) && count($access_token) === 0)) {
if ($headers['access_token'] === null || (is_array($headers['access_token']) && count($headers['access_token']) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $access_token when calling resourcePost'
);
Expand All @@ -918,7 +921,6 @@ protected function resourcePostRequest($resource, $access_token, $body)

$resourcePath = '/{resource}';
$formParams = [];
$queryParams = [];
$headerParams = [];
$httpBody = '';
$multipart = false;
Expand All @@ -941,13 +943,13 @@ protected function resourcePostRequest($resource, $access_token, $body)
if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
['application/json'],
$access_token
$headers['access_token']
);
} else {
$headers = $this->headerSelector->selectHeaders(
['application/json'],
['application/json'],
$access_token
$headers['content_type'],
$headers['access_token']
);
}

Expand Down

0 comments on commit 6230bf4

Please sign in to comment.