get() public method

public get ( $id )
Ejemplo n.º 1
0
 /**
  * post a GET request.
  */
 protected function get($method, $params = array(), $headers = array(), $options = array())
 {
     # construct the query URL.
     $url = self::HOST_API_URL . $method;
     $auth_head = $this->get_auth_header($this->access_key, $this->secret_key);
     if (!$headers) {
         $headers = array();
     }
     if (!$options) {
         $options = array();
     }
     // set timeout
     $options['timeout'] = 10 * 60;
     $headers['Authorization'] = $auth_head;
     // build query url.
     $url = $this->build_http_parameters($url, $params);
     // echo "$url";
     $response = Requests::get($url, $headers, $params, $options);
     // echo $response->body;
     # Handle any HTTP errors.
     if ($response->status_code != 200) {
         throw new ViSearchException("HTTP failure, status code {$response->status_code}");
     }
     # get the response as an object.
     $response_json = json_decode($response->body);
     return $response_json;
 }
Ejemplo n.º 2
0
 /**
  * Get account information
  * 
  * @param Int $id - Account ID
  * @return \Oanda\response\getAccount\AccountFull
  */
 public function getAccount($id)
 {
     $headers = array('Authorization' => 'Bearer ' . $this->getToken());
     $response = \Requests::get($this->getUrl() . '/accounts/' . $id, $headers);
     $this->checkAnswer($response);
     return new \Oanda\response\getAccount\AccountFull(json_decode($response->body));
 }
Ejemplo n.º 3
0
 /**
  * 获得access_token
  * @return null
  */
 public function applyAccessToken($appid, $secret)
 {
     //        $redis = Redis::connection();
     //        if( ! $redis){
     //            throw new \Exception("redis connect error");
     //        }
     //        $accessToken = $redis->get('dajiayao.device.'.$appid);
     //        if( ! $accessToken){
     //            $url = sprintf(self::GET_TOKEN,$appid,$secret);
     //            $response = \Requests::get($url);
     //            $rtJson = $response->body;
     //            $rtJson = json_decode($rtJson);
     //            if (array_key_exists('access_token', $rtJson)) {
     //                $redis->setex('dajiayao.device.'.$appid,7000,$rtJson->access_token);
     //            }else{
     //                throw new \Exception("weixin get access_token error");
     //            }
     //        }
     //
     //        return $redis->get('dajiayao.device.'.$appid);
     //TODO 后期需要从缓存或者从access_token中央服务器中获取
     $url = sprintf(self::GET_TOKEN, $appid, $secret);
     $response = \Requests::get($url);
     $rtJson = $response->body;
     $rtJson = json_decode($rtJson);
     if (array_key_exists('access_token', $rtJson)) {
         return $rtJson->access_token;
     } else {
         throw new \Exception("weixin get access_token error");
     }
 }
Ejemplo n.º 4
0
 /**
  * Get the Zip File from Server & return back the downloaded file location
  */
 public static function zipFile($url, $zipFile)
 {
     if (!extension_loaded('zip')) {
         self::log("Dependency Missing, Please install PHP Zip Extension");
         echo ser("PHP Zip Extension", "I can't find the Zip PHP Extension. Please Install It & Try again");
     }
     self::log("Started Downloading Zip File from {$url} to {$zipFile}");
     $userAgent = 'LobbyBot/0.1 (' . L_SERVER . ')';
     /**
      * Get The Zip From Server
      */
     $hooks = new \Requests_Hooks();
     if (self::$progress != null) {
         $progress = self::$progress;
         $hooks->register('curl.before_send', function ($ch) use($progress) {
             curl_setopt($ch, CURLOPT_NOPROGRESS, false);
             curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, $progress);
         });
     }
     try {
         \Requests::get($url, array("User-Agent" => $userAgent), array('filename' => $zipFile, 'hooks' => $hooks, 'timeout' => time()));
     } catch (\Requests_Exception $error) {
         self::log("HTTP Requests Error ({$url}) : {$error}");
         echo ser("Error", "HTTP Requests Error : " . $error);
         return false;
     }
     self::log("Downloaded Zip File from {$url} to {$zipFile}");
     return $zipFile;
 }
Ejemplo n.º 5
0
 /**
  * Gets departures from the given station starting at the given time.
  *
  * @param int $stationID
  * @param Carbon $time
  * @return array
  * @throws ApiException
  */
 public static function getDepartures(int $stationID, Carbon $time, int $maxJourneys = 10)
 {
     // prepare parameters for our request
     $query = ['input' => $stationID, 'boardType' => 'dep', 'time' => $time->format('H:i'), 'date' => $time->format('d.m.y'), 'maxJourneys' => $maxJourneys, 'start' => 'yes'];
     // send it to the bvg mobile site
     $response = \Requests::get(self::getApiEndpoint() . '?' . http_build_query($query));
     if ($response->status_code == 200) {
         // our results array
         $departures = [];
         // prepare document
         $dom = new Dom();
         $dom->load($response->body);
         // get date from API
         $date = $dom->find('#ivu_overview_input');
         $date = trim(substr($date->text, strpos($date->text, ':') + 1));
         $date = Carbon::createFromFormat('d.m.y', $date, 'Europe/Berlin');
         // get table data without the first line (header)
         $rows = $dom->find('.ivu_result_box .ivu_table tbody tr');
         // loop through each departure in the table
         foreach ($rows as $row) {
             // get columns
             $columns = $row->find('td');
             // explode time into two parts
             $time = explode(':', strip_tags($columns[0]));
             // push the departure onto our results array
             $departures[] = ['time' => $date->copy()->hour($time[0])->minute($time[1])->second(0), 'line' => trim(strip_tags($columns[1]->find('a')[0])), 'direction' => trim(strip_tags($columns[2]))];
         }
         // return results
         return $departures;
     } else {
         throw new ApiException('Failed getting station data from BVG API');
     }
 }
Ejemplo n.º 6
0
 public function getHelp()
 {
     // Get the current version
     $current_version = \Config::get('seat.version');
     // Try determine how far back we are on releases
     $versions_behind = 0;
     try {
         // Check the releases from Github for eve-seat/seat
         $headers = array('Accept' => 'application/json');
         $request = Requests::get('https://api.github.com/repos/eve-seat/seat/releases', $headers);
         if ($request->status_code == 200) {
             $release_data = json_decode($request->body);
             // Try and determine if we are up to date
             if ($release_data[0]->tag_name == 'v' . $current_version) {
             } else {
                 foreach ($release_data as $release) {
                     if ($release->tag_name == 'v' . $current_version) {
                         break;
                     } else {
                         $versions_behind++;
                     }
                 }
             }
         } else {
             $release_data = null;
         }
     } catch (Exception $e) {
         $release_data = null;
     }
     return View::make('help.help')->with('release_data', $release_data)->with('versions_behind', $versions_behind);
 }
Ejemplo n.º 7
0
 public static function httpGetRequest($url)
 {
     Requests::register_autoloader();
     $headers = array('MP-Public-Key' => MPower_Setup::getPublicKey(), 'MP-Private-Key' => MPower_Setup::getPrivateKey(), 'MP-Master-Key' => MPower_Setup::getMasterKey(), 'MP-Token' => MPower_Setup::getToken(), 'MP-Mode' => MPower_Setup::getMode(), 'User-Agent' => "MPower Checkout API PHP client v1 aka Don Nigalon");
     $request = Requests::get($url, $headers, array('timeout' => 10));
     return json_decode($request->body, true);
 }
Ejemplo n.º 8
0
 /**
  * Check Github for release information
  *
  * @return array
  */
 public function checkVersion()
 {
     // Prepare a return array
     $results = array('release_data' => null, 'versions_behind' => 0);
     // Get the current version
     $current_version = \Config::get('seat.version');
     try {
         // Check the releases from Github for eve-seat/seat
         $headers = array('Accept' => 'application/json');
         $request = \Requests::get('https://api.github.com/repos/eve-seat/seat/releases', $headers);
         if ($request->status_code == 200) {
             $results['release_data'] = json_decode($request->body);
             // Try and determine if we are up to date
             if ($results['release_data'][0]->tag_name == 'v' . $current_version) {
             } else {
                 foreach ($results['release_data'] as $release) {
                     if ($release->tag_name == 'v' . $current_version) {
                         break;
                     } else {
                         $results['versions_behind']++;
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $this->error('[!] Error: Failed to retrieve version information.');
         $this->error('[!] ' . $e->getMessage());
     }
     return $results;
 }
Ejemplo n.º 9
0
 public function getFavForums()
 {
     $data = array('tbs' => $this->getTbs());
     $response = Requests::get(self::FAV_URL . "?" . $this->encrypt($data), $this->_headers);
     $response = (array) json_decode($response->body);
     return $response['forum_list'];
 }
Ejemplo n.º 10
0
 public static function query_lastfm($url)
 {
     debug_event('Recommendation', 'search url : ' . $url, 5);
     $request = Requests::get($url, array(), Core::requests_options());
     $content = $request->body;
     return simplexml_load_string($content);
 }
Ejemplo n.º 11
0
Archivo: FFVV.php Proyecto: flub78/GVV3
 /**
  * Envoie une requête à HEVA
  */
 public function heva_request($req_uri = "", $params = array())
 {
     $FFVV_Heva_Host = "api.licences.ffvv.stadline.com";
     $head = wsse_header_short($this->config->item('ffvv_id'), $this->config->item('ffvv_pwd'));
     $url = "http://" . $FFVV_Heva_Host . $req_uri;
     return Requests::get($url, array('X-WSSE' => $head), $params);
 }
Ejemplo n.º 12
0
 public function get_pasien($no_rm_nasional = '')
 {
     $url = $this->REST_PASIEN_SERVER . '/' . $no_rm_nasional;
     $header = array('Accept' => 'application/json');
     $data = Requests::get($url, $header);
     print_r($data);
 }
Ejemplo n.º 13
0
 public function request($method, $params = null)
 {
     if (!is_null($params) or !empty($params) && is_array($params)) {
         foreach ($params as $param => $value) {
             $prefix = $value == reset($params) ? '?' : '&';
             $parameters .= sprintf("%s%s=%s", $prefix, $param, urlencode($value));
         }
     } else {
         throw new \Exception('Method request() must have an array argument.');
     }
     $this->query = null;
     if (is_null($this->request_as)) {
         $this->request_as = 'admin';
     }
     # https://tech.yandex.ru/market/partner/doc/dg/concepts/error-codes-docpage/
     $response = \Requests::post("https://pddimp.yandex.ru/api2/{$this->request_as}{$method}{$parameters}", ['Accept' => 'application/json', 'PddToken' => $this->pdd_token, 'Authorization' => $this->oauth_token]);
     if ($response->status_code == 405) {
         $response = \Requests::get("https://pddimp.yandex.ru/api2/{$this->request_as}{$method}{$parameters}", ['Accept' => 'application/json', 'PddToken' => $this->pdd_token, 'Authorization' => $this->oauth_token]);
     }
     switch ($response->status_code) {
         case 200:
             return json_decode($response->body, true);
             break;
         case 405:
             throw new \Exception('Method Not Allowed');
             break;
         default:
             throw new \Exception($response->status_code);
             break;
     }
     $this->request_as = null;
 }
Ejemplo n.º 14
0
 public static function httpGetRequest($url)
 {
     Requests::register_autoloader();
     $headers = array('PAYDUNYA-PUBLIC-KEY' => Paydunya_Setup::getPublicKey(), 'PAYDUNYA-PRIVATE-KEY' => Paydunya_Setup::getPrivateKey(), 'PAYDUNYA-MASTER-KEY' => Paydunya_Setup::getMasterKey(), 'PAYDUNYA-TOKEN' => Paydunya_Setup::getToken(), 'PAYDUNYA-MODE' => Paydunya_Setup::getMode(), 'User-Agent' => "PAYDUNYA Checkout API PHP client v1 aka Neptune");
     $request = Requests::get($url, $headers, array('timeout' => 10));
     return json_decode($request->body, true);
 }
Ejemplo n.º 15
0
 static function send($url, $headers = [], $options = [], $set = ['ret' => 'body', 'post' => ''])
 {
     $default_headers = ['User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36'];
     $default_options = ['follow_redirects' => false, 'timeout' => 30];
     $headers = $headers + $default_headers;
     $options = $options + $default_options;
     //出错的话就访问10次
     for ($i = 1; $i < 10; $i++) {
         \Log::debug("第{$i}次访问" . $url);
         try {
             if (isset($set['post']) && $set['post'] != "") {
                 $html = \Requests::post($url, $headers, $set['post'], $options);
             } else {
                 $html = \Requests::get($url, $headers, $options);
             }
         } catch (\Requests_Exception $e) {
             continue;
             //表示url访问出错了
         }
         if ($html->body != "") {
             break;
         }
         //表示访问正确
     }
     if ($set['ret'] == 'body') {
         return $html->body;
     } else {
         return $html;
     }
 }
Ejemplo n.º 16
0
 public static function get($url)
 {
     $response = \Requests::get($url, array('Accept' => 'application/json'));
     if ($response->success) {
         return json_decode($response->body, true);
     }
     return false;
 }
Ejemplo n.º 17
0
function getForecast($coordinates)
{
    $location = $coordinates->latitude . "," . $coordinates->longitude;
    $apiCall = FORECAST_API_URL . "/" . FORECAST_API_KEY . "/" . $location . "?units=si&v=" . rand(0, 100);
    $response = Requests::get($apiCall, array(), array("timeout" => 30));
    $weather = json_decode($response->body);
    return $weather;
}
Ejemplo n.º 18
0
 /**
  * Response says it's chunked and starts looking like it is, but turns out
  * that they're lying to us
  */
 public function testMixedChunkiness()
 {
     $transport = new MockTransport();
     $transport->body = "02\r\nab\r\nNot actually chunked!";
     $transport->chunked = true;
     $options = array('transport' => $transport);
     $response = Requests::get('http://example.com/', array(), $options);
     $this->assertEquals($transport->body, $response->body);
 }
Ejemplo n.º 19
0
 public function logout()
 {
     /*
      * compares session token against get method to see if it's the actual user
      */
     if (Sessions::get('token') == Requests::get('token')) {
         Sessions::destroy();
     }
 }
Ejemplo n.º 20
0
 /**
  * Get the service document
  */
 public function serviceDocumentProvider()
 {
     $options = array('useragent' => 'Gorilla/0.1 php-requests/' . Requests::VERSION);
     if (!empty($this->auth)) {
         $options = array('auth' => array($this->auth['user'], $this->auth['pass']));
     }
     $document = Requests::get($this->uri . '/service', array(), array(), $options);
     return array(array($document));
 }
Ejemplo n.º 21
0
 /**
  * @dataProvider transportProvider
  */
 public function testUsingInstantiation($transport)
 {
     $options = array('auth' => new Requests_Auth_Basic(array('user', 'passwd')), 'transport' => $transport);
     $request = Requests::get('http://httpbin.org/basic-auth/user/passwd', array(), $options);
     $this->assertEquals(200, $request->status_code);
     $result = json_decode($request->body);
     $this->assertEquals(true, $result->authenticated);
     $this->assertEquals('user', $result->user);
 }
Ejemplo n.º 22
0
 protected function query_omdb($title, $year = '')
 {
     $url = 'http://www.omdbapi.com/?t=' . rawurlencode($title);
     if (!empty($year)) {
         $url .= '&y=' . rawurlencode($year);
     }
     $request = Requests::get($url, array(), Core::requests_options());
     return json_decode($request->body);
 }
Ejemplo n.º 23
0
 public function ParseURL()
 {
     if (Requests::get('url') == true) {
         //remove trailing slash, sanatise url and explode the array
         return $url = explode("/", filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
         $this->controller = isset($url[0]) ? $url[0] : null;
         $this->method = isset($url[1]) ? $url[1] : null;
     }
 }
Ejemplo n.º 24
0
 protected function setCookieRequest($cookies)
 {
     $options = array('cookies' => $cookies);
     $response = Requests::get(httpbin('/cookies/set'), array(), $options);
     $data = json_decode($response->body, true);
     $this->assertInternalType('array', $data);
     $this->assertArrayHasKey('cookies', $data);
     return $data['cookies'];
 }
Ejemplo n.º 25
0
 public function request($method, $url, $api_key, $data = NULL, $headers = array("Content-Type" => "application/json", "Accept" => "application/json"))
 {
     try {
         $options = array('auth' => new \Requests_Auth_Basic(array($api_key, '')));
         if ($method == "GET") {
             $url_params = is_array($data) ? '?' . http_build_query($data) : '';
             $response = \Requests::get(Client::BASE_URL . $url . $url_params, $headers, $options);
         } else {
             if ($method == "POST") {
                 $response = \Requests::post(Client::BASE_URL . $url, $headers, json_encode($data), $options);
             } else {
                 if ($method == "PATCH") {
                     $response = \Requests::patch(Client::BASE_URL . $url, $headers, json_encode($data), $options);
                 } else {
                     if ($method == "DELETE") {
                         $response = \Requests::delete(Client::BASE_URL . $url, $headers, $options);
                     }
                 }
             }
         }
     } catch (\Exception $e) {
         throw new UnableToConnect();
     }
     if ($response->status_code >= 200 && $response->status_code <= 206) {
         if ($method == "DELETE") {
             return $response->status_code == 204 || $response->status_code == 200;
         }
         return json_decode($response->body);
     }
     if ($response->status_code == 400) {
         $code = 0;
         $message = "";
         try {
             $error = (array) json_decode($response->body)->errors[0];
             $code = key($error);
             $message = current($error);
         } catch (\Exception $e) {
             throw new UnhandledError($response->body, $response->status_code);
         }
         throw new InputValidationError($message, $code);
     }
     if ($response->status_code == 401) {
         throw new AuthenticationError();
     }
     if ($response->status_code == 404) {
         throw new NotFound();
     }
     if ($response->status_code == 403) {
         throw new InvalidApiKey();
     }
     if ($response->status_code == 405) {
         throw new MethodNotAllowed();
     }
     throw new UnhandledError($response->body, $response->status_code);
 }
Ejemplo n.º 26
0
 /**
  * Query Embed.ly's oEmbed service for an embeddable version
  * of the content available at the given URL.
  * @param String $url The URL to query; all normalization of the URL
  * is assumed to have been done externally.
  * @param array $opts Options for submitting along with the URL;
  * if omitted, the option "key" will be inserted and will carry
  * the value stored in config option "embedly.key"
  * @see config()
  * @throws Exception If the API response code is anything other than 200
  */
 function extract($url, $opts = array())
 {
     $api = self::$root . '/extract?' . http_build_query(array_merge(array('key' => config('embedly.key'), 'url' => $url), $opts));
     $req = Requests::get($api);
     $res = json_decode($req->body);
     if ($req->status_code !== 200) {
         throw new Exception($res->error_message, $res->error_code);
     } else {
         return $res;
     }
 }
Ejemplo n.º 27
0
 public function setUp()
 {
     global $testconfig;
     $this->api = new WPAPI($testconfig['url'], $testconfig['username'], $testconfig['password']);
     // Set up the schema retriever. This should be included instead,
     // once finalised.
     $schema_data = Requests::get(self::SCHEMA_BASE);
     $arrayretriever = new WPAPI_Test_SchemaRetriever(array(self::SCHEMA_BASE => $schema_data->body));
     $this->retriever = new UriRetriever();
     $this->retriever->setUriRetriever($arrayretriever);
 }
Ejemplo n.º 28
0
 function get_noantrian_client()
 {
     $date = date("d-m-Y");
     $rs_id = $this->input->post('rs_id');
     $poli_id = $this->input->post('poli_id');
     $host = $this->queue_model->get_host($rs_id);
     $url = $host->mrs_host . $this->REST_GET_ANTRIAN;
     echo $url;
     $header = array('Accept' => 'application/json');
     $data_antrian = Requests::get($url . '/' . $poli_id . '/' . $date, $header);
     echo $data_antrian;
 }
Ejemplo n.º 29
0
 protected function load($id)
 {
     $response = Requests::get(sprintf('http://zuri.net/zurich/%s/', $id));
     if ($response->status_code != 200) {
         throw new RequestException('Could not fetch response.');
     }
     $doc = new \DOMDocument();
     if (@$doc->loadHTML($response->body) === false) {
         throw new RequestException('Could not parse response.');
     }
     return new \DOMXPath($doc);
 }
Ejemplo n.º 30
0
 public function getPendingOrders($accountId, $maxId = 0, $count = 50, $instrument = 'all', array $ids = array())
 {
     $data = array();
     if ($maxId > 0) {
         $data['maxId'] = $maxId;
     }
     $data['amount'] = $count;
     $data['instrument'] = $instrument;
     $data['ids'] = implode("%2C", $ids);
     $orders = \Requests::get($this->getUrl() . '/accounts/' . $accountId . '/orders', array('Authorization' => 'Bearer ' . $this->getToken()), $data);
     $this->checkAnswer($orders);
     return $orders;
 }