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


PHP Client::get方法代码示例

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


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

示例1: getAllProjects

 public function getAllProjects()
 {
     $key = "{$this->cachePrefix}-all-projects";
     if ($this->cache && ($projects = $this->cache->fetch($key))) {
         return $projects;
     }
     $first = json_decode($this->client->get('projects.json', ['query' => ['limit' => 100]])->getBody(), true);
     $projects = $first['projects'];
     if ($first['total_count'] > 100) {
         $requests = [];
         for ($i = 100; $i < $first['total_count']; $i += 100) {
             $requests[] = $this->client->getAsync('projects.json', ['query' => ['limit' => 100, 'offset' => $i]]);
         }
         /** @var Response[] $responses */
         $responses = Promise\unwrap($requests);
         $responseProjects = array_map(function (Response $response) {
             return json_decode($response->getBody(), true)['projects'];
         }, $responses);
         $responseProjects[] = $projects;
         $projects = call_user_func_array('array_merge', $responseProjects);
     }
     usort($projects, function ($projectA, $projectB) {
         return strcasecmp($projectA['name'], $projectB['name']);
     });
     $this->cache && $this->cache->save($key, $projects);
     return $projects;
 }
开发者ID:stelsvitya,项目名称:server-manager,代码行数:27,代码来源:Projects.php

示例2: get

 /**
  * @param string $url
  * @return mixed
  */
 protected function get($url)
 {
     /** @noinspection PhpVoidFunctionResultUsedInspection */
     /** @var Response $response */
     $response = $this->client->get($url);
     return json_decode($response->getBody());
 }
开发者ID:elliotchance,项目名称:independentreserve,代码行数:11,代码来源:PublicClient.php

示例3: downloadFile

 /**
  * @param string $url
  * @param string $saveTo
  */
 private function downloadFile($url, $saveTo)
 {
     if ($this->progressBar) {
         $this->setDownloadWithProgressBar();
     }
     $this->httpClient->get($url, ['save_to' => $saveTo]);
 }
开发者ID:fonsecas72,项目名称:selenium-handler,代码行数:11,代码来源:SeleniumDownloader.php

示例4: validateTicket

 /**
  * Validate the service ticket parameter present in the request.
  *
  * This method will return the username of the user if valid, and raise an
  * exception if the ticket is not found or not valid.
  *
  * @param string $version
  *   The protocol version of the CAS server.
  * @param string $ticket
  *   The CAS authentication ticket to validate.
  * @param array $service_params
  *   An array of query string parameters to add to the service URL.
  *
  * @return array
  *   An array containing validation result data from the CAS server.
  * @throws CasValidateException
  */
 public function validateTicket($version, $ticket, $service_params = array())
 {
     try {
         $validate_url = $this->casHelper->getServerValidateUrl($ticket, $service_params);
         $this->casHelper->log("Trying to validate against {$validate_url}");
         $options = array();
         $cert = $this->casHelper->getCertificateAuthorityPem();
         if (!empty($cert)) {
             $options['verify'] = $cert;
         } else {
             $options['verify'] = FALSE;
         }
         $response = $this->httpClient->get($validate_url, $options);
         $response_data = $response->getBody()->__toString();
         $this->casHelper->log("Received " . htmlspecialchars($response_data));
     } catch (ClientException $e) {
         throw new CasValidateException("Error with request to validate ticket: " . $e->getMessage());
     }
     switch ($version) {
         case "1.0":
             return $this->validateVersion1($response_data);
         case "2.0":
             return $this->validateVersion2($response_data);
     }
     // If we get here, its because we had a bad CAS version specified.
     throw new CasValidateException("Unknown CAS protocol version specified.");
 }
开发者ID:anarshi,项目名称:recap,代码行数:44,代码来源:CasValidator.php

示例5: call

 /**
  * Execute the get method on the guzzle client and create a response
  *
  * @param array $opts
  * @return Response
  */
 public function call(array $opts, $url)
 {
     /** @var ResponseInterface $response */
     /** @noinspection PhpVoidFunctionResultUsedInspection */
     $response = $this->client->get($url, $opts);
     return new Response($response);
 }
开发者ID:banderon1,项目名称:open-weather,代码行数:13,代码来源:Requester.php

示例6: validateTicket

 /**
  * Validate the service ticket parameter present in the request.
  *
  * This method will return the username of the user if valid, and raise an
  * exception if the ticket is not found or not valid.
  *
  * @param string $ticket
  *   The CAS authentication ticket to validate.
  * @param array $service_params
  *   An array of query string parameters to add to the service URL.
  *
  * @return array
  *   An array containing validation result data from the CAS server.
  *
  * @throws CasValidateException
  *   Thrown if there was a problem making the validation request or
  *   if there was a local configuration issue.
  */
 public function validateTicket($ticket, $service_params = array())
 {
     $options = array();
     $verify = $this->casHelper->getSslVerificationMethod();
     switch ($verify) {
         case CasHelper::CA_CUSTOM:
             $cert = $this->casHelper->getCertificateAuthorityPem();
             $options['verify'] = $cert;
             break;
         case CasHelper::CA_NONE:
             $options['verify'] = FALSE;
             break;
         case CasHelper::CA_DEFAULT:
         default:
             // This triggers for CasHelper::CA_DEFAULT.
             $options['verify'] = TRUE;
     }
     $validate_url = $this->casHelper->getServerValidateUrl($ticket, $service_params);
     $this->casHelper->log("Attempting to validate service ticket using URL {$validate_url}");
     try {
         $response = $this->httpClient->get($validate_url, $options);
         $response_data = $response->getBody()->__toString();
         $this->casHelper->log("Validation response received from CAS server: " . htmlspecialchars($response_data));
     } catch (RequestException $e) {
         throw new CasValidateException("Error with request to validate ticket: " . $e->getMessage());
     }
     $protocol_version = $this->casHelper->getCasProtocolVersion();
     switch ($protocol_version) {
         case "1.0":
             return $this->validateVersion1($response_data);
         case "2.0":
             return $this->validateVersion2($response_data);
     }
     throw new CasValidateException('Unknown CAS protocol version specified: ' . $protocol_version);
 }
开发者ID:pulibrary,项目名称:recap,代码行数:53,代码来源:CasValidator.php

示例7: execute

 /**
  * Execute the command.
  *
  * @param InputInterface $input The input.
  * @param OutputInterface $output The output.
  * @throws InvalidArgumentException If the configuration is not specified.
  * @return integer
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configFile = $input->getOption('config-file');
     $config = Yaml::parse(file_get_contents($configFile), true);
     if (!isset($config['strava']['auth'])) {
         throw new InvalidArgumentException('There is no configuration specified for tracker "strava". See example config.');
     }
     $secretToken = $config['strava']['auth']['secretToken'];
     $clientID = $config['strava']['auth']['clientID'];
     $username = $config['strava']['auth']['username'];
     $password = $config['strava']['auth']['password'];
     $httpClient = new Client();
     /** @var \GuzzleHttp\Message\ResponseInterface $response */
     // Do normal login.
     $response = $httpClient->get('https://www.strava.com/login', ['cookies' => true]);
     $authenticityToken = $this->getAuthenticityToken($response);
     // Perform the login to strava.com
     $httpClient->post('https://www.strava.com/session', array('cookies' => true, 'body' => array('authenticity_token' => $authenticityToken, 'email' => $username, 'password' => $password)));
     // Get the authorize page.
     $response = $httpClient->get('https://www.strava.com/oauth/authorize?client_id=' . $clientID . '&response_type=code&redirect_uri=http://localhost&scope=view_private,write&approval_prompt=force', ['cookies' => true]);
     $authenticityToken = $this->getAuthenticityToken($response);
     // Accept the application.
     $response = $httpClient->post('https://www.strava.com/oauth/accept_application?client_id=' . $clientID . '&response_type=code&redirect_uri=http://localhost&scope=view_private,write', array('cookies' => true, 'allow_redirects' => false, 'body' => array('authenticity_token' => $authenticityToken)));
     $redirectLocation = $response->getHeader('Location');
     $urlQuery = parse_url($redirectLocation, PHP_URL_QUERY);
     parse_str($urlQuery, $urlQuery);
     $authorizationCode = $urlQuery['code'];
     // Token exchange.
     $response = $httpClient->post('https://www.strava.com/oauth/token', array('body' => array('client_id' => $clientID, 'client_secret' => $secretToken, 'code' => $authorizationCode)));
     $jsonResponse = $response->json();
     $code = $jsonResponse['access_token'];
     $output->writeln('Your access token is: <comment>' . $code . '</comment>');
     return 0;
 }
开发者ID:JavierMartinz,项目名称:SportTrackerConnector,代码行数:42,代码来源:GetToken.php

示例8: facebook

 /**
  * Login with Facebook.
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function facebook(Request $request)
 {
     $accessTokenUrl = 'https://graph.facebook.com/v2.5/oauth/access_token';
     $graphApiUrl = 'https://graph.facebook.com/v2.5/me';
     $params = ['code' => $request->input('code'), 'client_id' => $request->input('clientId'), 'redirect_uri' => $request->input('redirectUri'), 'client_secret' => Config::get('app.facebook_secret')];
     $client = new GuzzleHttp\Client();
     // Step 1. Exchange authorization code for access token.
     $accessToken = json_decode($client->get($accessTokenUrl, ['query' => $params])->getBody(), true);
     // Step 2. Retrieve profile information about the current user.
     $profile = json_decode($client->get($graphApiUrl, ['query' => $accessToken])->getBody(), true);
     // Step 3a. If user is already signed in then link accounts.
     if ($request->header('Authorization')) {
         $user = User::where('facebook', '=', $profile['id']);
         $userData = $user->first();
         if ($userData) {
             return response()->json(['token' => $this->createToken($userData)]);
         }
         $token = explode(' ', $request->header('Authorization'))[1];
         $payload = json_decode(Crypt::decrypt($token));
         $user = User::find($payload['sub']);
         $user->facebook = $profile['id'];
         $user->displayName = $user->displayName ?: $profile['name'];
         $user->save();
         return response()->json(['token' => $this->createToken($user)]);
     } else {
         $user = User::where('facebook', '=', $profile['id']);
         if ($user->first()) {
             return response()->json(['token' => $this->createToken($user->first())]);
         }
         $user = new User();
         $user->facebook = $profile['id'];
         $user->save();
         return response()->json(['token' => $this->createToken($user)]);
     }
 }
开发者ID:yayatoure42,项目名称:service-exchange,代码行数:41,代码来源:AuthenticateController.php

示例9: histogramsShouldIncrementAtomically

    /**
     * @test
     */
    public function histogramsShouldIncrementAtomically()
    {
        $start = microtime(true);
        $promises = [$this->client->getAsync('/examples/some_histogram.php?c=0&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=1&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=2&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=3&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=4&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=5&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=6&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=7&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=8&adapter=' . $this->adapter), $this->client->getAsync('/examples/some_histogram.php?c=9&adapter=' . $this->adapter)];
        Promise\settle($promises)->wait();
        $end = microtime(true);
        echo "\ntime: " . ($end - $start) . "\n";
        $metricsResult = $this->client->get('/examples/metrics.php?adapter=' . $this->adapter);
        $body = (string) $metricsResult->getBody();
        $this->assertThat($body, $this->stringContains(<<<EOF
test_some_histogram_bucket{type="blue",le="0.1"} 1
test_some_histogram_bucket{type="blue",le="1"} 2
test_some_histogram_bucket{type="blue",le="2"} 3
test_some_histogram_bucket{type="blue",le="3.5"} 4
test_some_histogram_bucket{type="blue",le="4"} 5
test_some_histogram_bucket{type="blue",le="5"} 6
test_some_histogram_bucket{type="blue",le="6"} 7
test_some_histogram_bucket{type="blue",le="7"} 8
test_some_histogram_bucket{type="blue",le="8"} 9
test_some_histogram_bucket{type="blue",le="9"} 10
test_some_histogram_bucket{type="blue",le="+Inf"} 10
test_some_histogram_count{type="blue"} 10
test_some_histogram_sum{type="blue"} 45
EOF
));
    }
开发者ID:jimdo,项目名称:prometheus_client_php,代码行数:29,代码来源:BlackBoxTest.php

示例10: fire

 public function fire()
 {
     $client = new Client(array('base_uri' => 'https://hacker-news.firebaseio.com'));
     $endpoints = array('top' => '/v0/topstories.json', 'ask' => '/v0/askstories.json', 'job' => '/v0/jobstories.json', 'show' => '/v0/showstories.json', 'new' => '/v0/newstories.json');
     foreach ($endpoints as $type => $endpoint) {
         $response = $client->get($endpoint);
         $result = $response->getBody();
         $items = json_decode($result, true);
         foreach ($items as $id) {
             $item_res = $client->get("/v0/item/" . $id . ".json");
             $item_data = json_decode($item_res->getBody(), true);
             if (!empty($item_data)) {
                 $item = array('id' => $id, 'title' => $item_data['title'], 'item_type' => $item_data['type'], 'username' => $item_data['by'], 'score' => $item_data['score'], 'time_stamp' => $item_data['time']);
                 $item['is_' . $type] = true;
                 if (!empty($item_data['text'])) {
                     $item['description'] = strip_tags($item_data['text']);
                 }
                 if (!empty($item_data['url'])) {
                     $item['url'] = $item_data['url'];
                 }
                 $db_item = DB::table('items')->where('id', '=', $id)->first();
                 if (empty($db_item)) {
                     DB::table('items')->insert($item);
                 } else {
                     DB::table('items')->where('id', $id)->update($item);
                 }
             }
         }
     }
     return 'ok';
 }
开发者ID:anchetaWern,项目名称:hn-reader,代码行数:31,代码来源:UpdateNewsItems.php

示例11: check

 /**
  * Perform the check of a URL
  *
  * @param string $url URL to check
  * @param int $timeout timeout for the request. Defaults to 5 seconds
  * @return Status
  */
 public function check($url, $timeout = 5)
 {
     $this->validateUrl($url);
     $response = null;
     $statusCode = null;
     $reason = null;
     $unresolved = false;
     $timeStart = microtime(true);
     try {
         $response = $this->guzzle->get($url, ['timeout' => $timeout]);
         $statusCode = $response->getStatusCode();
     } catch (ClientException $e) {
         // When not a 200 status but still responding
         $statusCode = $e->getCode();
         $reason = $e->getMessage();
     } catch (ConnectException $e) {
         // Unresolvable host etc
         $reason = $e->getMessage();
         $unresolved = true;
     } catch (\Exception $e) {
         // Other errors
         $reason = $e->getMessage();
         $unresolved = true;
     }
     $timeEnd = microtime(true);
     $time = $timeEnd - $timeStart;
     // seconds
     return new UrlStatus($url, $statusCode, $time, $unresolved, $response, $reason);
 }
开发者ID:viirre,项目名称:urlchecker,代码行数:36,代码来源:Checker.php

示例12: handle

 /**
  * Execute the console command.
  * @return mixed
  */
 public function handle()
 {
     $client = new Client();
     //Call to EMS API to get the employee details
     $date = Carbon::yesterday()->format('Y-m-d');
     //$date = '2016-03-03';
     $ems_data = $client->get(env(APP_HOST) . "/" . EMS_API_PATH . 'employee_list/' . $date);
     if ($ems_data->getStatusCode() == STATUS_OK) {
         $data = json_decode($ems_data->getBody()->getContents());
         foreach ($data as $key => $ems) {
             $staff = Staff::whereEmail($ems->employee_email_id)->first();
             if (!empty($staff)) {
                 //Find JIRA hours
                 $worklog = Timelog::whereStaffId($staff->id)->whereStarted($date)->sum('time_spent');
                 $actual_jira_hours = gmdate('H:i:s', $worklog);
                 $actual_ems_hours = $ems->actual_hours;
                 //Comparing EMS and JIRA hours
                 if ($actual_jira_hours != NULL && $actual_jira_hours != '00:00:00' && $actual_ems_hours != NULL && $actual_ems_hours != '00:00:00') {
                     $diffrence = $actual_ems_hours - $actual_jira_hours;
                     //IF difference is greater then 1 hour, then update EMS
                     // Call back to EMS to mark employee as half absent
                     $client->get(env(APP_HOST) . "/" . EMS_API_PATH . 'update_employee_timesheet/' . $ems->emp_id . '/' . $date . ($diffrence > ONE && $diffrence < FOUR) ? '/half' : '/full');
                 }
             }
         }
     }
 }
开发者ID:arsenaltech,项目名称:folio,代码行数:31,代码来源:CheckJiraHours.php

示例13: getLastEmail

 /**
  * @return MailTesterMessage
  */
 public function getLastEmail()
 {
     $inboxId = $this->config['inbox_id'];
     $messageId = $this->getAllEmails()[0]['id'];
     $email = $this->mailtrap->get("/api/v1/inboxes/{$inboxId}/messages/{$messageId}")->json();
     return $this->populateMessage($messageId, $email);
 }
开发者ID:psyao,项目名称:mailtester,代码行数:10,代码来源:MailTrap.php

示例14: get

 /**
  * @param string $url
  * @param array $options
  * @throws GuzzleException
  * @return Response
  */
 public function get($url, array $options = [])
 {
     if (strpos($url, 'http') !== 0) {
         $url = $this->baseUrl . '/' . $this->collection . '/' . ltrim($url, '/');
     }
     return new Response($this, $this->client->get($url, $options));
 }
开发者ID:opensoft,项目名称:tfs-rest-api,代码行数:13,代码来源:ClientHelper.php

示例15: fetch

 /**
  * Make API Call
  * @param  string $path  API Path
  * @param  array  $query Additional query parameters (optional)
  * @return GuzzleHttp\Response
  */
 public function fetch($path, array $query = [])
 {
     if (!$this->api instanceof Http) {
         $this->setupHttpClient();
     }
     return $this->api->get($path, ['query' => $query])->json();
 }
开发者ID:adamgoose,项目名称:gitlab,代码行数:13,代码来源:Client.php


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