本文整理汇总了PHP中GuzzleHttp\ClientInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::get方法的具体用法?PHP ClientInterface::get怎么用?PHP ClientInterface::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public function get($url)
{
if (!$this->isValidArgument($url)) {
throw new \InvalidArgumentException('Supply a valid URL please.');
}
return $this->guzzle->get($url);
}
示例2: get
/**
* Executa uma requisição GET.
*
* @param $part
* @param array $data
* @param array $headers
* @return mixed
*/
public function get($part, $data = [], array $headers = [])
{
$opts = ['headers' => array_merge([], $this->headers, $headers)];
$part = uri_params($part, $data);
$response = new Response($this->client->get($part, $opts));
return $response->make();
}
示例3: execute
/**
* Execute an operaction
*
* A successful operation will return result as an array.
* An unsuccessful operation will return null.
*
* @param OperationInterface $op
* @return array|null
*/
public function execute(OperationInterface $op)
{
try {
if ($op instanceof DeleteOperationInterface) {
$response = $this->httpClient->delete($op->getEndpoint(), ['headers' => $op->getHeaders()]);
} elseif ($op instanceof PostOperationInterface) {
$response = $this->httpClient->post($op->getEndpoint(), ['headers' => $op->getHeaders(), 'body' => $op->getData()]);
} elseif ($op instanceof PatchOperationInterface) {
$response = $this->httpClient->patch($op->getEndpoint(), ['headers' => $op->getHeaders(), 'body' => $op->getData()]);
} elseif ($op instanceof PutOperationInterface) {
$response = $this->httpClient->put($op->getEndpoint(), ['headers' => $op->getHeaders(), 'body' => $op->getData()]);
} else {
$response = $this->httpClient->get($op->getEndpoint());
}
} catch (GuzzleHttp\Exception\ClientException $e) {
throw new Exception\ClientException('ClientException occurred in request to Orchestrate: ' . $e->getMessage(), $e->getCode(), $e);
} catch (GuzzleHttp\Exception\ServerException $e) {
throw new Exception\ServerException('ServerException occurred in request to Orchestrate: ' . $e->getMessage(), $e->getCode(), $e);
}
$refLink = null;
$location = null;
if ($response->hasHeader('ETag')) {
$refLink = str_replace('"', '', $response->getHeaderLine('ETag'));
} elseif ($response->hasHeader('Link')) {
$refLink = str_replace(['<', '>; rel="next"'], ['', ''], $response->getHeaderLine('Link'));
}
if ($response->hasHeader('Location')) {
$location = $response->getHeaderLine('Location');
}
$rawValue = $response->getBody(true);
$value = json_decode($rawValue, true);
return $op->getObjectFromResponse($refLink, $location, $value, $rawValue);
}
示例4: getRequest
/**
* @since 0.2
* @param Request $request
* @return mixed
*/
public function getRequest(Request $request)
{
$resultArray = $this->client->get(null, array('query' => array_merge($request->getParams(), array('format' => 'json')), 'headers' => $request->getHeaders()))->json();
$this->triggerErrors($resultArray);
$this->throwUsageExceptions($resultArray);
return $resultArray;
}
示例5: getQueue
/**
* @param string $vhost
* @param string $name
* @param int $interval
*
* @return array
*/
public function getQueue($vhost, $name, $interval = 30)
{
$queueName = sprintf('%s/%s', urlencode($vhost), urlencode($name));
$url = sprintf('http://%s:%d/api/queues/%s?%s', $this->hostname, $this->port, $queueName, http_build_query(['lengths_age' => $interval, 'lengths_incr' => $interval, 'msg_rates_age' => $interval, 'msg_rates_incr' => $interval, 'data_rates_age' => $interval, 'data_rates_incr' => $interval]));
$response = $this->httpClient->get($url, ['auth' => [$this->user, $this->password]]);
return $response->json();
}
示例6: denormalize
/**
* {@inheritdoc}
*/
public function denormalize($data, $class, $format = NULL, array $context = array())
{
$file_data = (string) $this->httpClient->get($data['uri'][0]['value'])->getBody();
$path = 'temporary://' . drupal_basename($data['uri'][0]['value']);
$data['uri'] = file_unmanaged_save_data($file_data, $path);
return $this->entityManager->getStorage('file')->create($data);
}
示例7: downloadFile
/**
* Download a package file.
*
* @param string $path
* @param string $url
* @param string $shasum
*/
public function downloadFile($path, $url, $shasum = '')
{
$file = $path . '/' . uniqid();
try {
$data = $this->client->get($url)->getBody();
if ($shasum && sha1($data) !== $shasum) {
throw new ChecksumVerificationException("The file checksum verification failed");
}
if (!$this->files->makeDir($path) || !$this->files->putContents($file, $data)) {
throw new NotWritableException("The path is not writable ({$path})");
}
if (Zip::extract($file, $path) !== true) {
throw new ArchiveExtractionException("The file extraction failed");
}
$this->files->delete($file);
} catch (\Exception $e) {
$this->files->delete($path);
if ($e instanceof TransferException) {
if ($e instanceof BadResponseException) {
throw new UnauthorizedDownloadException("Unauthorized download ({$url})");
}
throw new DownloadErrorException("The file download failed ({$url})");
}
throw $e;
}
}
示例8: fetchPageContentFor
/**
* Scrape and fetch page content for the provided link
*
* @param $link
* @return string
*/
public function fetchPageContentFor($link)
{
// We need to enable cookie to be able to get the proper page source
$cookieJar = new CookieJar();
$response = $this->guzzleClient->get($link, ['cookies' => $cookieJar]);
return (string) $response->getBody();
}
示例9: getListTasks
/**
* Return all the tasks of a given list
*
* @param int $list_id
*
* @return array()
*/
public function getListTasks($list_id)
{
if (!is_numeric($list_id)) {
throw new \InvalidArgumentException('The list id must be numeric.');
}
$response = $this->client->get('tasks', ['query' => ['list_id' => $list_id]]);
$this->checkResponseStatusCode($response, 200);
return json_decode($response->getBody());
}
示例10: download
/**
* @param $url
* @return string
* @throws HttpClientException
*/
public function download($url)
{
$response = $this->guzzlClient->get($url);
if (200 == $response->getStatusCode()) {
$body = $response->getBody();
return $this->saveBodyAsFile($body);
}
throw new HttpClientException(sprintf('Unable to get download from "%s"', $url));
}
示例11: get
/**
* @param $action
* @param array $options
* @return mixed
* @throws \Exception
*/
public function get($action, array $options)
{
$requestOptions = $this->buildRequestOptions($action, $options);
try {
$response = $this->connection->get($this->api_url, ['headers' => $requestOptions['headers'], 'cookies' => $requestOptions['cookies'], 'query' => $requestOptions['query']]);
} catch (RequestException $e) {
throw new \Exception($e->getMessage(), $e->getCode(), $e);
}
return $response->json();
}
示例12: sendRequest
/**
* send a request to pugme api
*
* @param string $url
* @return mixed
* @throws PugNotFoundException
*/
private function sendRequest($url)
{
try {
$response = $this->client->get($this->baseUrl . $url);
$pug = json_decode($response->getBody(), true);
} catch (Exception $e) {
throw new PugNotFoundException();
}
return $pug;
}
示例13: get
/**
* Fetch the media items.
*
* @param string $user
*
* @throws \Vinkla\Instagram\InstagramException
*
* @return array
*/
public function get(string $user) : array
{
try {
$url = sprintf('https://www.instagram.com/%s/media', $user);
$response = $this->client->get($url);
return json_decode((string) $response->getBody(), true)['items'];
} catch (RequestException $e) {
throw new InstagramException(sprintf('The user [%s] was not found.', $user));
}
}
示例14: profileApi
public function profileApi($uuid)
{
$response = $this->client->get(sprintf(static::PROFILE_API, $uuid))->json(array('object' => true));
if (!$response) {
throw new \RuntimeException('Bad UUID ' . $uuid);
} elseif (isset($response->error)) {
throw new \RuntimeException('Error from API: ' . $response->error . ' on UUID ' . $uuid);
}
return $response;
}
示例15: get
/**
* {@inheritdoc}
*/
public function get($url)
{
try {
$this->response = $this->client->get($url);
} catch (RequestException $e) {
$this->response = $e->getResponse();
$this->handleError();
}
return $this->response->getBody();
}