/** * @test */ public function shouldRenewCacheWhenResourceHasChanged() { $cache = $this->getCacheMock(); $response = new Response(200); $client = $this->getBrowserMock(); $client->expects($this->once())->method('send')->will($this->returnValue($response)); $httpClient = new CachedHttpClient(array('base_url' => ''), $client); $httpClient->setCache($cache); $cache->expects($this->once())->method('set')->with('test', $response); $cache->expects($this->once())->method('getModifiedSince')->with('test')->will($this->returnValue(1256953732)); $httpClient->get('test'); }
/** * {@inheritdoc} * * @return void */ public function initialize() { $httpClient = null; if (!empty($this->_config['useCache'])) { if ($this->_config['useCache'] === true) { $this->_config['useCache'] = 'default'; } $httpClient = new CachedHttpClient(); $httpClient->setCache(new CacheBridge($this->_config['useCache'])); } $this->_client = new Client($httpClient); $this->_authenticate(); }
/** * Register the service provider. * * @return void */ public function register() { $this->package('nwidart/activity'); $this->app->bind('Nwidart\\Activity\\EventFactoryInterface', 'Nwidart\\Activity\\Github\\GithubEventFactory'); $this->app['activity'] = $this->app->share(function ($app) { $driver = $app['config']->get('activity::driver'); $factoryClassName = "Nwidart\\Activity\\{$driver}\\{$driver}EventFactory"; $factory = new $factoryClassName(); $client = new CachedHttpClient(); $client->setCache(new FilesystemCache(app_path() . '/storage/github-api-cache')); $client = new Client($client); $client->authenticate($app['config']->get('activity::github.token'), 'http_token'); return new Activity($factory, $client); }); }
/** * Register the github cached http client class. * * @param \Illuminate\Contracts\Foundation\Application $app * @return void */ protected function registerGithubCachedHttpClient(Application $app) { $app->singleton('blogit.github.cachedHttpClient', function () { $cachedHttpClient = new CachedHttpClient(); $cachedHttpClient->setCache(new FilesystemCache(storage_path() . '/github-api-cache')); return $cachedHttpClient; }); $app->alias('blogit.github.cachedHttpClient', CachedHttpClient::class); }
/** * Get a GitHub client. The GitHub client will be set to cache * responses via transients * * @return Client */ function github_client() { $cached = new CachedHttpClient(); $cached->setCache(new TransientCache()); return new Client($cached); }
/** * GitHub Clientのインスタンスを帰す。 * もし引数で設定されていればauth tokenを設定する。 * * @param InputInterface $input * @return Client */ protected function getGitHubClient(InputInterface $input) { $httpClient = null; if ($input->getOption('with-http-cache')) { $httpClient = new CachedHttpClient(); $httpClient->setCache(new FilesystemCache(__DIR__ . '/cache/github-api-cache')); } $client = new Client($httpClient); $token = $input->getOption('token'); if ($token) { $client->authenticate($token, null, Client::AUTH_URL_TOKEN); } return $client; }