本文整理汇总了PHP中Guzzle\Http\ClientInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::get方法的具体用法?PHP ClientInterface::get怎么用?PHP ClientInterface::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
/**
* {@inheritdoc}
*/
public function load(ClassMetadata $metadata, ParserInterface $parser)
{
// Create a request with basic Auth
$request = $this->client->get('repos/' . $this->owner . '/' . $this->repository . '/contents');
try {
// Send the request and get the response.
$response = $request->send();
} catch (ClientErrorResponseException $e) {
$this->handleBadResponseExceptions($e);
}
$files = $response->json();
$batch = array();
foreach ($files as $file) {
$batch[] = $this->client->get('repos/' . $this->owner . '/' . $this->repository . '/contents/' . $file['path']);
}
try {
$responses = $this->client->send($batch);
} catch (MultiTransferException $e) {
$this->handleBadResponseExceptions($e->getFirst());
}
$content = array();
foreach ($responses as $response) {
$file = $response->json();
$decodedContent = base64_decode($file['content']);
$content[] = $parser->parse($metadata, $file['name'], $decodedContent);
}
return $content;
}
示例2: ping
/**
* Perform a ping request
* @return PingResponse
* @throws CommunicationError If there was an error communicating with the endpoint
* @throws InvalidRequestError If the endpoint proclaims the request invalid
*/
public function ping()
{
$request = $this->guzzleClient->get("/v1/ping");
$data = $this->sendRequest($request);
$pingResponse = new PingResponse($this->getLaunchKeyDate($data["launchkey_time"]), $data["key"], $this->getLaunchKeyDate($data["date_stamp"]));
return $pingResponse;
}
示例3: load
/**
* {@inheritdoc}
*/
public function load(ClassMetadata $metadata, ParserInterface $parser)
{
// Create a request with basic Auth
$request = $this->client->get('metadata/dropbox/' . $this->path);
try {
// Send the request and get the response.
$response = $request->send();
} catch (ClientErrorResponseException $e) {
$this->handleBadResponseExceptions($e);
}
$responseBody = $response->json();
$batch = array();
foreach ($responseBody['contents'] as $file) {
$batch[] = $this->client->get('https://api-content.dropbox.com/1/files/dropbox' . $file['path']);
}
try {
$responses = $this->client->send($batch);
} catch (MultiTransferException $e) {
$this->handleBadResponseExceptions($e->getFirst());
}
$content = array();
foreach ($responses as $response) {
$url = parse_url($response->getEffectiveUrl());
$filename = basename($url['path']);
$receivedContent = $response->getBody(true);
$content[] = $parser->parse($metadata, $filename, $receivedContent);
}
return $content;
}
示例4: handleRequest
/**
* Sends the request to given URL and returns JSON response.
*
* @param string
* @return void
*/
public function handleRequest($url)
{
$request = $this->client->get($url);
$json = ['success' => TRUE, 'error' => NULL, 'body' => NULL];
$this->enableCrossDomainRequests();
try {
$result = $request->send(TRUE);
} catch (CurlException $e) {
$json['success'] = FALSE;
$json['error'] = sprintf("Unable to handle request: CURL failed with message '%s'.", $e->getError());
switch ($e->getErrorNo()) {
case CURLE_COULDNT_RESOLVE_HOST:
http_response_code(404);
break;
default:
http_response_code(400);
break;
}
}
if (isset($result)) {
$json['body'] = $result->getBody(TRUE);
}
header('Content-Type: application/json');
echo json_encode($json);
}
示例5: load
/**
* {@inheritdoc}
*/
public function load(ClassMetadata $metadata, ParserInterface $parser, $retries = 0)
{
try {
// Send the request and get the response.
$response = $this->client->get('files/' . $this->folder . '/children')->send();
} catch (ClientErrorResponseException $e) {
if ($this->client->getDefaultOption('request.options/headers/Authorization') && $retries < 1) {
$this->refreshToken();
$retries++;
return $this->load($metadata, $parser, $retries);
}
$this->handleBadResponseExceptions($e);
}
$json = $response->json();
$files = $json['items'];
$batch = array();
foreach ($files as $file) {
$batch[] = $this->client->get('files/' . $file['id']);
}
try {
$responses = $this->client->send($batch);
} catch (MultiTransferException $e) {
$this->handleBadResponseExceptions($e->getFirst());
}
$content = array();
foreach ($responses as $response) {
$file = $response->json();
$response = $this->client->get($file['downloadUrl'])->send();
$downloadedContent = $response->getBody(true);
$content[] = $parser->parse($metadata, $file['originalFilename'], $downloadedContent);
}
return $content;
}
示例6: loadWsdl
/**
* Load remote WSDL to local cache.
*
* @param string $url
* @return string
*/
public function loadWsdl($url)
{
$response = $this->guzzleClient->get($url)->send();
$cacheFilePath = $this->getCachedWsdlPath($url);
$this->fs->dumpFile($cacheFilePath, $response->getBody(true));
return $cacheFilePath;
}
示例7: getMessage
/**
* {@inheritdoc}
*/
public function getMessage($id)
{
try {
return $this->guzzle->get('/messages/' . $id . '.json')->send()->json();
} catch (GuzzleException $e) {
throw new ConnectionException("", 0, $e);
}
}
示例8: loadWsdl
/**
* Load remote WSDL to local cache.
*
* @param string $url
* @return string
*/
public function loadWsdl($url)
{
$clientOptions = ['verify' => empty($this->bundleConfig['sync_settings']['skip_ssl_verification'])];
$response = $this->guzzleClient->get($url, null, $clientOptions)->send();
$cacheFilePath = $this->getCachedWsdlPath($url);
$this->fs->dumpFile($cacheFilePath, $response->getBody(true));
return $cacheFilePath;
}
示例9: track
public function track($trackingNumber)
{
try {
$response = $this->httpClient->get($this->url, array(), array('query' => array('RQXML' => $this->createRequestXml($trackingNumber))))->send();
} catch (HttpException $e) {
throw Exception::createFromHttpException($e);
}
return $this->parse($response->getBody(true));
}
示例10: get
/**
* {@inheritdoc}
*/
public function get($url)
{
try {
$this->response = $this->client->get($url)->send();
} catch (RequestException $e) {
$this->response = $e->getResponse();
$this->handleError();
}
return $this->response->getBody(true);
}
示例11: getByAccessToken
/**
* @param string $access_token
* @return User
*/
public function getByAccessToken($access_token)
{
$me = $this->http->get('https://graph.facebook.com/me?access_token=' . $access_token)->send()->json();
$data = $this->data_provider->findUserByFacebookId($me['id']);
$user = null;
if ($data != null) {
$user = $this->createUser($data);
}
return $user;
}
示例12: createHttpRequest
/**
*
* @param \Wehup\AMI\Request\RequestInterface $request
* @return \Guzzle\Http\Message\Response
*/
protected function createHttpRequest(Request\RequestInterface $request)
{
$httpRequest = $this->httpClient->get('rawman');
$httpRequest->addCookie('mansession_id', $this->cookie);
foreach ($request->getParams() as $key => $value) {
$httpRequest->getQuery()->set($key, $value);
}
$httpRequest->getQuery()->set('Action', $request->getAction());
return $httpRequest;
}
示例13: generate
/**
* {@inheritdoc}
*/
public function generate($toFile = null)
{
$url = self::BASE_URL;
$url .= $this->dimension . '/';
$url .= $this->backgroundColor->getColor(false) . '/';
$url .= $this->stringColor->getColor(false) . '.';
$url .= $this->imageExtension->getExtension() . '&text=';
$url .= urlencode($this->text);
if ($toFile !== null) {
$this->httpClient->get($url)->setResponseBody($toFile)->send();
}
return new Result(null, $toFile, $url);
}
示例14: getCounts
/**
* Get the issues counts from Drupal.org for the specified parameters.
*
* @param array $commonParameters
* An array of query parameters to use in all requests.
* @param array $fetchSet
* An array to specify separate requests to make and their unique
* parameters, in the format
* 'setKey' => array(
* 'parameterKey' => 'parameterValue',
* )
*/
public function getCounts($commonParameters, $fetchSet)
{
$results = array();
foreach ($fetchSet as $fetchKey => $fetchParameters) {
$request = $this->client->get('/project/issues/search/drupal');
$request->getQuery()->overwriteWith($commonParameters)->overwriteWith($fetchParameters);
try {
$results[$fetchKey] = $this->getCount($request);
} catch (\Exception $e) {
$results[$fetchKey] = null;
}
}
return $results;
}
示例15: request
/**
* Execute the url request
*
* @param string $url
*
* @return \Guzzle\Http\EntityBodyInterface|string
*/
protected function request($url)
{
if (null === $this->httpClient) {
$this->httpClient = new HttpClient();
}
return $this->httpClient->get($url)->send()->getBody(true);
}