示例#1
1
 /**
  * Creates a guzzle service client
  * @return \Guzzle\Http\Client the guzzle client
  */
 protected function createGuzzle()
 {
     $guzzle = new \Guzzle\Http\Client();
     $connectionConfig = $this->getClient()->getConnectionConfig();
     $guzzle->setBaseUrl('http://' . $connectionConfig['host'] . ':1' . $connectionConfig['port'] . '/');
     $authPlugin = new CurlAuthPlugin($connectionConfig['user'], $connectionConfig['password']);
     $guzzle->addSubscriber($authPlugin);
     return $guzzle;
 }
示例#2
0
 public static function getMockResponseClient($responseCode, $fixtureFile)
 {
     $client = new \Guzzle\Http\Client();
     $plugin = new \Guzzle\Plugin\Mock\MockPlugin();
     $mockResponse = SpecHelper::getMockResponseFromFixture($responseCode, $fixtureFile);
     $plugin->addResponse($mockResponse);
     $client->addSubscriber($plugin);
     return $client;
 }
 /**
  * 
  * @return \Guzzle\Http\Message\Request $request
  */
 public function getBaseRequest()
 {
     if (is_null($this->baseRequest)) {
         $client = new \Guzzle\Http\Client();
         $client->addSubscriber(new \Guzzle\Plugin\History\HistoryPlugin());
         $this->baseRequest = $client->get();
     }
     return $this->baseRequest;
 }
 /**
  * @return \Guzzle\Http\Client
  */
 protected function buildHttpMockClient($body)
 {
     $plugin = new \Guzzle\Plugin\Mock\MockPlugin();
     $response = new \Guzzle\Http\Message\Response(200);
     $response->setBody($body);
     $plugin->addResponse($response);
     $mockedClient = new \Guzzle\Http\Client();
     $mockedClient->addSubscriber($plugin);
     return $mockedClient;
 }
 /**
  * Test a count request that cannot be satisfied with only the first page
  * of results.
  */
 public function testMultiPageCount()
 {
     $responses = array(MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_0'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_1'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_2'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_3'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_4'), MockPlugin::getMockFile(TEST_RESOURCE_PATH . '/http/drupal_org_major_bugs_5'));
     $mockPlugin = new MockPlugin($responses);
     $client = new \Guzzle\Http\Client();
     $client->addSubscriber($mockPlugin);
     $issueCounter = new DrupalIssueCount($client);
     $issueCount = $issueCounter->getCounts(array('status' => array(1, 13, 8, 14, 15, 4)), array('major_bugs' => array('priorities' => array(300), 'categories' => array(1))));
     $this->assertEquals(271, $issueCount['major_bugs']);
 }
 private function createPackagistClient($data, $status = 200)
 {
     $packagistResponse = new \Guzzle\Http\Message\Response($status);
     $packagistResponse->setBody($data);
     $plugin = new \Guzzle\Plugin\Mock\MockPlugin();
     $plugin->addResponse($packagistResponse);
     $clientHttp = new \Guzzle\Http\Client();
     $clientHttp->addSubscriber($plugin);
     return new Client($clientHttp);
 }
示例#7
0
 /**
  * Constructor.
  *
  * @param string $backend Backend type, currently 'mysql' or 'redshift' is accepted.
  * @param string $token Storage API token.
  * @param string $runId Storage API run Id.
  * @param string $url
  */
 public function __construct($backend, $token, $runId, $url = 'https://syrup.keboola.com/provisioning')
 {
     $this->setBackend($backend);
     $this->setToken($token);
     $this->setRunId($runId);
     $client = new \Guzzle\Http\Client($url);
     $client->getConfig()->set('curl.options', array(CURLOPT_TIMEOUT => $this->timeout));
     $maintenanceBackoff = new BackoffPlugin(new TruncatedBackoffStrategy(10, new MaintenanceBackoffStrategy(array(503), new CurlBackoffStrategy(CurlBackoffStrategy::getDefaultFailureCodes(), new ExponentialBackoffStrategy()))));
     $client->addSubscriber($maintenanceBackoff);
     $this->client = $client;
 }
 public function setUp()
 {
     // see the config_test.yml, there's a parameters in order to not stream the output using FakeImageCreator.
     $data = '{"package":{"name":"pugx\\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","time":"2013-05-24T14:45:06+00:00","maintainers":[{"name":"liuggio","email":"*****@*****.**"}],"versions":{"dev-master":{"name":"pugx\\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","keywords":[],"homepage":"","version":"dev-master","version_normalized":"9999999-dev","license":[],"authors":[],"source":{"type":"git","url":"https:\\/\\/github.com\\/PUGX\\/badge-poser.git","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e"},"dist":{"type":"zip","url":"https:\\/\\/api.github.com\\/repos\\/PUGX\\/badge-poser\\/zipball\\/024df1d420cd715aea3400bfea9b87ed0f3bb47e","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e","shasum":""},"type":"library","time":"2013-05-24T19:19:25+00:00","autoload":{"psr-0":{"":"src\\/"}},"extra":{"symfony-app-dir":"app","symfony-web-dir":"web","branch-alias":{"dev-master":"0.1-dev"}},"require":{"php":">=5.3.3","symfony\\/symfony":"2.2.*","doctrine\\/orm":">=2.2,<3.0,>=2.2.3","doctrine\\/doctrine-bundle":"1.2.*","twig\\/extensions":"1.0.*","symfony\\/assetic-bundle":"2.1.*","symfony\\/swiftmailer-bundle":"2.2.*","symfony\\/monolog-bundle":"2.2.*","sensio\\/distribution-bundle":"2.2.*","sensio\\/framework-extra-bundle":"2.2.*","sensio\\/generator-bundle":"2.2.*","jms\\/security-extra-bundle":"1.4.*","jms\\/di-extra-bundle":"1.3.*","knplabs\\/packagist-api":"dev-master"},"require-dev":{"guzzle\\/plugin-mock":"*"}},"dev-develop":{"name":"pugx\\/badge-poser","description":"add badges on your readme, such as downloads number or latest version.","keywords":[],"homepage":"","version":"dev-develop","version_normalized":"dev-develop","license":[],"authors":[],"source":{"type":"git","url":"https:\\/\\/github.com\\/PUGX\\/badge-poser.git","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e"},"dist":{"type":"zip","url":"https:\\/\\/api.github.com\\/repos\\/PUGX\\/badge-poser\\/zipball\\/024df1d420cd715aea3400bfea9b87ed0f3bb47e","reference":"024df1d420cd715aea3400bfea9b87ed0f3bb47e","shasum":""},"type":"library","time":"2013-05-24T19:19:25+00:00","autoload":{"psr-0":{"":"src\\/"}},"extra":{"symfony-app-dir":"app","symfony-web-dir":"web","branch-alias":{"dev-master":"0.1-dev"}},"require":{"php":">=5.3.3","symfony\\/symfony":"2.2.*","doctrine\\/orm":">=2.2,<3.0,>=2.2.3","doctrine\\/doctrine-bundle":"1.2.*","twig\\/extensions":"1.0.*","symfony\\/assetic-bundle":"2.1.*","symfony\\/swiftmailer-bundle":"2.2.*","symfony\\/monolog-bundle":"2.2.*","sensio\\/distribution-bundle":"2.2.*","sensio\\/framework-extra-bundle":"2.2.*","sensio\\/generator-bundle":"2.2.*","jms\\/security-extra-bundle":"1.4.*","jms\\/di-extra-bundle":"1.3.*","knplabs\\/packagist-api":"dev-master"},"require-dev":{"guzzle\\/plugin-mock":"*"}}},"type":"library","repository":"https:\\/\\/github.com\\/PUGX\\/badge-poser","downloads":{"total":99,"monthly":12,"daily":9},"favers":9}}';
     $packagistResponse = new \Guzzle\Http\Message\Response(200);
     $packagistResponse->setBody($data);
     $plugin = new \Guzzle\Plugin\Mock\MockPlugin();
     $plugin->addResponse($packagistResponse);
     $clientHttp = new \Guzzle\Http\Client();
     $clientHttp->addSubscriber($plugin);
     $this->packagistClient = new Client($clientHttp);
 }
 /**
  * @test
  */
 public function test()
 {
     $restClient = new \Guzzle\Http\Client('http://api.searchperience.com/');
     $mock = new \Guzzle\Plugin\Mock\MockPlugin();
     $mock->addResponse(new \Guzzle\Http\Message\Response(201, NULL, $this->getFixtureContent('Api/Client/System/Storage/Fixture/StopwordTags.xml')));
     $restClient->addSubscriber($mock);
     $this->stopwordTagBackend->injectRestClient($restClient);
     $synonymTags = $this->stopwordTagBackend->getAll();
     $this->assertEquals(3, $synonymTags->getTotalCount(), 'Could not reconstitute synonym collection');
     $this->assertEquals(3, $synonymTags->getCount(), 'Could not get count from synonyms');
     $secondSynonymTag = $synonymTags->offsetGet(1);
     $this->assertSame("de", $secondSynonymTag->getTagName(), 'Could not restore synonym tag');
 }
 /**
  *
  * @test
  */
 public function canPostDocument()
 {
     $this->urlQueueItemBackend = $this->getMock('\\Searchperience\\Api\\Client\\System\\Storage\\RestUrlQueueItemBackend', array('executePostRequest'));
     $this->urlQueueItemBackend->injectDateTimeService(new \Searchperience\Api\Client\System\DateTime\DateTimeService());
     $restClient = new \Guzzle\Http\Client('http://api.searchperience.com/');
     $mock = new \Guzzle\Plugin\Mock\MockPlugin();
     $mock->addResponse(new \Guzzle\Http\Message\Response(201));
     $restClient->addSubscriber($mock);
     $this->urlQueueItemBackend->injectRestClient($restClient);
     $expectsArgumentsArray = array('deleted' => 0, 'documentId' => '111', 'priority' => 3, 'url' => 'http://aoe.com');
     $this->urlQueueItemBackend->expects($this->once())->method('executePostRequest')->with($expectsArgumentsArray)->will($this->returnValue($this->getMock('\\Guzzle\\Http\\Message\\Response', array(), array(), '', false)));
     $this->urlQueueItemBackend->post($this->getTestUrlQueueItem());
 }
 public function testExcludeSourceUrlFromHistoryComparison()
 {
     $httpClient = new \Guzzle\Http\Client();
     $mockPlugin = new \Guzzle\Plugin\Mock\MockPlugin();
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/'));
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/2/'));
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/3/'));
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/4/'));
     $mockPlugin->addResponse(\Guzzle\Http\Message\Response::fromMessage('HTTP/1.1 301' . "\n" . 'Location: http://example.com/5/'));
     $httpClient->addSubscriber($mockPlugin);
     $detector = new \webignition\HttpRedirectLoopDetector\HttpRedirectLoopDetector();
     $detector->setHttpClient($httpClient);
     $detector->setUrl('https://example.com/');
     $this->assertFalse($detector->test());
 }
 /**
  * @test
  */
 public function canBuildUrlQueueItemFromSingleXMLResponse()
 {
     $restClient = new \Guzzle\Http\Client('http://api.searchperience.com/');
     $mock = new \Guzzle\Plugin\Mock\MockPlugin();
     $mock->addResponse(new \Guzzle\Http\Message\Response(201, NULL, $this->getFixtureContent('Api/Client/System/Storage/Fixture/UrlqueueStatus.xml')));
     $restClient->addSubscriber($mock);
     $this->urlQueueStatusBackend->injectRestClient($restClient);
     /** @var $urlQueueItem \Searchperience\Api\Client\Domain\UrlQueueItem\UrlQueueStatus */
     $urlQueueStatus = $this->urlQueueStatusBackend->get();
     $this->assertEquals(4, $urlQueueStatus->getErrorCount(), 'Could not reconstitude the error count from the response xml');
     $this->assertEquals(5, $urlQueueStatus->getAllCount(), 'Could not reconstitude the error count from the response xml');
     $this->assertEquals(3, $urlQueueStatus->getWaitingCount(), 'Could not reconstitude the error count from the response xml');
     $this->assertEquals(2, $urlQueueStatus->getProcessingCount(), 'Could not reconstitude the error count from the response xml');
     $this->assertEquals(2, $urlQueueStatus->getDeletedCount(), 'Could not reconstitude the error count from the response xml');
 }
 /**
  * @test
  */
 public function canDeleteStopword()
 {
     //$this->markTestIncomplete('Process error');
     $this->stopwordBackend = $this->getMock('\\Searchperience\\Api\\Client\\System\\Storage\\RestStopwordBackend', array('deleteByWord'));
     $this->stopwordBackend->injectDateTimeService(new \Searchperience\Api\Client\System\DateTime\DateTimeService());
     $restClient = new \Guzzle\Http\Client('http://api.searchperience.com/');
     $mock = new \Guzzle\Plugin\Mock\MockPlugin();
     $mock->addResponse(new \Guzzle\Http\Message\Response(201));
     $restClient->addSubscriber($mock);
     $this->stopwordBackend->injectRestClient($restClient);
     $this->stopwordBackend->expects($this->once())->method('deleteByWord')->with('one', 'foo')->will($this->returnValue($this->getMock('\\Guzzle\\Http\\Message\\Response', array(), array(), '', false)));
     $stopword = new Stopword();
     $stopword->setWord('foo');
     $stopword->setTagName('one');
     $this->stopwordBackend->delete('one', $stopword);
 }
 /**
  * @test
  */
 public function canGetAllArtifactType()
 {
     $restClient = new \Guzzle\Http\Client('http://api.searchperience.me/qvc/');
     $mock = new \Guzzle\Plugin\Mock\MockPlugin();
     $mock->addResponse(new \Guzzle\Http\Message\Response(201, NULL, $this->getFixtureContent('Api/Client/System/Storage/Fixture/artifact_types.json')));
     $restClient->addSubscriber($mock);
     $this->artifactTypeBackend->injectRestClient($restClient);
     $expectedArtifactTypeCollection = new ArtifactTypeCollection();
     $artifactType1 = new ArtifactType();
     $artifactType1->setName("topseller");
     $expectedArtifactTypeCollection->append($artifactType1);
     $artifactType2 = new ArtifactType();
     $artifactType2->setName("recommendation");
     $expectedArtifactTypeCollection->append($artifactType2);
     $actualArtifactTypeCollection = $this->artifactTypeBackend->getAll();
     $this->assertEquals($expectedArtifactTypeCollection, $actualArtifactTypeCollection);
 }
 /**
  * @test
  */
 public function canGetOneArtifact()
 {
     $restClient = new \Guzzle\Http\Client('http://api.searchperience.me/qvc/');
     $mock = new \Guzzle\Plugin\Mock\MockPlugin();
     $mock->addResponse(new \Guzzle\Http\Message\Response(201, NULL, $this->getFixtureContent('Api/Client/System/Storage/Fixture/topseller_artifact.json')));
     $restClient->addSubscriber($mock);
     $this->artifactBackend->injectRestClient($restClient);
     $expectedArtifactCollection = new ArtifactCollection();
     $expectedArtifact = new TopsellerArtifact();
     $expectedArtifact->setData(array("2121121", "2121"));
     $expectedArtifactCollection->append($expectedArtifact);
     $genericArtifact = new GenericArtifact();
     $genericArtifact->setId("1");
     $genericArtifact->setTypeName("topseller");
     $actualArtifactCollection = $this->artifactBackend->getOne($genericArtifact);
     $this->assertEquals($expectedArtifactCollection, $actualArtifactCollection);
 }
 public function doCommand()
 {
     $url = $this->param('baseUrl');
     $opts = $this->param('options');
     $ua = $this->param('userAgent');
     $plugins = $this->param('plugins');
     $client = new \Guzzle\Http\Client($url, $opts);
     if (isset($ua)) {
         $client->setUserAgent($ua);
     }
     if (!empty($plugins)) {
         foreach ($plugins as $plugin) {
             $client->addSubscriber($plugin);
         }
     }
     // XXX: Could add event listeners here, too.
     return $client;
 }
示例#17
0
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app['f1'] = $this->app->share(function ($app) {
         $settings = $app['config']['avr/f1::config'];
         // Get access tokens from F1
         $authenticate = new Authenticate($settings);
         // Create the HTTP Client
         $client = new \Guzzle\Http\Client($app['config']['avr/f1::config.baseUrl']);
         // Authenticate with F1
         $oauth = new \Guzzle\Plugin\Oauth\OauthPlugin(array('consumer_key' => $app['config']['avr/f1::config.key'], 'consumer_secret' => $app['config']['avr/f1::config.secret'], 'token' => $authenticate->accessToken['oauth_token'], 'token_secret' => $authenticate->accessToken['oauth_token_secret']));
         // Return authenticated HTTP client
         return $client->addSubscriber($oauth);
     });
     // Create the F1 alias
     $this->app->booting(function () {
         $loader = \Illuminate\Foundation\AliasLoader::getInstance();
         $loader->alias('F1', 'Avr\\F1\\Facade\\F1');
     });
 }
示例#18
0
 /**
  * objet qui fera la passerelle entre l'API et les services web SitecRESA.
  * Il suffit de le construire et de le passer à méthode d'un objet ou d'une Classe héritant de {@see SitecRESA\Datatype\DatatypeAbstract}
  * @param array $config configuration particulière à l'instance.
  * Les configuration permanentes doivent être définies dans le fichier /config.php
  */
 public function __construct($apiConfig)
 {
     if (!isset($apiConfig['url']) || !isset($apiConfig['apiKey']) || !isset($apiConfig['secretKey'])) {
         throw new Exception\Api("You have to give an array with path, url, apiKey and secretKey to create a client");
     }
     $this->sApiKey = $apiConfig['apiKey'];
     $this->sSecretKey = $apiConfig['secretKey'];
     $apiClient = new \Guzzle\Http\Client($apiConfig['url'], array('request.params' => array('cache.override_ttl' => 3600)));
     $canCache = new \Guzzle\Plugin\Cache\CallbackCanCacheStrategy(function ($request) {
         $dateDebut = $request->getQuery()->get('dateDebut');
         $fin = $request->getQuery()->get('dateFin');
         if (!isset($dateDebut) && !isset($fin) && preg_match("%organisme\\/get%", $request->getUrl()) || !isset($dateDebut) && !isset($fin) && preg_match("%produit\\/get%", $request->getUrl()) || !isset($dateDebut) && !isset($fin) && preg_match("%conditionretenue\\/get%", $request->getUrl()) || !isset($dateDebut) && !isset($fin) && preg_match("%equipementscategorieproduit\\/get%", $request->getUrl())) {
             return true;
         }
         return false;
     });
     $cachePlugin = new \Guzzle\Plugin\Cache\CachePlugin(array('storage' => new \Guzzle\Plugin\Cache\DefaultCacheStorage(new \Guzzle\Cache\DoctrineCacheAdapter(new \Doctrine\Common\Cache\FilesystemCache($apiConfig['cache']))), 'can_cache' => $canCache));
     $apiClient->addSubscriber($cachePlugin);
     $this->client = $apiClient;
 }
 /**
  * @test
  */
 public function canGetAllAdminSearchCollection()
 {
     $restClient = new \Guzzle\Http\Client('http://api.searchperience.me/qvc/');
     $mock = new \Guzzle\Plugin\Mock\MockPlugin();
     $mock->addResponse(new \Guzzle\Http\Message\Response(201, NULL, $this->getFixtureContent('Api/Client/System/Storage/Fixture/adminsearch_collection.xml')));
     $restClient->addSubscriber($mock);
     $this->adminSearchBackend->injectRestClient($restClient);
     $expectedAdminSearchCollection = new AdminSearchCollection();
     $expectedAdminSearch1 = new AdminSearch();
     $expectedAdminSearch1->__setProperty("id", "1");
     $expectedAdminSearch1->__setProperty("title", "some endpoint");
     $expectedAdminSearch1->__setProperty("description", "some endpoint");
     $expectedAdminSearch1->__setProperty("url", "http://www.dummy.url/api/");
     $expectedAdminSearchCollection->append($expectedAdminSearch1);
     $expectedAdminSearch2 = new AdminSearch();
     $expectedAdminSearch2->__setProperty("id", "2");
     $expectedAdminSearch2->__setProperty("title", "some endpoint 2");
     $expectedAdminSearch2->__setProperty("description", "some endpoint 2");
     $expectedAdminSearch2->__setProperty("url", "http://www.dummy.url/api/v2");
     $expectedAdminSearchCollection->append($expectedAdminSearch2);
     $actualAdminSearchCollection = $this->adminSearchBackend->getAll();
     $this->assertEquals($expectedAdminSearchCollection, $actualAdminSearchCollection);
 }
示例#20
0
$clientConfig = new \fkooman\OAuth\Client\ClientConfig(array("authorize_endpoint" => "http://localhost/oauth/php-oauth/authorize.php", "client_id" => "php-oauth-client-example", "client_secret" => "f00b4r", "token_endpoint" => "http://localhost/oauth/php-oauth/token.php"));
$tokenStorage = new \fkooman\OAuth\Client\SessionStorage();
$httpClient = new \Guzzle\Http\Client();
$api = new fkooman\OAuth\Client\Api("foo", $clientConfig, $tokenStorage, $httpClient);
$context = new \fkooman\OAuth\Client\Context("*****@*****.**", array("authorizations"));
$accessToken = $api->getAccessToken($context);
if (false === $accessToken) {
    /* no valid access token available, go to authorization server */
    header("HTTP/1.1 302 Found");
    header("Location: " . $api->getAuthorizeUri($context));
    exit;
}
try {
    $client = new \Guzzle\Http\Client();
    $bearerAuth = new \fkooman\Guzzle\Plugin\BearerAuth\BearerAuth($accessToken->getAccessToken());
    $client->addSubscriber($bearerAuth);
    $response = $client->get($apiUri)->send();
    header("Content-Type: application/json");
    echo $response->getBody();
} catch (\fkooman\Guzzle\Plugin\BearerAuth\Exception\BearerErrorResponseException $e) {
    if ("invalid_token" === $e->getBearerReason()) {
        // the token we used was invalid, possibly revoked, we throw it away
        $api->deleteAccessToken($context);
        $api->deleteRefreshToken($context);
        /* no valid access token available, go to authorization server */
        header("HTTP/1.1 302 Found");
        header("Location: " . $api->getAuthorizeUri($context));
        exit;
    }
    throw $e;
} catch (\Exception $e) {
 /**
  * @test
  */
 public function verifyPostCreateNewDocument()
 {
     $restClient = new \Guzzle\Http\Client('http://api.searchperience.com/');
     $mock = new \Guzzle\Plugin\Mock\MockPlugin();
     $mock->addResponse(new \Guzzle\Http\Message\Response(201));
     $restClient->addSubscriber($mock);
     $this->documentBackend->injectRestClient($restClient);
     $statusCode = $this->documentBackend->post($this->getDocument());
     $this->assertEquals($statusCode, 201);
 }
示例#22
0
 /**
  * @return \Guzzle\Http\Client
  */
 public function getHttpClient()
 {
     $httpClient = new \Guzzle\Http\Client();
     if ($this->debug) {
         $logPlugin = new \Guzzle\Plugin\Log\LogPlugin($this->getHttpLogAdapter(), \Guzzle\Log\MessageFormatter::DEBUG_FORMAT);
         $httpClient->addSubscriber($logPlugin);
     }
     return $httpClient;
 }
示例#23
0
 public function getClient($token = null, $tokenSecret = null)
 {
     $token = !is_null($token) ? $token : ($this->oauth_token ? $this->oauth_token : '');
     $tokenSecret = !is_null($tokenSecret) ? $tokenSecret : ($this->oauth_token_secret ? $this->oauth_token_secret : '');
     $oauth = new \Guzzle\Http\Plugin\OauthPlugin(array('consumer_key' => $this->api_key, 'consumer_secret' => $this->secret_key, 'token' => $token, 'token_secret' => $tokenSecret));
     $client = new \Guzzle\Http\Client(SHOPLO_API_URL);
     $client->addSubscriber($oauth);
     return $client;
 }
 public function testScopeResponse()
 {
     $plugin = new \Guzzle\Plugin\Mock\MockPlugin();
     $plugin->addResponse(new \Guzzle\Http\Message\Response(200, null, '{"active": true, "scope": "foo:rw bar:r"}'));
     $client = new \Guzzle\Http\Client("https://auth.example.org/introspect");
     $client->addSubscriber($plugin);
     $rs = new ResourceServer($client);
     $rs->setAuthorizationHeader("Bearer 001");
     $v = $rs->verifyToken();
     $this->assertInstanceOf("fkooman\\OAuth\\ResourceServer\\TokenIntrospection", $v);
 }
 /**
  * @param $customerKey
  * @return \Guzzle\Http\Client
  * @throws Exception\RuntimeException
  */
 protected static function getPreparedGuzzleClient($customerKey)
 {
     $guzzle = new \Guzzle\Http\Client();
     $guzzle->setConfig(array('customerKey' => $customerKey, 'redirect.disable' => true));
     if (self::$HTTP_DEBUG === TRUE) {
         if (class_exists('\\Guzzle\\Plugin\\Log\\LogPlugin')) {
             $guzzle->addSubscriber(\Guzzle\Plugin\Log\LogPlugin::getDebugPlugin());
             return $guzzle;
         } else {
             throw new \Searchperience\Common\Exception\RuntimeException('Please run "composer install --dev" to install "guzzle/plugin-log"');
         }
     }
     return $guzzle;
 }