当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::addSubscriber方法代码示例

本文整理汇总了PHP中Guzzle\Service\Client::addSubscriber方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::addSubscriber方法的具体用法?PHP Client::addSubscriber怎么用?PHP Client::addSubscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Service\Client的用法示例。


在下文中一共展示了Client::addSubscriber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initializeClient

 /**
  * Initializes the HTTP Client
  */
 private function initializeClient()
 {
     $this->client = new GuzzleClient($this->config->getBaseUrl());
     $this->client->setDefaultOption('headers', $this->getHeaders());
     $this->client->getConfig()->set('curl.options', array(CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4));
     if ($this->config->getDebug()) {
         $this->client->addSubscriber(LogPlugin::getDebugPlugin());
     }
 }
开发者ID:opifer,项目名称:smarteventmanager,代码行数:12,代码来源:Client.php

示例2: Client

 function __construct()
 {
     $client = new Client('https://api.twitter.com/1.1/');
     $oauth = new OauthPlugin(['consumer_key' => 'NkGX5YSyTPPz2ONSA6nnTMjEv', 'consumer_secret' => 'stqZsBkUj6qOu1Jokv1vulwToqSd7ce8XqZEV17s6DVT1tqDoc', 'token' => '110823516-PyPFyDZwRZPDkZBdv3MkQfod8N1k6z6IWdYBocBE', 'token_secret' => 'mjrwp48ujjZ90ljLx3p8EVXAF8FrHPgL878UsoHNo51xT']);
     $client->addSubscriber($oauth);
     $this->client = $client;
 }
开发者ID:PuchkaTs,项目名称:ganbaatar,代码行数:7,代码来源:TwitterAPI.php

示例3: register

 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->bind('twitter', function () {
         $client = new Client('https://api.twitter.com/1.1');
         $auth = new OauthPlugin(['consumer_key' => Config::get('twitter.consumer_key'), 'consumer_secret' => Config::get('twitter.consumer_secret'), 'token' => Config::get('twitter.token'), 'token_secret' => Config::get('twitter.token_secret')]);
         $client->addSubscriber($auth);
         return new TwitterAPI($client);
     });
 }
开发者ID:acarist,项目名称:laravel-twitter,代码行数:14,代码来源:TwitterServiceProvider.php

示例4: register

 public function register()
 {
     $this->app->bind('yelp', function () {
         $client = new Client('http://api.yelp.com/v2/');
         $auth = new OauthPlugin(['consumer_key' => Config::get('yelp.consumer_key'), 'consumer_secret' => Config::get('yelp.consumer_secret'), 'token' => Config::get('yelp.token'), 'token_secret' => Config::get('yelp.token_secret')]);
         $client->addSubscriber($auth);
         return new YelpAPI($client);
     });
 }
开发者ID:neostoic,项目名称:sharemeal,代码行数:9,代码来源:YelpServiceProvider.php

示例5: createEchaleGasClient

 public function createEchaleGasClient()
 {
     $client = new Client();
     $client->setDescription(ServiceDescription::factory('config/services/echalegas.json'));
     $logger = new Logger('debug');
     $logger->pushHandler(new StreamHandler('logs/debug.log'));
     $logPlugin = new LogPlugin(new MonologLogAdapter($logger), MessageFormatter::DEBUG_FORMAT);
     $client->addSubscriber($logPlugin);
     return $client;
 }
开发者ID:comphppuebla,项目名称:echale-gas-app,代码行数:10,代码来源:IndexService.php

示例6: getMockedClient

 protected function getMockedClient(Response $response)
 {
     $operation = new Operation(array('httpMethod' => 'GET', 'name' => 'Mock'));
     $service = new ServiceDescription();
     $service->addOperation($operation);
     $plugin = new MockPlugin();
     $plugin->addResponse($response);
     $client = new Client();
     $client->setDescription($service);
     $client->addSubscriber($plugin);
     return $client;
 }
开发者ID:teaandcode,项目名称:behat-guzzle-extension,代码行数:12,代码来源:GuzzleContextSpec.php

示例7: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     \Log::info('Fetch tweets');
     $client = new Client('https://api.twitter.com/1.1/');
     $auth = new Oauth(['consumer_key' => env('TWITTER_CONSUMER_KEY'), 'consumer_secret' => env('TWITTER_CONSUMER_SECRET'), 'token' => env('TWITTER_ACCESS_TOKEN'), 'token_secret' => env('TWITTER_ACCESS_TOKEN_SECRET')]);
     $client->addSubscriber($auth);
     //$response = $client->get('search/tweets.json?q=%23peukpoll&since=' . date('Y-m-d'))->send();
     $response = $client->get('search/tweets.json?q=%23peukpoll')->send();
     $data = $response->json()['statuses'];
     $tweets = array_fetch($response->json()['statuses'], 'text');
     foreach ($tweets as $tweet) {
         $values[] = explode(' ', $tweet);
     }
     for ($i = 0; $i < count($values); $i++) {
         $user = User::where('username', $data[$i]['user']['screen_name'])->first();
         if ($user == null) {
             $user = new User();
             $user->username = $data[$i]['user']['screen_name'];
             $user->save();
         }
         $tweet = Tweet::where('tweet', $data[$i]['id'])->first();
         if ($tweet == null) {
             $tweet = new Tweet();
             $tweet->x = $values[$i][0];
             $tweet->y = $values[$i][2];
             $tweet->score_x = 1;
             $tweet->score_y = 1;
             $tweet->tweet = $data[$i]['id'];
             $tweet->user()->associate($user);
             $tweet->save();
             $numberOfUpcomingTweets = UpcomingTweet::all()->count();
             if ($numberOfUpcomingTweets > 0) {
                 $upcomingTweet = new UpcomingTweet();
                 $upcomingTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 year'));
                 $upcomingTweet->tweet()->associate($tweet);
                 $upcomingTweet->save();
             } else {
                 $upcomingTweet = new UpcomingTweet();
                 $upcomingTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 hour'));
                 $upcomingTweet->tweet()->associate($tweet);
                 $upcomingTweet->save();
             }
         }
     }
 }
开发者ID:kristofsw,项目名称:peukpoll,代码行数:50,代码来源:FetchTweet.php

示例8: compat

 /**
  * PHP 5.3 compatibility services
  *
  * @deprecated
  *
  * @param Application $app
  */
 private function compat(Application $app)
 {
     // Register a Guzzle ServiceBuilder
     $app['guzzle'] = $app->share(function () use($app) {
         if (!isset($app['guzzle.services'])) {
             $builder = new ServiceBuilder(array());
         } else {
             $builder = ServiceBuilder::factory($app['guzzle.services']);
         }
         return $builder;
     });
     // Register a simple Guzzle Client object (requires absolute URLs when guzzle.base_url is unset)
     $app['guzzle.client'] = $app->share(function () use($app) {
         $client = new ServiceClient($app['guzzle.base_url']);
         foreach ($app['guzzle.plugins'] as $plugin) {
             $client->addSubscriber($plugin);
         }
         return $client;
     });
 }
开发者ID:aleksabp,项目名称:bolt,代码行数:27,代码来源:GuzzleServiceProvider.php

示例9: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $repositoryName = $this->parseRepositoryName($input->getOption('repository'));
     $client = new Client($input->getOption('api-url') . '{?access_token}', array('access_token' => $input->getOption('access-token'), 'request.options' => array('Content-Type' => 'application/json')));
     $client->addSubscriber(BackoffPlugin::getExponentialBackoff());
     $postData = $this->generatePostData($input);
     if (!isset($postData['coverage'])) {
         $output->write(sprintf('Notifying that no code coverage data is available for repository "%s" and revision "%s"... ', $repositoryName, $postData['revision']));
     } else {
         $output->write(sprintf('Uploading code coverage for repository "%s" and revision "%s"... ', $repositoryName, $postData['revision']));
     }
     try {
         $client->post('repositories/' . $repositoryName . '/data/code-coverage{?access_token}', null, json_encode($postData))->send();
         $output->writeln('Done');
         return 0;
     } catch (BadResponseException $ex) {
         $output->writeln("<error>Failed</error>");
         if ($ex instanceof ClientErrorResponseException) {
             $output->writeln('<error>' . $ex->getResponse()->getBody(true) . '</error>');
             return 1;
         }
         throw $ex;
     }
 }
开发者ID:startupwrench,项目名称:startupwrench,代码行数:24,代码来源:UploadCommand.php

示例10: testModelListObjectResponse

 /**
  * Test array of models in response defined with wrapper model containing an array property
  * @group mock
  * @depends testClientConstruct
  */
 public function testModelListObjectResponse(Client $client)
 {
     // fake a response with multiple valid objects
     $plugin = new MockPlugin();
     $plugin->addResponse(new Response(200, array(), '{"list":[{"foo":4},{"foo":5},{"foo":6}]}'));
     $client->addSubscriber($plugin);
     $response = $client->testwrapobj();
     // test response is a model
     $this->assertInstanceof('\\Guzzle\\Service\\Resource\\Model', $response);
     // test response has 3 items
     $list = $response->get('list');
     $this->assertCount(3, $list);
 }
开发者ID:rodsouto,项目名称:swizzle,代码行数:18,代码来源:ModelTest.php

示例11: authorizeRemote

 /**
  * Authorize the user on the remote server
  * @param  Input $input
  * @return GuzzleClient
  */
 public function authorizeRemote($input)
 {
     $client = new GuzzleClient($input['remote_url']);
     $client->setSslVerification(FALSE);
     $cookieJar = new ArrayCookieJar();
     // Create a new cookie plugin
     $cookiePlugin = new CookiePlugin($cookieJar);
     // Add the cookie plugin to the client
     $client->addSubscriber($cookiePlugin);
     $post_data = array('username' => $input['username'], 'password' => $input['password'], 'remember' => 'checked', 'api' => true);
     $response = $client->post('login/backend', array(), $post_data)->send();
     $response_json = $response->json();
     if (isset($response_json['error'])) {
         throw new Exception($response_json['error']);
     }
     return $client;
 }
开发者ID:jrafaelca,项目名称:Doptor,代码行数:22,代码来源:Synchronize.php

示例12: logClient

 /**
  * Adds a LogPlugin to a Guzzle service client object
  *
  * This will cause any requests created by the client to log all
  * requests sent and received.
  *
  * @param Guzzle\Service\Client $client The Guzzle service client
  */
 protected function logClient(Client $client)
 {
     $client->addSubscriber(LogPlugin::getDebugPlugin());
 }
开发者ID:dh-open,项目名称:desk-php,代码行数:12,代码来源:SystemTestCase.php

示例13: addSubscriber

 /**
  * Add a guzzle plugin to the client.
  * This is mainly for testing, but also useful for logging, validation, etc.
  *
  * @param mixed $plugin A guzzle plugin
  */
 public function addSubscriber($plugin)
 {
     $this->client->addSubscriber($plugin);
 }
开发者ID:kojiyamauchi,项目名称:WebPayAndPayPalAPISampleInWordPress,代码行数:10,代码来源:WebPay.php

示例14: toggleRateLimitingPlugin

 /**
  * @param Client $client
  * @param $config
  */
 public static function toggleRateLimitingPlugin(Client $client, $config)
 {
     if (array_key_exists('disable_rate_limiting', $config) && $config['disable_rate_limiting']) {
         return;
     }
     $rateFactor = array_key_exists('rate_limit_factor', $config) ? $config['rate_limit_factor'] : null;
     $client->addSubscriber(new RateLimitPlugin($rateFactor));
 }
开发者ID:opdavies,项目名称:nwdrupalwebsite,代码行数:12,代码来源:AbstractMeetupClient.php

示例15: Client

require '../vendor/autoload.php';
use Guzzle\Service\Client;
use Guzzle\Service\Description\ServiceDescription;
use Guzzle\Log\MessageFormatter;
use Guzzle\Log\MonologLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Faker\Factory;
$faker = Factory::create();
$client = new Client();
$client->setDescription(ServiceDescription::factory('../config/config.json'));
$logger = new Logger('debug');
$logger->pushHandler(new StreamHandler('../logs/debug.log'));
$logPlugin = new LogPlugin(new MonologLogAdapter($logger), MessageFormatter::DEBUG_FORMAT);
$client->addSubscriber($logPlugin);
$contact = $client->showContact(['contactId' => 1, 'accept' => 'application/json']);
echo "\nShow contact information {$contact['name']} {$contact['last_name']}\n";
$newContact = ['name' => $faker->firstName, 'lastName' => $faker->lastName];
$contact = $client->newContact(array_merge($newContact, ['accept' => 'application/xml']));
echo <<<MESSAGE

New contact information {$contact['name']} {$contact['last_name']} with ID {$contact['contact_id']}

MESSAGE;
$newName = $faker->firstName;
$contact = $client->editContact(['contactId' => 2, 'name' => $newName, 'accept' => 'application/json']);
echo <<<MESSAGE

Edit name {$newName}. Updated contact information: {$contact['name']} {$contact['last_name']} with ID {$contact['contact_id']}
开发者ID:comphppuebla,项目名称:guzzlesfd,代码行数:30,代码来源:service.php


注:本文中的Guzzle\Service\Client::addSubscriber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。