public function fetch() { if ($this->getExtid() < 1 || !$this->getType()) { return FALSE; } $item = $this->getInstanceByAttributes(['extid' => $this->getExtid(), 'type' => $this->getType()]); if ($item !== NULL) { $this->setResponse($item->getResponse()); return; } $app = \Slim\Slim::getInstance(); $client = \Discogs\ClientFactory::factory(['defaults' => ['headers' => ['User-Agent' => $app->config['discogsapi']['useragent']]]]); $getter = 'get' . ucfirst($this->getType()); $response = $client->{$getter}(['id' => $this->getExtid()]); $this->setTstamp(time()); $this->setResponse(serialize($response)); $this->insert(); }
protected function createClient($mock, History $history) { $path = sprintf('%s/../../fixtures/%s', __DIR__, $mock); $client = ClientFactory::factory(); $httpClient = $client->getHttpClient(); $mock = new Mock([$path]); $httpClient->getEmitter()->attach($mock); $httpClient->getEmitter()->attach($history); return $client; }
public function testFactoryWithCustomUserAgent() { $client = ClientFactory::factory(['defaults' => ['headers' => ['User-Agent' => 'test']]]); $default = ['User-Agent' => 'test']; $this->assertSame($default, $client->getHttpClient()->getDefaultOption('headers')); }