public function testGetResponse() { $config = new CloseIoConfig(); $config->setApiKey('testkey'); $closeIoApiWrapper = new CloseIoApiWrapper($config); $curl = new Curl(); $request = new CloseIoRequest($closeIoApiWrapper->getApiHandler()); $request->setUrl('www.google.com'); $request->setMethod(Curl::METHOD_GET); $response = $curl->getResponse($request); $this->assertEquals($response->getReturnCode(), '200'); $this->assertNotEmpty($response->getRawData()); $this->assertFalse($response->hasErrors()); }
/** * @param $jsonString * @param $expected * @dataProvider jsonStringProvider * @throws \LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException */ public function testSetData($jsonString, $expected) { $closeIoConfig = new CloseIoConfig(); $closeIoConfig->setApiKey('testapikey'); $closeIoApiHandler = new ApiHandler($closeIoConfig); $request = new CloseIoRequest($closeIoApiHandler); if ($expected === false) { $this->setExpectedException('LooplineSystems\\CloseIoApiWrapper\\Library\\Exception\\JsonDecodingException'); $request->setData($jsonString); } else { $request->setData($jsonString); $this->assertNotEmpty($request->getData()); } }
/** * @param mixed $data * @param bool $expected * @param string $expectedData * * @dataProvider jsonStringProvider * @throws \LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException */ public function testSetData($data, $expected, $expectedData = null) { $closeIoConfig = new CloseIoConfig(); $closeIoConfig->setApiKey('testapikey'); $closeIoApiHandler = new ApiHandler($closeIoConfig); $request = new CloseIoRequest($closeIoApiHandler); if ($expected === false) { $this->setExpectedException(InvalidParamException::class); $request->setData($data); } else { $request->setData($data); $this->assertEquals($expectedData, $request->getData()); } }
/** * @param CloseIoRequest $request * @return CloseIoResponse * @throws BadApiRequestException * @throws UrlNotSetException */ public function getResponse(CloseIoRequest $request) { if ($request->getUrl() == null) { throw new UrlNotSetException(); } $curlHandler = $this->init($request); $this->finalize($curlHandler, $request); /** @var CloseIoResponse $response */ $response = $this->execute($curlHandler); if ($response->hasErrors()) { throw new BadApiRequestException($response->getErrors()); } else { return $response; } }
/** * @return string */ protected function getApiKey() { return $this->apiRequest->getApiKey(); }