Skip to content

Commit

Permalink
Merge pull request #4 from retrowaver/custom_http_build_query
Browse files Browse the repository at this point in the history
custom httpBuildQuery method
  • Loading branch information
retrowaver authored May 29, 2019
2 parents 5310195 + f756570 commit b941cbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function getAuthorizationUri()
'redirect_uri' => $this->redirectUri
);

return static::AUTHORIZATION_URI . '?' . http_build_query($data);
return static::AUTHORIZATION_URI . '?' . $this->httpBuildQuery($data);
}

/**
Expand Down Expand Up @@ -113,7 +113,7 @@ private function requestAccessToken($data)
"Content-Type: application/x-www-form-urlencoded"
);

$data = http_build_query($data);
$data = $this->httpBuildQuery($data);

$response = $this->sendHttpRequest(static::TOKEN_URI, 'POST', $headers, $data);

Expand Down
20 changes: 18 additions & 2 deletions src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function get($data = null)

if ($data !== null) {
$uri .= '?';
$uri .= http_build_query($data);
$uri .= $this->httpBuildQuery($data);
}

return $this->sendApiRequest($uri, 'GET');
Expand Down Expand Up @@ -91,7 +91,7 @@ public function delete($data = null)

if ($data !== null) {
$uri .= '?';
$uri .= http_build_query($data);
$uri .= $this->httpBuildQuery($data);
}

return $this->sendApiRequest($uri, 'DELETE');
Expand Down Expand Up @@ -155,6 +155,22 @@ protected function sendHttpRequest($url, $method, $headers = array(), $data = ''
return file_get_contents($url, false, $context);
}

/**
* @param array $data
* @return string
*/
protected function httpBuildQuery($data)
{
// Change booleans to strings ("true" / "false")
foreach ($data as $key => $value) {
if (gettype($value) === 'boolean') {
$data[$key] = var_export($value, true);
}
}

return preg_replace('/%5B\d+%5D/', '', http_build_query($data));
}

/**
* @var string
*/
Expand Down

0 comments on commit b941cbe

Please sign in to comment.