本文整理匯總了PHP中Buzz\Browser::get方法的典型用法代碼示例。如果您正苦於以下問題:PHP Browser::get方法的具體用法?PHP Browser::get怎麽用?PHP Browser::get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Buzz\Browser
的用法示例。
在下文中一共展示了Browser::get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getUserDetails
/**
* @param string $token
*
* @return ProviderMetadata
*/
public function getUserDetails($token)
{
try {
// Fetch user data
$response = $this->httpClient->get('https://api.github.com/user', ['Authorization' => sprintf('token %s', $token), 'User-Agent' => 'Pickleweb']);
$data = json_decode($response->getContent(), true);
if (empty($data) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json error');
}
// Fetch emails if needed
if (empty($data['email'])) {
$response = $this->httpClient->get('https://api.github.com/user/emails', ['Authorization' => sprintf('token %s', $token), 'User-Agent' => 'Pickleweb']);
$emails = json_decode($response->getContent(), true);
if (empty($emails) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json error');
}
$emails = array_filter($emails, function ($emailData) {
return true === $emailData['primary'];
});
if (!empty($emails)) {
$data['email'] = current($emails)['email'];
}
}
return new ProviderMetadata(['uid' => $data['id'], 'nickName' => $data['login'], 'realName' => $data['name'], 'email' => $data['email'], 'profilePicture' => $data['avatar_url'], 'homepage' => $data['html_url'], 'location' => $data['location']]);
} catch (\Exception $e) {
throw new \RuntimeException('cannot fetch account details', 0, $e);
}
}
示例2: request
/**
*
* @param string $path Path (will be appended to the Base URL)
* @param array $params
* @param mixed $method
* @return \SimpleXMLElement
*/
protected function request($path, array $params = null, $method = RequestInterface::METHOD_GET)
{
// Full URL
$fullUrl = new Url($this->baseUrl . $path);
// Additional headers
$headers = array('User-Agent: ' . $this->getUserAgentString());
// Got data?
if ($method === RequestInterface::METHOD_GET) {
if ($params != null && count($params) > 0) {
$fullUrl = new Url($this->baseUrl . $path . '?' . http_build_query($params));
}
$response = $this->browser->get($fullUrl, $headers);
} else {
$response = $this->browser->call($fullUrl, $method, $headers, $params);
}
// Convert XML
$xml = @simplexml_load_string($response->getContent());
// Succesful?
if ($xml === false) {
throw new MollieException('Server did not respond with valid XML.');
}
// Error?
if ($xml->item != null && (string) $xml->item['type'] == 'error') {
throw new MollieException((string) $xml->item->message, intval($xml->item->errorcode));
}
return $xml;
}
示例3: getUserDetails
/**
* @param string $token
*
* @return ProviderMetadata
*/
public function getUserDetails($token)
{
try {
// Fetch user data
list($identifier, $secret) = explode('@', $token);
$tokenObject = new TokenCredentials();
$tokenObject->setIdentifier($identifier);
$tokenObject->setSecret($secret);
$url = 'https://api.bitbucket.org/2.0/user';
$headers = $this->oauthProvider->getHeaders($tokenObject, 'GET', $url);
$response = $this->httpClient->get($url, $headers);
$data = json_decode($response->getContent(), true);
if (empty($data) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json error');
}
// Fetch email
$url = sprintf('https://api.bitbucket.org/1.0/users/%s/emails', $data['username']);
$headers = $this->oauthProvider->getHeaders($tokenObject, 'GET', $url);
$response = $this->httpClient->get($url, $headers);
$emails = json_decode($response->getContent(), true);
if (empty($emails) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json error');
}
$emails = array_filter($emails, function ($emailData) {
return true === $emailData['primary'];
});
$data['email'] = empty($emails) ? '' : current($emails)['email'];
return new ProviderMetadata(['uid' => $data['uuid'], 'nickName' => $data['username'], 'realName' => $data['display_name'], 'email' => $data['email'], 'profilePicture' => $data['links']['avatar']['href'], 'homepage' => $data['links']['html']['href'], 'location' => $data['location']]);
} catch (\Exception $e) {
throw new \RuntimeException('cannot fetch account details', 0, $e);
}
}
示例4: translate
/**
* @param string $sourceLanguage
* @param string $destinationLanguage
* @param string $text
* @return string
*/
public function translate($sourceLanguage, $destinationLanguage, $text)
{
$response = $this->browser->get(sprintf(static::API_ENDPOINT_MASK, $sourceLanguage, $destinationLanguage, urlencode($text)));
$rawXml = $response->getContent();
$xml = simplexml_load_string($rawXml);
return (string) $xml;
}
示例5: get
/**
* {@inheritdoc}
*/
public function get($url)
{
$response = $this->browser->get($url);
if (!$response->isSuccessful()) {
throw $this->handleResponse($response);
}
return $response->getContent();
}
示例6: authenticate
/**
* @param string $key The key
* @param string $pass The pass
* @return boolean
* @throws BadResponseException
*/
public function authenticate($key, $pass)
{
$response = $this->browser->get(sprintf('%s/check/password.json?%s', $this->baseUrl, http_build_query(array('key' => $key, 'pass' => $pass))));
if (500 == $response->getStatusCode()) {
throw new BadResponseException($response);
}
return 'true' == $response->getContent() ? true : false;
}
示例7: getUserDetails
/**
* @param string $token
*
* @return ProviderMetadata
*/
public function getUserDetails($token)
{
$data = json_decode($this->httpClient->get('https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' . $token)->getContent(), true);
if (empty($data) || json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('cannot fetch account details');
}
return new ProviderMetadata(['uid' => $data['id'], 'nickName' => $data['given_name'], 'realName' => $data['name'], 'email' => $data['email'], 'profilePicture' => $data['picture'], 'homepage' => $data['link']]);
}
示例8: getTickets
public function getTickets()
{
$this->browser->get($this->url . self::TICKET_LIST);
$ticketsData = $this->getResponse()->tickets;
$tickets = array_map(function ($value) {
return new Ticket($value);
}, $ticketsData);
return $tickets;
}
示例9: getContent
/**
* {@inheritDoc}
*/
public function getContent($url)
{
try {
$response = $this->browser->get($url);
$content = $response->getContent();
} catch (\Exception $e) {
$content = null;
}
return $content;
}
示例10: doRequest
/**
* @throws \InvalidArgumentException
* @param $type
* @param $url
* @param array $headers
* @param null $content
* @return \Buzz\Message\Response
*/
private function doRequest($type, $url, $headers = array(), $content = null)
{
$this->authorize();
$headers = array_merge($headers, array('Authorization: GoogleLogin Auth=' . $this->authToken));
switch ($type) {
case 'GET':
return $this->httpClient->get($url, $headers);
case 'POST':
return $this->httpClient->post($url, $headers, $content);
default:
throw new \InvalidArgumentException($type . ' is no valid request type');
}
}
示例11: getResponseContent
/**
* @param $url
* @return string
* @throws LoadDataException
*/
public function getResponseContent($url)
{
try {
/** @var \Buzz\Message\Response $buzzResponse */
$buzzResponse = $this->browser->get($url);
if (!$buzzResponse->getContent()) {
throw new \Exception('Empty response data');
}
} catch (\Exception $e) {
throw new LoadDataException($e->getMessage(), $e->getCode());
}
return $buzzResponse->getContent();
}
示例12: search
/**
* {@inheritDoc}
*
* @throws ConnectionException
* @throws UnexpectedResponseException
*/
public function search($query, $page = null)
{
$url = $this->getUrl($query, $page);
try {
$response = $this->browser->get($url);
} catch (\Exception $e) {
throw new ConnectionException(sprintf('Could not connect to "%s"', $url), 0, $e);
}
if ($response->getStatusCode() != 200) {
throw new UnexpectedResponseException(sprintf('Unexpected response: %s (%d)', $response->getReasonPhrase(), $response->getStatusCode()));
}
return $this->transformResponse($response->getContent());
}
示例13: doGetExchangeRate
/**
* Get exchange rate
* @return float
* @throws ProviderUnavailableException
* @throws UnsupportedConversionException
*/
public function doGetExchangeRate()
{
$url = sprintf($this->baseUrl, $this->baseCurrency, $this->targetCurrency);
$response = $this->browser->get($url);
if (200 !== $response->getStatusCode()) {
throw new ProviderUnavailableException($this->getName());
}
$data = explode(',', $response->getContent());
if (!isset($data[1]) || !is_numeric($data[1])) {
throw new UnsupportedConversionException($this->baseCurrency, $this->targetCurrency);
}
return $data[1];
}
示例14: findByLocationAndDateTime
/**
* @param $latitude
* @param $longitude
* @return \Manticora\WeatherCenter\Domain\Model\Weather\Weather
*/
public function findByLocationAndDateTime($latitude, $longitude, DateTimeInterface $dateTime)
{
$response = $this->client->get('http://api.wunderground.com/api/' . $this->key . '/lang:' . $this->language . '/hourly10day/q/' . $latitude . ',' . $longitude . '.json');
$o = json_decode($response->getContent(), true);
$store = new JsonStore($o);
$pattern = "\$..hourly_forecast[?(@.FCTTIME.hour == {$dateTime->getHour()}\n && @.FCTTIME.mday == {$dateTime->getDay()}\n && @.FCTTIME.mon == {$dateTime->getMonth()} )]";
$res = $store->get(str_replace(array("\n", "\r"), '', $pattern));
if (!isset($res[0])) {
return null;
}
$weat = $res[0];
$weather = new Weather($weat['condition'], $weat['icon_url'], $weat['temp']['metric'], $weat['humidity'], $weat['pop'], $weat['wspd']['metric'], $weat['wdir']['degrees']);
return $weather;
}
示例15: fetchRepository
public function fetchRepository($slug)
{
$repositoryUrl = sprintf('%s/%s.json', $this->apiUrl, $slug);
$buildsUrl = sprintf('%s/%s/builds.json', $this->apiUrl, $slug);
$repository = new Repository();
$repositoryArray = json_decode($this->browser->get($repositoryUrl)->getContent(), true);
if (!$repositoryArray) {
throw new \UnexpectedValueException(sprintf('Response is empty for url %s', $repositoryUrl));
}
$repository->fromArray($repositoryArray);
$buildCollection = new BuildCollection(json_decode($this->browser->get($buildsUrl)->getContent(), true));
$repository->setBuilds($buildCollection);
return $repository;
}