本文整理汇总了PHP中Guzzle\Service\Client类的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetch
/**
* Created by PhpStorm.
* User: WhiteBlue
* Date: 15/7/8
* Time: 下午10:11
*/
function fetch()
{
$client = new Client();
$request = new Request('GET', 'http://api.bilibili.cn/index');
$response = $client->send($request, ['timeout' => 2]);
$json = json_decode($response->getBody());
$count = 0;
foreach ($json as $type => $value) {
$sort = Sort::where('type', '=', $type)->first();
if ($sort != null) {
foreach ($value as $id => $content) {
if (is_object($content)) {
if (Save::where('aid', '=', $content->aid)->first() == null) {
$save = new Save();
$save->aid = $content->aid;
$save->title = $content->title;
if (strlen($content->description) > 70) {
$save->content = mb_substr($content->description, 0, 70, 'utf-8') . '....';
} else {
$save->content = $content->description;
}
$save->href = 'http://www.bilibili.com/video/AV' . $content->aid;
$save->img = $content->pic;
$sort->saves()->save($save);
$count++;
$sort->update = date('Y:m:d');
$sort->save();
}
}
}
}
}
event(new UpdateEvent());
return $count;
}
示例2: getClient
protected function getClient()
{
$description = new ServiceDescription(array('operations' => array('test' => array('httpMethod' => 'PUT', 'parameters' => array('ContentMD5' => array(), 'Body' => array('location' => 'body'))))));
$client = new Client();
$client->setDescription($description);
return $client;
}
示例3: setUp
public function setUp()
{
$this->commandFactory = $this->getMock(self::CLASS_FACTORY, array('factory'));
$guzzleClient = new Client();
$guzzleClient->setCommandFactory($this->commandFactory);
$this->client = new JanusClient($guzzleClient);
}
示例4: productAction
public function productAction()
{
$client = new Client('http://stroyka.by');
$request = $client->get('/');
$request->send();
$resault = $request->getResponse()->getBody(true);
$crawler = new Crawler();
// $crawler->addHTMLContent($resault);
// $res = $request->getResponse()->getH;
// var_dump($res);exit();
// $text = utf8_decode($resault);
$crawler = new Crawler($resault);
$resault = $crawler->filter('ul.b-categories')->html();
//
//
// $crowler2 = new Crawler($resault);
//
// $resault = $crowler2->filter('span.b-categories__name');
//
// $nodeValues = $crawler->filter('span.b-categories__name')->each(function (Crawler $node, $i) {
// return utf8_decode($node->text());
// });
// var_dump(mb_detect_encoding($nodeValues[0]));exit();
// foreach($nodeValues as $nv) {
// $category = new Category();
// $category->setName($nv);
// $this->getDoctrine()->getManager()->persist($category);
// }
// $this->getDoctrine()->getManager()->flush();
// var_dump($nodeValues);
// var_dump($resault);
// exit;
return $this->render('AcmeAppBundle:Default:product.html.twig', array('result' => $resault));
}
示例5: getClient
protected function getClient()
{
$service = ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'TestData' . DIRECTORY_SEPARATOR . 'test_service.xml');
$client = new Client('http://www.google.com/');
$client->setDescription($service);
return $client;
}
示例6: resolve
public function resolve()
{
$deps = array($this->package);
$resolved = array();
$guzzle = new Client('http://packagist.org');
while (count($deps) > 0) {
$package = $this->rename(array_pop($deps));
if (!$package) {
continue;
}
try {
$response = $guzzle->get('/packages/' . $package . '.json')->send()->getBody(true);
} catch (\Exception $e) {
continue;
}
$package = json_decode($response);
if (!is_null($package)) {
foreach ($package->package->versions as $version) {
if (!isset($version->require)) {
continue;
}
foreach ($version->require as $dependency => $version) {
if (!in_array($dependency, $resolved) && !in_array($dependency, $deps)) {
$deps[] = $dependency;
$deps = array_unique($deps);
}
}
}
echo " * Package {$package->package->name} was added\n";
$resolved[] = $package->package->name;
}
}
return $resolved;
}
示例7: 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;
}
示例8: getDigest
/**
* Get digest credits
*/
public function getDigest($date)
{
$client = new Client('https://graph.facebook.com/oauth/access_token?client_id={company_id}&client_secret={company_secret}&grant_type=client_credentials', array('company_id' => $this->companyId, 'company_secret' => $this->companySecret));
$response = $client->get()->send();
if (200 !== $response->getStatusCode()) {
throw new Exception("Can't get access token using passed company id and secret");
}
$token = $response->getBody();
parse_str($token);
$dailyDigestUrl = "https://paymentreports.facebook.com/{company_id}/report?date={date}&type=digest&access_token={access_token}";
$client = new Client($dailyDigestUrl, array('company_id' => $this->companyId, 'access_token' => $access_token, 'date' => $date));
$response = $client->get()->send();
if (200 !== $response->getStatusCode()) {
throw new \Exception("Can't download daily detail report");
}
$cacheDir = $this->container->get('kernel')->getRootDir() . '/cache';
$extractDir = $cacheDir . '/tmp-facebook-report';
@mkdir($extractDir, 0755, true);
$zipFileName = tempnam($extractDir, "fb_detail_report") . ".zip";
file_put_contents($zipFileName, $response->getBody());
$zip = new \ZipArchive();
if ($zip->open($zipFileName) === TRUE) {
$zip->extractTo($extractDir);
$zip->close();
@unlink($zipFileName);
$finder = new Finder();
$finder->files()->name($this->companyId . '_digest_*.csv')->in($extractDir);
foreach ($finder as $file) {
$stop = true;
$header = array();
$rows = array();
foreach (file($file->getRealpath()) as $line) {
if (preg_match('/^SH.*credits_digest$/', $line)) {
$stop = false;
continue;
}
if (preg_match('/^SF/', $line)) {
$stop = true;
continue;
}
if (preg_match('/^CH/', $line)) {
$line = preg_replace('/^CH,/', '', $line);
$header = str_getcsv($line);
continue;
}
if (!$stop) {
$line = preg_replace('/^SD,/', '', $line);
$columns = str_getcsv($line);
$row = array_combine($header, $columns);
$rows[] = $row;
}
}
@unlink($file->getRealpath());
return $rows;
}
} else {
throw new Exception("Can't unzip facebook report archive");
}
}
示例9: postJSON
private function postJSON($url, $headers, $payload)
{
$client = new Client();
$request = $client->createRequest('POST', $url, ["Content-Type" => "application/json;charset=UTF-8", "Accept" => "application/json"] + $headers, $payload);
$response = $request->send();
$json = $response->getBody(true);
return json_decode($json);
}
示例10: __construct
/**
* Initializes the BeHat context for every scenario
*
* @param array $parameters Context parameters defined in behat.yml (default.context.parameters...)
*/
public function __construct(array $parameters)
{
$this->client = new \Guzzle\Service\Client();
$this->client->setDefaultOption('exceptions', false);
// disable exceptions: we want to test error responses
self::$parameters = $parameters;
$this->restObj = new \stdClass();
}
示例11: __construct
/**
* Initializes initializer
*
* @param Client $client
* @param array $parameters
*/
public function __construct(Client $client, array $parameters)
{
$this->client = $client;
$this->parameters = $parameters;
if (!empty($parameters['service_descriptions'])) {
$this->client->setDescription(ServiceDescription::factory($parameters['service_descriptions']));
}
}
示例12: getData
protected function getData()
{
$client = new Client();
$response = $client->get(static::DATA_SOURCE_URL)->send();
if (200 !== $response->getStatusCode()) {
throw new RemoteServerProblem('Data is not available');
}
return $this->convertData(json_decode($response->getBody(), true));
}
示例13: 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);
});
}
示例14: testGetPetById
/**
* Tests a simple model
* @depends testClientConstruct
* @depends testFindPetsByStatus
*/
public function testGetPetById(Client $client, $petId)
{
$petId = 3;
// <- bug in petstore definition disallows pidId>100
$pet = $client->getPetById(compact('petId'));
$this->assertInstanceOf('\\Guzzle\\Service\\Resource\\Model', $pet);
$this->assertEquals($petId, $pet['id']);
$this->assertInternalType('string', $pet['name']);
}
示例15: testAllowsForJsonBasedArrayParamsFunctionalTest
public function testAllowsForJsonBasedArrayParamsFunctionalTest()
{
$description = new ServiceDescription(array('operations' => array('test' => new Operation(array('httpMethod' => 'PUT', 'parameters' => array('data' => array('required' => true, 'filters' => 'json_encode', 'location' => 'body')))))));
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('test', array('data' => array('foo' => 'bar')));
$request = $command->prepare();
$this->assertEquals('{"foo":"bar"}', (string) $request->getBody());
}