Convert a PSR-7 response to a data type you want to work with.
public static convert ( Psr\Http\Message\ResponseInterface $response, string $requestFormat, string $dataType ) : Psr\Http\Message\ResponseInterface | Psr\Http\Message\StreamInterface | SimpleXMLElement | string | ||
$response | Psr\Http\Message\ResponseInterface | |
$requestFormat | string | |
$dataType | string | |
리턴 | Psr\Http\Message\ResponseInterface | Psr\Http\Message\StreamInterface | SimpleXMLElement | string |
/** * @expectedException \Happyr\LinkedIn\Exception\InvalidArgumentException */ public function testConvertJsonToFoobar() { $body = '{"foo":"bar"}'; $response = new Response(200, [], $body); ResponseConverter::convert($response, 'json', 'foobar'); }
/** * {@inheritdoc} */ public function api($method, $resource, array $options = array()) { // Add access token to the headers $options['headers']['Authorization'] = sprintf('Bearer %s', (string) $this->getAccessToken()); // Do logic and adjustments to the options $requestFormat = $this->filterRequestOption($options); // Generate an url $url = $this->getUrlGenerator()->getUrl('api', $resource, isset($options['query']) ? $options['query'] : array()); $body = isset($options['body']) ? $options['body'] : null; $this->lastResponse = $this->getRequestManager()->sendRequest($method, $url, $options['headers'], $body); //Get the response data format if (isset($options['response_data_type'])) { $responseDataType = $options['response_data_type']; } else { $responseDataType = $this->getResponseDataType(); } return ResponseConverter::convert($this->lastResponse, $requestFormat, $responseDataType); }