Skip to content

Commit

Permalink
Use 'consumes' for Content-Type. Replaced API_CONTENT_TYPE_JSON const…
Browse files Browse the repository at this point in the history
…ant with fallback constants for both Content-Type and Accept.
  • Loading branch information
robvanaarle committed Jul 12, 2023
1 parent 97d5f9c commit d50bca0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class BaseClient
{
protected const API_TOKEN_URI = 'https://login.bol.com/token';
protected const API_ENDPOINT = 'https://api.bol.com/';
protected const API_CONTENT_TYPE_JSON = 'application/vnd.retailer.v10+json';
protected const API_CONTENT_TYPE_FALLBACK = 'application/vnd.retailer.v10+json';
protected const API_ACCEPT_FALLBACK = 'application/vnd.retailer.v10+json';

/**
* @var bool Whether request will be sent to the demo endpoint.
Expand Down Expand Up @@ -390,13 +391,13 @@ private function prepareAndExecuteRequest(string $method, string $url, array $op

$httpOptions = [];
$httpOptions['headers'] = [
'Accept' => $options['produces'] ?? static::API_CONTENT_TYPE_JSON,
'Accept' => $options['produces'] ?? static::API_ACCEPT_FALLBACK,
'Authorization' => sprintf('Bearer %s', $this->accessToken->getToken()),
];

// encode the body if a model is supplied for it
if (isset($options['body']) && $options['body'] instanceof AbstractModel) {
$httpOptions['headers']['Content-Type'] = static::API_CONTENT_TYPE_JSON;
$httpOptions['headers']['Content-Type'] = $options['consumes'] ?? static::API_CONTENT_TYPE_FALLBACK;
$httpOptions['body'] = json_encode($options['body']->toArray(true));
}

Expand Down

0 comments on commit d50bca0

Please sign in to comment.