コード例 #1
0
 /**
  * Build a new FactoryDriver
  *
  * @param Container $app
  */
 public function __construct(Container $app)
 {
     $this->app = $app;
     $this->client = new \Guzzle\Http\Client();
     $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
     $this->client->addSubscriber($cookiePlugin);
 }
コード例 #2
0
 protected function setUp()
 {
     $this->httpClient = new HttpClient('http://localhost');
     $this->clientMocker = new MockPlugin();
     $this->httpClient->addSubscriber($this->clientMocker);
     $this->engineClient = new EngineClient($this->httpClient, array('collection_name' => 'widgets'));
 }
コード例 #3
0
ファイル: Connection.php プロジェクト: grit45/gumer-psn-php
 /**
  * @param \Guzzle\Http\Client $guzzle
  * @return void
  */
 public function setGuzzle(Client $guzzle)
 {
     $this->guzzle = $guzzle;
     $this->guzzle->setSslVerification(false, false);
     $this->guzzle->setUserAgent('User-Agent: Mozilla/5.0 (Linux; U; Android 4.3; EN; C6502 Build/10.4.1.B.0.101) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 PlayStation App/1.60.5/EN/EN');
     $this->guzzle->addSubscriber(new CookiePlugin(new ArrayCookieJar()));
 }
コード例 #4
0
ファイル: GuzzleHandler.php プロジェクト: BertschiAG/JRA
 /**
  * GuzzleHandler constructor.
  *
  * @param ConfigFacade|ConfigInterface $pConfig
  * @param InternalFactory $pFactory
  */
 public function __construct(ConfigInterface $pConfig, InternalFactory $pFactory)
 {
     $this->_config = $pConfig;
     $this->_factory = $pFactory;
     $this->_client = $this->_factory->getGuzzleFactory()->getHttpClientObject($this->_configurationOptions());
     $this->_client->addSubscriber($this->_factory->getGuzzleFactory()->getCookiePlugin());
 }
コード例 #5
0
 public function setUp()
 {
     // create client
     $this->_client = new \Guzzle\Http\Client('http://www.bing.com/');
     // add request sign plugin
     $this->_client->addSubscriber(new \Sokil\Guzzle\Plugin\RequestSign(array('key' => 'Shared secret key used for generating the HMAC variant of the message digest', 'additionalParams' => array('akey' => 'avalue'))));
 }
コード例 #6
0
 /**
  * 
  * @return \Guzzle\Http\Client
  */
 protected function getHttpClient()
 {
     if (is_null($this->httpClient)) {
         $this->httpClient = new HttpClient();
         $this->httpClient->addSubscriber(new \Guzzle\Plugin\History\HistoryPlugin());
     }
     return $this->httpClient;
 }
コード例 #7
0
 public function __construct()
 {
     $this->guzzleClient = new Client();
     $this->logger = LogFactory::getLogger(get_class($this));
     if (!$this->logger instanceof NullLogger) {
         $logPlugin = new LogPlugin(new GuzzleLogAdapter(), MessageFormatter::DEFAULT_FORMAT);
         $this->guzzleClient->addSubscriber($logPlugin);
     }
 }
コード例 #8
0
 /**
  * @return \Guzzle\Http\Client
  */
 protected function getClient()
 {
     if (is_null($this->client)) {
         $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
         $this->client = new Client($this->parameters['base_url']);
         $this->client->addSubscriber($cookiePlugin);
     }
     return $this->client;
 }
コード例 #9
0
 public function testRegisterPlugin()
 {
     $client = new Client('http://example.com');
     $client->addSubscriber($this->getPlugin());
     $mock = new MockPlugin();
     $mock->addResponse(new Response(200));
     $client->addSubscriber($mock);
     $request = $client->get('/resource/1');
     $request->send();
     $authorization = (string) $request->getHeader('Authorization');
     $this->assertRegExp('@Acquia 1:([a-zA-Z0-9+/]+={0,2})$@', $authorization);
 }
コード例 #10
0
ファイル: Api.php プロジェクト: venkat554/twitter-1
 /**
  * Set the consumer_key and consumer_secret for this instance.
  *
  * @param string $consumer_key The consumer_key of the twitter account.
  * @param string $consumer_secret The consumer_secret for the twitter account.
  * @param string $access_token_key The OAuth access token key value
  * @param string $access_token_secret The OAuth access token's secret
  */
 public function setCredentials($consumer_key, $consumer_secret, $access_token_key = null, $access_token_secret = null)
 {
     $this->setConsumerKey($consumer_key);
     $this->setConsumerSecret($consumer_secret);
     $this->setAccessTokenKey($access_token_key);
     $this->setAccessTokenSecret($access_token_secret);
     $this->oauth_consumer = null;
     if (!is_null($consumer_key) && !is_null($consumer_secret) && !is_null($access_token_key) && !is_null($access_token_secret)) {
         $oauth = new OauthPlugin(array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'token' => $access_token_key, 'token_secret' => $access_token_secret));
         $this->http_client->addSubscriber($oauth);
     }
 }
コード例 #11
0
 /**
  * @param string $token
  * @param string $secret
  * @return Client
  */
 public function getOAuthConnection($token = null, $secret = null)
 {
     $client = new Client('https://api.twitter.com');
     $params = array('consumer_key' => $this->key, 'consumer_secret' => $this->secret);
     if ($token !== null && $secret !== null) {
         $params['token'] = $token;
         $params['token_secret'] = $secret;
     }
     $oauth = new OauthPlugin($params);
     $client->addSubscriber($oauth);
     if (null !== $this->logger) {
         $client->addSubscriber(new LogPlugin(new PsrLogAdapter($this->logger)));
     }
     return $client;
 }
コード例 #12
0
ファイル: Client.php プロジェクト: dialogue1/amity-client
 public static function create($host, $ssl, $clientID, $apiKey)
 {
     $guzzle = new GuzzleHttpClient(($ssl ? 'https' : 'http') . '://' . $host . '/');
     $signer = new RequestSigner($clientID, $apiKey);
     $guzzle->addSubscriber($signer);
     return new static($guzzle);
 }
コード例 #13
0
 public function connect($errors = 0)
 {
     $client = new Client(null);
     if (!file_exists($this->_cookieFile)) {
         file_put_contents($this->_cookieFile, "");
     }
     $cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
     $client->addSubscriber($cookiePlugin);
     $client->setUserAgent('User-Agent', 'Mozilla/5.0 (Linux; U; Android 4.2.2; de-de; GT-I9195 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
     $this->_client = $client;
     try {
         $url = $this->getLoginUrl();
         $this->loginAndGetCode($url);
         $this->enterAnswer();
         $this->gatewayMe();
         $this->auth();
         $this->getSid();
         $this->utasRefreshNucId();
         $this->auth();
         $this->utasAuth();
         $this->utasQuestion();
     } catch (\Exception $e) {
         throw $e;
         // server down, gotta retry
         if ($errors < static::RETRY_ON_SERVER_DOWN && preg_match("/service unavailable/mi", $e->getMessage())) {
             $this->connect(++$errors);
         } else {
             throw new \Exception('Could not connect to the mobile endpoint.');
         }
     }
     return array("nucleusId" => $this->nucId, "userAccounts" => $this->accounts, "sessionId" => $this->sid, "phishingToken" => $this->phishingToken, "platform" => $this->_loginDetails['platform']);
 }
コード例 #14
0
 public function connect($appKey, $appSecret, $accessToken, $tokenSecret)
 {
     try {
         $client = new Client(self::BASE_URL . '/{version}', ['version' => '1.1']);
         $oauth = new OauthPlugin(['consumer_key' => $appKey, 'consumer_secret' => $appSecret, 'token' => $accessToken, 'token_secret' => $tokenSecret]);
         return $client->addSubscriber($oauth);
     } catch (ClientErrorResponseException $e) {
         $req = $e->getRequest();
         $resp = $e->getResponse();
         print_r($resp);
         die('1');
     } catch (ServerErrorResponseException $e) {
         $req = $e->getRequest();
         $resp = $e->getResponse();
         die('2');
     } catch (BadResponseException $e) {
         $req = $e->getRequest();
         $resp = $e->getResponse();
         print_r($resp);
         die('3');
     } catch (Exception $e) {
         echo 'AGH!';
         die('4');
     }
 }
コード例 #15
0
 public function Connect()
 {
     $client = new Client(null);
     if (!file_exists($this->_cookieFile)) {
         file_put_contents($this->_cookieFile, "");
     }
     $cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
     $client->addSubscriber($cookiePlugin);
     $client->setUserAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36");
     $this->_client = $client;
     $login_url = $this->GetMainPage($this->urls['main']);
     $this->Login($login_url);
     $nucleusId = $this->GetNucleusId($this->urls['nucleus']);
     $this->GetShards($nucleusId, $this->urls['shards']);
     $userAccounts = $this->GetUserAccounts($nucleusId, $this->urls['userinfo']);
     $sessionId = $this->GetSessionId($nucleusId, $userAccounts, $this->urls['session']);
     $phishing = $this->Phishing($nucleusId, $sessionId, $this->urls['phishing']);
     if (isset($phishing['debug']) && $phishing['debug'] == "Already answered question.") {
         $phishingToken = $phishing['token'];
     } else {
         $phishingToken = $this->Validate($nucleusId, $sessionId, $this->urls['validate']);
     }
     $this->_loginResponse = array("nucleusId" => $nucleusId, "userAccounts" => $userAccounts, "sessionId" => $sessionId, "phishingToken" => $phishingToken, "platform" => $this->_loginDetails['platform']);
     return $this->_loginResponse;
 }
コード例 #16
0
 public function getPayload($entry, $accessToken, $message, $picture, &$chosenProvider)
 {
     try {
         $provider = craft()->oauth->getProvider('twitter');
         $token = craft()->socialPoster_accounts->getToken('twitter');
         $client = new Client('https://api.twitter.com/1.1');
         $subscriber = $provider->getSubscriber($token);
         $client->addSubscriber($subscriber);
         $request = $client->post('statuses/update.json', null, array('status' => $message));
         $response = $request->send();
         $data = $response->json();
         SocialPosterPlugin::log('Twitter post: ' . print_r($data, true), LogLevel::Info);
         $responseReturn = $this->_returnResponse($response);
         if (isset($data['id'])) {
             return array('success' => true, 'response' => $responseReturn, 'data' => $data);
         } else {
             return array('success' => false, 'response' => $responseReturn, 'data' => $data);
         }
     } catch (ClientErrorResponseException $e) {
         return array('success' => false, 'response' => $this->_returnResponse($e->getResponse(), $e));
     } catch (ServerErrorResponseException $e) {
         return array('success' => false, 'response' => $this->_returnResponse($e->getResponse(), $e));
     } catch (RequestErrorResponseException $e) {
         return array('success' => false, 'response' => $this->_returnResponse($e->getResponse(), $e));
     } catch (CurlException $e) {
         return array('success' => false, 'response' => $this->_returnResponse($e->getMessage(), $e));
     }
 }
コード例 #17
0
ファイル: Client.php プロジェクト: seofood/amazon-revenue
 /**
  * @param string $username
  * @param string $password
  * @param string $country
  *
  * @throws Exception
  */
 public function __construct($username, $password, $country = 'DE')
 {
     $this->_username = $username;
     $this->_password = $password;
     $this->_country = $country;
     if (!array_key_exists($country, $this->_hostNames)) {
         throw new Exception('No hostname for the given country available.');
     }
     $this->_host = $this->_hostNames[$country];
     $this->_client = new HttpClient('https://' . $this->_host . '/');
     $this->_client->setSslVerification(false, false, 0);
     $this->_client->setUserAgent('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17', true);
     $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
     $this->_client->addSubscriber($cookiePlugin);
     $this->_login();
 }
コード例 #18
0
 /**
  * @param HttpClient $client
  */
 public function setHttpClient(HttpClient $client)
 {
     if (!empty($this->credential)) {
         $client->addSubscriber(new OauthPlugin(array('consumer_key' => $this->credential->getConsumerKey(), 'consumer_secret' => $this->credential->getConsumerSecret())));
     }
     $this->httpClient = $client;
 }
コード例 #19
0
 public function setUp()
 {
     parent::setUp();
     $apiLoginId = getenv('AUTHORIZE_NET_API_LOGIN_ID');
     $transactionKey = getenv('AUTHORIZE_NET_TRANSACTION_KEY');
     //        //todo: Remove this before final commit
     $apiLoginId = '3wM8sJ9qR';
     $transactionKey = '3K2e3z44EKz3g326';
     if ($apiLoginId && $transactionKey) {
         $logger = new \Monolog\Logger('authorizenet_cim');
         $logger->pushHandler(new \Monolog\Handler\StreamHandler('/var/log/php/debug.log', \Monolog\Logger::DEBUG));
         $logger->pushHandler(new \Monolog\Handler\FirePHPHandler());
         $adapter = new PsrLogAdapter($logger);
         $logPlugin = new LogPlugin($adapter, MessageFormatter::DEBUG_FORMAT);
         $client = new Client();
         $client->addSubscriber($logPlugin);
         $this->gateway = new CIMGateway($client, $this->getHttpRequest());
         $this->gateway->setDeveloperMode(true);
         $this->gateway->setApiLoginId($apiLoginId);
         $this->gateway->setTransactionKey($transactionKey);
     } else {
         // No credentials were found, so skip this test
         $this->markTestSkipped();
     }
 }
コード例 #20
0
 /**
  * @param array $input
  * @param bool $expectSuccess
  *
  * @covers GeoPal\Open311\Clients\TorontoClient::createServiceRequest
  * @dataProvider providerTestCreateServiceRequest
  */
 public function testCreateServiceRequest($input, $expectSuccess)
 {
     $stubResponse = array(array(ServiceRequest::FIELD_SERVICE_REQUEST_ID => 'stub_id'));
     /**
      * Create and set up fake guzzle client
      */
     $response = is_null($stubResponse) ? new Response(200) : new Response(200, null, json_encode($stubResponse));
     $mockPlugin = new MockPlugin();
     $mockPlugin->addResponse($response);
     $stubGuzzleClient = new Client();
     $stubGuzzleClient->addSubscriber($mockPlugin);
     /**
      * Create test client
      */
     $client = new TorontoClient('testing', $stubGuzzleClient);
     /**
      * Check call result
      */
     if ($expectSuccess) {
         $this->assertInstanceOf('\\GeoPal\\Open311\\ServiceRequestResponse', $client->createServiceRequest($input[ServiceRequest::FIELD_SERVICE_CODE], $input[ServiceRequest::FIELD_LATITUDE], $input[ServiceRequest::FIELD_LONGITUDE], $input[ServiceRequest::FIELD_ADDRESS_STRING], $input[ServiceRequest::FIELD_ADDRESS_ID], $input[ServiceRequest::FIELD_EMAIL], $input[ServiceRequest::FIELD_DEVICE_ID], $input[ServiceRequest::FIELD_ACCOUNT_ID], $input[ServiceRequest::FIELD_FIRST_NAME], $input[ServiceRequest::FIELD_LAST_NAME], $input[ServiceRequest::FIELD_PHONE], $input[ServiceRequest::FIELD_DESCRIPTION], $input[ServiceRequest::FIELD_MEDIA_URL]));
     } else {
         $result = false;
         $exceptionThrown = false;
         try {
             // Throw an exception or change $result from false to null
             $result = $client->createServiceRequest($input[ServiceRequest::FIELD_SERVICE_CODE], $input[ServiceRequest::FIELD_LATITUDE], $input[ServiceRequest::FIELD_LONGITUDE], $input[ServiceRequest::FIELD_ADDRESS_STRING], $input[ServiceRequest::FIELD_EMAIL], $input[ServiceRequest::FIELD_DEVICE_ID], $input[ServiceRequest::FIELD_ACCOUNT_ID], $input[ServiceRequest::FIELD_FIRST_NAME], $input[ServiceRequest::FIELD_LAST_NAME], $input[ServiceRequest::FIELD_PHONE], $input[ServiceRequest::FIELD_DESCRIPTION], $input[ServiceRequest::FIELD_MEDIA_URL]);
         } catch (Open311Exception $e) {
             $exceptionThrown = true;
         }
         $this->assertTrue($exceptionThrown || is_null($result));
     }
 }
コード例 #21
0
 public function setUp()
 {
     $client = new Client();
     $this->mockPlugin = new MockPlugin();
     $client->addSubscriber($this->mockPlugin);
     $this->geolocator = new NominatimGeolocator($client);
 }
コード例 #22
0
 function it_set_up_a_client_oauth_plugin_subscriber(Client $client, RequestBuilder $builder, $factory, $plugin)
 {
     $builder->getCredentials()->willReturn(['some builder credentials']);
     $factory->create(['some builder credentials'])->shouldBeCalled()->willReturn($plugin);
     $client->addSubscriber($plugin)->shouldBeCalled();
     $this->secureClient($client, $builder);
 }
コード例 #23
0
ファイル: HtmlRetriever.php プロジェクト: unculture/scraper
 /**
  * @return Client
  */
 private function buildClient()
 {
     $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
     $client = new Client();
     $client->addSubscriber($cookiePlugin);
     return $client;
 }
コード例 #24
0
 /**
  *
  * @param array $p
  * @return bool|TokenResponse
  */
 protected function accessTokenRequest(array $p)
 {
     $this->c->setConfig(array(\Guzzle\Http\Client::REQUEST_OPTIONS => array('allow_redirects' => false, 'exceptions' => false, 'verify' => false)));
     if ($this->clientConfig->getCredentialsInRequestBody()) {
         // provide credentials in the POST body
         $p['client_id'] = $this->clientConfig->getClientId();
         $p['client_secret'] = $this->clientConfig->getClientSecret();
     } else {
         // use basic authentication
         $curlAuth = new \Guzzle\Plugin\CurlAuth\CurlAuthPlugin($this->clientConfig->getClientId(), $this->clientConfig->getClientSecret());
         $this->c->addSubscriber($curlAuth);
     }
     try {
         $request = $this->c->post($this->clientConfig->getTokenEndpoint());
         $request->addPostFields($p);
         $request->addHeader('Accept', 'application/json');
         $responseData = $request->send()->json();
         // some servers do not provide token_type, so we allow for setting
         // a default
         // issue: https://github.com/fkooman/php-oauth-client/issues/13
         if (null !== $this->clientConfig->getDefaultTokenType()) {
             if (is_array($responseData) && !isset($responseData['token_type'])) {
                 $responseData['token_type'] = $this->clientConfig->getDefaultTokenType();
             }
         }
         // if the field "expires_in" has the value null, remove it
         // issue: https://github.com/fkooman/php-oauth-client/issues/17
         if ($this->clientConfig->getAllowNullExpiresIn()) {
             if (is_array($responseData) && array_key_exists("expires_in", $responseData)) {
                 if (null === $responseData['expires_in']) {
                     unset($responseData['expires_in']);
                 }
             }
         }
         // if the field "scope" is empty string a default can be set
         // through the client configuration
         // issue: https://github.com/fkooman/php-oauth-client/issues/20
         if (null !== $this->clientConfig->getDefaultServerScope()) {
             if (is_array($responseData) && isset($responseData['scope']) && '' === $responseData['scope']) {
                 $responseData['scope'] = $this->clientConfig->getDefaultServerScope();
             }
         }
         return new TokenResponse($responseData);
     } catch (\Guzzle\Common\Exception\RuntimeException $e) {
         return false;
     }
 }
コード例 #25
0
 protected function setUp()
 {
     $client = new Client();
     $this->mockPlugin = new MockPlugin();
     $client->addSubscriber($this->mockPlugin);
     $this->download = new GuzzleDownloadAdapter($client);
     $this->download->setDirectory(self::$directory);
 }
コード例 #26
0
ファイル: ApiTest.php プロジェクト: sensiolabs/insight
 public function setUp()
 {
     $this->pluginMockResponse = new MockPlugin();
     $client = new Client();
     $client->addSubscriber($this->pluginMockResponse);
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->api = new Api(array('api_token' => 'my-token', 'user_uuid' => 'my-user-uuid'), $client, null, $this->logger);
 }
コード例 #27
0
ファイル: TweetCommand.php プロジェクト: onema/robo-cli
 protected function getClient()
 {
     $client = new Client('https://api.twitter.com/1.1');
     $auth = $this->getAuthentication();
     $oauth = new OauthPlugin($auth);
     $client->addSubscriber($oauth);
     return $client;
 }
 /**
  * Setup function
  * Pass a string to indicate whether to query the sandbox or production endpoints
  *
  * @param string $apistatus
  * @param string $realmId
  * @param AppSol\GFQuickbooksOnline\Includes\QBOAuth $qbOAuth
  * @return void
  **/
 public function setup($apistatus, $realmId, $qbOAuth)
 {
     $this->realmId = $realmId;
     $this->baseUrl = $apistatus == 'production' ? $this->productionBaseUrl : $this->sandboxBaseUrl;
     $this->client = new Client($this->baseUrl);
     $oauth = new OauthPlugin(array('consumer_key' => $qbOAuth->oauthConsumerKey, 'consumer_secret' => $qbOAuth->oauthConsumerSecret, 'token' => $qbOAuth->accessToken, 'token_secret' => $qbOAuth->accessTokenSecret));
     $this->client->addSubscriber($oauth);
 }
コード例 #29
0
 private function getMockClient($statusCode = 200, $content = null)
 {
     $plugin = new MockPlugin();
     $plugin->addResponse(new Response($statusCode, null, $content));
     $client = new Client(null, array('request.options' => array('exceptions' => false)));
     $client->addSubscriber($plugin);
     return $client;
 }
コード例 #30
0
 private function getMockGuzzle3Client($statusCode = 200, $content = null)
 {
     $plugin = new MockPlugin();
     $plugin->addResponse(new Guzzle3Response($statusCode, null, $content));
     $client = new Guzzle3Client();
     $client->addSubscriber($plugin);
     return $client;
 }