/** * Sends a request to a given path using the passed HTTP Method. * * @param string $httpMethod Either GET, POST, PUT, DELETE or PATCH. * @param string $requestPath The relative path of the request. * @param array $queryParams An associative array with the parameters to * add to the URL. Defaults to array(). * @param string $requestBody The body of the request, used when doing a * POST, PUT or PATCH request. Defaults to "". * * @return array The JSON parsed response if it was success. * @throws OoyalaMethodNotSupportedException if the HTTP method is not * supported. * @throws OoyalaRequestErrorException if there was an error sending the * request. */ public function sendRequest($httpMethod, $requestPath, $queryParams = array(), $requestBody = '') { if (substr($requestPath, 0, 4) != '/v2/') { $requestPath = '/v2/' . $requestPath; } $httpMethod = strtoupper($httpMethod); if (!in_array($httpMethod, self::$supportedMethods)) { throw new OoyalaMethodNotSupportedException('Method not supported ' . $httpMethod); } $params = $this->sanitizeAndAddNeededParams($queryParams); $params['signature'] = $this->generateSignature($httpMethod, $requestPath, array_merge($params, $queryParams), $requestBody); $url = $this->buildURL($httpMethod, $requestPath, $params); $response = $this->httpRequest->execute($httpMethod, $url, array('payload' => $requestBody)); return json_decode($response['body']); }
public function testWithOverridingOptions() { $ooyalaHttpRequest = new OoyalaHttpRequest(); $response = $ooyalaHttpRequest->execute('get', 'http://127.0.0.1', array('payload' => 'payload', 'contentType' => $this->contentType)); $this->assertEquals(200, $response['status']); }