예제 #1
2
 public function getCost($origin, $destination, $weight, $courier, $originType = NULL, $destinationType = NULL)
 {
     $params = array('origin' => $origin, 'destination' => $destination, 'weight' => $weight, 'courier' => CourierType::getCode($courier));
     if (!is_null($originType)) {
         $params['originType'] = LocationType::getCode($originType);
     }
     if (!is_null($destinationType)) {
         $params['destinationType'] = LocationType::getCode($destinationType);
     }
     return \Unirest::post($this->getEndPoint() . "cost", $this->getHeader(), http_build_query($params))->body->rajaongkir->results;
 }
 protected function makeRequest($query, $tags)
 {
     $url = 'https://graph.facebook.com/search?locale=en_US&type=post&access_token=' . $_SESSION['FBToken'] . '&q=' . urlencode($query);
     $response = Unirest::get($url)->body;
     $tags = array('facebook', 'public', 'facebook,public');
     foreach ($response->data as $postData) {
         if (property_exists($postData, 'message')) {
             $this->addPost($postData->message, $tags);
         }
     }
 }
예제 #3
1
function get($app, $endpoint)
{
    $parameters = ['key' => STEAM_WEB_API_KEY];
    foreach ($app->request->get() as $key => $value) {
        $parameters[$key] = $value;
    }
    $response = Unirest::get(STEAM_WEB_API_BASE_URL . $endpoint, NULL, $parameters);
    $app->response->setStatus($response->code);
    foreach ($response->headers as $key => $value) {
        if ($key === 'Content-Encoding') {
            continue;
        }
        $app->response->headers->set($key, $value);
    }
    echo $response->raw_body;
}
예제 #4
1
 *
 * Provides a demo of the use of the ShipStation API Wrapper.
 *
 * @package     Public
 * @subpackage  ShipStation
 * @author      Otoniel Ortega <*****@*****.**>
 * @copyright   2014 Otoniel Ortega (c)
 * @version     1.0
 * @licence     The MIT License (MIT)
 *
 */
// Load required libraries //
require_once 'libraries/unirest/Unirest.php';
require_once 'libraries/shipstation/Shipstation.class.php';
// Disables Unirest SSL validation //
Unirest::verifyPeer(false);
// Initialize ShipStation ==================================== //
$shipStation = new Shipstation();
$shipStation->setSsApiKey('{Your ShipStation API Key Here}');
$shipStation->setSsApiSecret('{Your ShipStation API Secret Here}');
// Define API methods to test ================================ //
// Note: Set to true the methods you want to test //
// Warehouses related methods //
$testGetWarehouses = true;
// Stores related methods //
$testGetStores = false;
// Order related methods //
$testGetOrders = false;
$testGetOrder = false;
$testAddOrder = false;
$testDeleteOrder = false;
 public function report(Report $report)
 {
     $form = $report->toWebFormat();
     $form['api_user'] = $this->api_user;
     $form['api_key'] = $this->api_key;
     $response = \Unirest::post($report->getUrl(), array(), $form);
     return $response->body;
 }
예제 #6
0
 public function testFacebookRequiresAuth()
 {
     $url = 'https://graph.facebook.com/search?locale=en_US&type=post&q=test';
     $response = Unirest::get($url)->body;
     $response = json_decode($response);
     $this->assertTrue(property_exists($response, 'error'));
     $this->assertTrue($response->error->code == 200);
 }
예제 #7
0
 public function getFullResponseObject($request)
 {
     $request = $this->request_encryption ? $this->requestEncrypt($request) : base64_encode(json_encode($request));
     $respond = parent::get(API_URL . "/{$this->client_name}/{$this->api_name}/{$this->api_version}/{$request}", NULL, NULL, $this->HTML_username, $this->HTML_password);
     if ($this->respond_decryption) {
         $respond->body->decrypted_data = $this->respondDecrypt($respond->body->encrypted_data);
         unset($respond->body->encrypted_data);
     }
     return $respond;
 }
예제 #8
0
function event_info($r_url)
{
    $production_id = explode("-", $r_url);
    $production_id = end($production_id);
    $production_id = explode(".", $production_id);
    $production_id = $production_id[0];
    $json_url = "http://www.vividseats.com/javascript/tickets.shtml?productionId=" . $production_id;
    $event_data = Unirest::GET($json_url);
    echo $event_data->raw_body;
}
예제 #9
0
/** Accepts a json containing the results of a user_timeline 
    Twitter query and the height and width of the word cloud
    to be generated **/
function generateWordCloud($json, $height, $width)
{
    $text = '';
    foreach ($json as $tweet) {
        $text .= ' ';
        $text .= $tweet['text'];
    }
    require_once 'Unirest.php';
    $response = Unirest::post("https://gatheringpoint-word-cloud-maker.p.mashape.com/index.php", array("X-Mashape-Authorization" => "OkVWcztYb4IzHPzPd41C7uo1xWWaaB1s"), array("height" => $height, "textblock" => $text, "width" => $width, "config" => "n\\/a"));
    return $response->body->url;
}
예제 #10
0
 public static function upload($b64)
 {
     $url = self::absoluteUrl('post');
     $response = @\Unirest::post($url, ["Accept" => "application/json"], ["img" => $b64]);
     //        $response->code; // HTTP Status code
     //        $response->headers; // Headers
     //        $response->raw_body; // Unparsed body
     $data = $response->body;
     // Parsed body
     return new self($data->objectid, $data->original_size->original_width, $data->original_size->original_height);
 }
예제 #11
0
 private function searchNearbyFromBaiduMapResponse($word = '', $radius = 2000)
 {
     $url = "http://api.map.baidu.com/geosearch/v2/nearby?";
     $url .= 'location=' . $this->location_Y . ',' . $this->location_X;
     $url .= '&geotable_id=' . self::BAIDUMAP_DATABOX;
     $url .= '&q=' . $word;
     $url .= '&radius=' . $radius;
     $url .= '&filter=ecid|' . $this->ecid . ',' . $this->ecid;
     $url .= '&ak=' . self::BAIDUMAP_AK;
     Vendor('Unirest.Unirest');
     return \Unirest::get($url, array("Accept" => "application/json"));
 }
예제 #12
0
 public function send(SendGrid\Email $email)
 {
     $form = $email->toWebFormat();
     $form['api_user'] = $this->api_user;
     $form['api_key'] = $this->api_key;
     // option to ignore verification of ssl certificate
     if (isset($this->options['turn_off_ssl_verification']) && $this->options['turn_off_ssl_verification'] == true) {
         \Unirest::verifyPeer(false);
     }
     $response = \Unirest::post($this->url, array('User-Agent' => 'sendgrid/' . $this->version . ';php'), $form);
     return $response->body;
 }
예제 #13
0
파일: SendGrid.php 프로젝트: a4ther/SOIN
 public function send(SendGrid\Email $email)
 {
     $form = $email->toWebFormat();
     $form['api_user'] = $this->username;
     $form['api_key'] = $this->password;
     // option to ignore verification of ssl certificate
     if (isset($this->options['turn_off_ssl_verification']) && $this->options['turn_off_ssl_verification'] == true) {
         \Unirest::verifyPeer(false);
     }
     $response = \Unirest::post($this->url, array(), $form);
     return $response->body;
 }
예제 #14
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     while (true) {
         $date = new DateTime();
         $games = Game::whereRaw('date < ? && winner_id IS NULL', array(new DateTime()))->get();
         if (count($games) > 0) {
             $response = Unirest::get("http://live.mobileapp.fifa.com/api/wc/matches");
             foreach ($games as $value) {
                 //On regarde tout les matchs de la liste retourné par l'API
                 foreach ($response->body->data->second as $match) {
                     //Si le match corespond a celui qu'on veut mettre à jour
                     if (isset($match->c_HomeNatioShort) && isset($match->c_AwayNatioShort) && $match->c_HomeNatioShort == $value->team1()->first()->code && $match->c_AwayNatioShort == $value->team2()->first()->code) {
                         //Si le match à commencé
                         if ($match->b_Started == true) {
                             $value->team1_goals = $match->n_HomeGoals;
                             $value->team2_goals = $match->n_AwayGoals;
                             $this->info('[' . $date->format('Y-m-d H:i:s') . '] MAJ scores : ' . $value->team1()->first()->name . ' ' . $value->team1_goals . '-' . $value->team2_goals . ' ' . $value->team2()->first()->name . '.');
                         }
                         if ($match->b_Finished == true) {
                             if ($value->team1_goals > $value->team2_goals) {
                                 $value->setFinished(1);
                                 $this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team1()->first()->name . ' gagnant.');
                             } else {
                                 if ($value->team1_goals < $value->team2_goals) {
                                     $value->setFinished(2);
                                     $this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team2()->first()->name . ' gagnant.');
                                 } else {
                                     if ($value->team1_goals == $value->team2_goals) {
                                         $value->team1_kick_at_goal = $match->n_HomeGoalsShootout;
                                         $value->team2_kick_at_goal = $match->n_AwayGoalsShootout;
                                         if ($match->n_HomeGoalsShootout > $match->n_AwayGoalsShootout) {
                                             $value->setFinished(1);
                                             $this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team1()->first()->name . ' gagnant.');
                                         } else {
                                             $value->setFinished(2);
                                             $this->info('[' . $date->format('Y-m-d H:i:s') . '] Match fini : ' . $value->team2()->first()->name . ' gagnant.');
                                         }
                                     }
                                 }
                             }
                         }
                         break;
                     }
                 }
                 $value->save();
             }
         } else {
             $this->info('[' . $date->format('Y-m-d H:i:s') . '] Aucun match à surveiller.');
         }
         sleep(50);
     }
 }
예제 #15
0
 public static function request($httpMethod, $url, $body = NULL, $headers = array(), $username = NULL, $password = NULL)
 {
     if (!is_array($body) && $body !== NULL) {
         $body = json_decode($body, true);
     }
     if ($httpMethod != 'GET') {
         if (is_array($body) || $body instanceof Traversable) {
             Unirest::http_build_query_for_curl($body, $postBody);
         }
     } elseif (is_array($body)) {
         if (strpos($url, '?') !== false) {
             $url .= "&";
         } else {
             $url .= "?";
         }
         Unirest::http_build_query_for_curl($body, $postBody);
         $url .= urldecode(http_build_query($postBody));
     }
     $response = new \stdClass();
     $response->body = new \stdClass();
     //metadata injection
     $response->body->_meta = array('status' => "SUCCESS", 'offset' => 0, 'count' => 20, 'total' => 21, 'links' => array());
     //response headers
     $response->headers = array('Status' => '200 OK', 'Connection' => 'Keep-Alive');
     $response->code = 200;
     // Error Triggering via params
     $showError = false;
     if (is_array($body)) {
         foreach ($body as $key => $value) {
             if ($key == 'showError' && $value == '1') {
                 $showError = true;
             }
             if ($key == 'showLinks' && $value == '1') {
                 $response->body->_meta['links'] = array('next' => array('method' => $httpMethod, 'uri' => 'http://someuri.com'));
             }
         }
     }
     if ($showError) {
         $response->code = 404;
         $response->headers['Status'] = '404 Not Found';
         $response->body->_meta['status'] = "ERROR";
         $response->body->_meta['httpMethod'] = $httpMethod;
         $response->body->_meta['url'] = $url;
     }
     // End Error triggering
     $response->body->records = array('httpMethod' => $httpMethod, 'url' => $url, 'body' => $body, 'headers' => $headers, 'username' => $username, 'password' => $password);
     return $response;
 }
예제 #16
0
 public function call($text)
 {
     $url = $this->service()->first()->root;
     $url .= "/" . $this->name . "/";
     $params = $this->parameters;
     $pArray = array();
     foreach ($params as $p) {
         if ($p->defaultValue) {
             $pArray[$p->name] = $p->defaultValue;
         }
     }
     $textParam = $this->parameters()->where('defaultValue', '=', 'NULL')->first();
     // $pArray[]
     $pArray[$textParam->name] = $text;
     $response = Unirest::post($url, array("Accept" => $this->httpHeaders), $pArray);
     $responseObj = json_decode($response->raw_body);
     return $responseObj;
 }
예제 #17
0
 public function get_metacritic_page($game_name)
 {
     $returnValue = "";
     # convert spaces to -
     $game_name = str_replace(' ', '-', $game_name);
     # Remove &<space>
     $game_name = str_replace('& ', '', $game_name);
     # lowercase
     $game_name = strtolower($game_name);
     # Remove all special chars execept a-z, digits, --sign, ?-sign, !-sign
     $game_name = preg_replace('/[^a-z\\d\\?!\\-]/', '', $game_name);
     # Get the webpage
     $response = Unirest::get("http://www.metacritic.com/game/pc/" . $game_name);
     if ($response->code == 200) {
         $returnValue = $response->raw_body;
     }
     return $returnValue;
 }
예제 #18
0
    public function make_request($options) {
        $injector = Injector::getInstance();
        
        $url = $options['url'];
        $method = $options['method'];
        $headers = $options['headers'];
        $body = isset($options['body']) ? $options['body'] : '';
        $response = null;
        if (isset($options['qs'])) {
            $qs = http_build_query($options['qs']);
            $url.= '?' . $qs;
        }
        $url = str_replace('%2C', ',', $url);

        \Unirest::verifyPeer($injector->ssl_verification);
        if ($options['method'] == 'GET') {
            $response = \Unirest::get($url, $headers);
        }
        
        if ($options['method'] == 'POST') {
            $response = \Unirest::post($url, $headers, $body);
        }
        
        if ($options['method'] == 'PUT') {
            $response = \Unirest::put($url, $headers, $body);
        }
        
        if ($options['method'] == 'DELETE') {
            $response = \Unirest::delete($url, $headers);
        }
        
        if ($options['method'] == 'PATCH') {
            $response = \Unirest::patch($url, $headers, $body);
        }

        return $response;
    }
예제 #19
0
 /**
  * Send a cURL request
  * @param  string $httpMethod 		HTTP Method to use (based off \Unirest\HttpMethod constants)
  * @param  string $url        		URL to send the request to
  * @param  mixed  $body       		Request body
  * @param  array  $headers    		Additional headers to send
  * @throws Exception 				If a cURL error occurs
  * @return \Unireset\HttpResponse 	\Unirest\HttpResponse object
  */
 private static function request($httpMethod, $url, $body = NULL, $headers = array())
 {
     $lowercaseHeaders = array();
     foreach ($headers as $key => $val) {
         $key = trim(strtolower($key));
         if ($key == "user-agent" || $key == "expect") {
             continue;
         }
         $lowercaseHeaders[] = $key . ": " . $val;
     }
     $lowercaseHeaders[] = "user-agent: unirest-php/1.0";
     $lowercaseHeaders[] = "expect:";
     $ch = curl_init();
     if ($httpMethod != HttpMethod::GET) {
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
     }
     curl_setopt($ch, CURLOPT_URL, Unirest::encodeUrl($url));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $lowercaseHeaders);
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $response = curl_exec($ch);
     $error = curl_error($ch);
     if ($error) {
         throw new \Exception($error);
     }
     // Split the full response in its headers and body
     $curl_info = curl_getinfo($ch);
     $header_size = $curl_info["header_size"];
     $header = substr($response, 0, $header_size);
     $body = substr($response, $header_size);
     $httpCode = $curl_info["http_code"];
     return new HttpResponse($httpCode, $body, $header);
 }
예제 #20
0
 /**
  * ----------------------------------------------------
  *  getStores()
  * ----------------------------------------------------
  * 
  * Get list of stores availables.
  * 
  * @return Array $stores
  */
 public function getStores()
 {
     // Enforce API requests cap //
     $this->enforceApiRateLimit();
     $response = Unirest::get($this->endpoint . $this->methodsPaths['getStores'], array("Authorization" => $this->authorization));
     return $this->processReply($response);
 }
예제 #21
0
 /**
  * Fungsi untuk mendapatkan data status pengiriman
  * @param integer $waybill no resi pengiriman 
  * @param string $courier Kode kurir
  * @return object Object yang berisi informasi response, terdiri dari: code, headers, body, raw_body.
  */
 function getWaybill($waybill, $courier)
 {
     $params = array('waybill' => $waybill, 'courier' => $courier);
     return \Unirest::post(self::$base_url . "waybill", array(), http_build_query($params));
 }
예제 #22
0
 public static function enableSSL()
 {
     self::$useSSL = true;
     \Unirest::verifyPeer(true);
 }
예제 #23
0
function google_search($event_name, $event_date, $ticket_site)
{
    $url = "https://www.google.com/search?q=" . $event_name . " " . $event_date . " " . $ticket_site;
    $google_page_data = Unirest::GET($url);
    return $google_page_data->raw_body;
}
예제 #24
0
 /**
  * delPoi函数用于通过百度地图API删除指定的POI。
  * @param string $poi_ids POI编号
  * @return 由百度地图API响应的类
  * @author 李少年
  * @version 2013-07-07
  */
 public function delPoi($poi_id)
 {
     $url = "http://api.map.baidu.com/geodata/v3/poi/delete";
     $arrBase = array("ak" => self::BAIDUMAP_AK, "ids" => $poi_id, "geotable_id" => self::BAIDUMAP_DATABOX);
     Vendor('Unirest.Unirest');
     $response = \Unirest::post($url, array("Accept" => "application/json"), $arrBase);
     if ($response->body->status == 0) {
         $params['poiID'] = $poi_id;
         return 0;
     }
     return -1;
 }
예제 #25
0
 public function GetGiphyPictures($api_key, $searchterm)
 {
     $url = $this->getApi('giphy.search');
     $response = Unirest::get($url . 'q=' . $searchterm . '&api_key=' . $api_key . '&offset=0');
     return json_decode($response->raw_body, true);
 }
 /**
  * Delete one object
  * @param   string $pk    Required parameter: CustomerID
  * @return CustomersModel response from the API call*/
 public function DeleteOneCustomers($pk)
 {
     //prepare query string for API call
     $queryBuilder = Configuration::BASEURI . "/Customers/{pk}";
     //process optional query parameters
     APIHelper::appendUrlWithTemplateParameters($queryBuilder, array("pk" => $pk));
     //validate and preprocess url
     $queryUrl = APIHelper::cleanUrl($queryBuilder);
     //prepare headers
     $headers = array("User-Agent" => @"APIMATIC 2.0", "Accept" => "application/json");
     //prepare API request
     $request = Unirest::delete($queryUrl, $headers);
     //and invoke the API call request to fetch the response
     $response = $request->getResponse();
     //Error handling using HTTP status codes
     if ($response->code < 200 || $response->code > 206) {
         //[200,206] = HTTP OK
         throw new APIException("HTTP Response Not OK", $response->code);
     }
     return $response->body;
 }
예제 #27
0
 public function testHttpBuildQueryWhenCurlFile()
 {
     $file = Unirest::file(dirname(__FILE__) . "/test_upload.txt");
     $body = array("to" => "*****@*****.**", "from" => "*****@*****.**", "file" => $file);
     Unirest::http_build_query_for_curl($body, $postBody);
     $this->assertEqual($postBody['file'], $file);
 }
<?php

require_once 'unirest-php/lib/Unirest.php';
$response = Unirest::post("http://app.monkeylearn.com/api/v1/categorizer/hDDngsX8/classify_text/", array("Authorization" => "token <YOUR TOKEN GOES HERE>"), array("text" => "This is a text to try language detection."));
print_r($response->code);
print_r($response->headers);
print_r($response->body);
?>
 
예제 #29
-1
 /**
  * Fungsi untuk mendapatkan data ongkos kirim
  * @param integer $origin ID kota asal
  * @param integer $destination ID kota tujuan
  * @param integer $weight Berat kiriman dalam gram
  * @param string $courier Kode kurir, jika NULL maka tampilkan semua kurir
  * @return object Object yang berisi informasi response, terdiri dari: code, headers, body, raw_body.
  */
 function getCost($origin, $destination, $weight, $courier = NULL)
 {
     $params = array('origin' => $origin, 'destination' => $destination, 'weight' => $weight);
     if (!is_null($courier)) {
         $params['courier'] = $courier;
     }
     return \Unirest::post(RajaOngkir::$base_url . "cost", array(), http_build_query($params));
 }
예제 #30
-1
 /**
  * Ensure that a URL is encoded and safe to use with cURL
  * @param  string $url URL to encode
  * @return string
  */
 private static function encodeUrl($url)
 {
     $url_parsed = parse_url($url);
     $scheme = $url_parsed['scheme'] . '://';
     $host = $url_parsed['host'];
     $port = isset($url_parsed['port']) ? $url_parsed['port'] : null;
     $path = isset($url_parsed['path']) ? $url_parsed['path'] : null;
     $query = isset($url_parsed['query']) ? $url_parsed['query'] : null;
     if ($query != null) {
         $query = '?' . http_build_query(Unirest::getArrayFromQuerystring($url_parsed['query']));
     }
     if ($port && $port[0] != ":") {
         $port = ":" . $port;
     }
     $result = $scheme . $host . $port . $path . $query;
     return $result;
 }