コード例 #1
0
ファイル: inc.request.php プロジェクト: rellla/djkclient
function send_request2($url, $method = "get", $input = null)
{
    $client = new RESTClient();
    if ($method == "post") {
        $result = $client->post($url, $input);
    } elseif ($method == "get") {
        $result = $client->get($url, $input);
    } else {
        $result = "Error: no method specified";
    }
    return $result;
}
コード例 #2
0
function send_request($url, $method = "get", $input = null)
{
    global $restservicedir;
    $address = $restservicedir . $url;
    $client = new RESTClient();
    if ($method == "post") {
        $result = $client->post($address, $input);
    } elseif ($method == "get") {
        $result = $client->get($address, $input);
    } else {
        $result = "Error: no method specified";
    }
    return $result;
}
コード例 #3
0
 /**
  * Reload the REST information.
  * This is only a empty placeholder. The child class can override it.
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.0.0
  * @since 0.0.1 Use HTTPRequestMethod enum.
  * @since 0.1.0 Use a default Locale.
  * @since 0.1.1 Unstatic every attributes.
  */
 private function load()
 {
     // if the REST path empty -> this is the not the implementation or can't get something else
     if (InputValidator::isEmpty(self::RESTPATH) || !RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         return;
     }
     $content = RESTClient::sendWithLocalization(self::RESTPATH, Locales::getLocale());
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         return;
     }
     // reset values
     $this->resetValues();
     if (!InputValidator::isEmptyArrayKey($content, "name")) {
         $this->NAME = $content["name"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "navigationCaption")) {
         $this->NAVIGATIONCAPTION = $content["navigationCaption"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "description")) {
         $this->DESCRIPTION = $content["description"];
     }
     // update timestamp when make the next request
     $timestamp = (int) (microtime(true) * 1000);
     $this->NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME;
 }
コード例 #4
0
 /**
  * This function gets the product images.
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.1.0
  * @since 0.1.1 Fix bug with nonsetted product URL and delete reload functionality.
  * @since 0.1.1 Use unstatic variables.
  * @api
  * @param String $productID The product ID to get images.
  */
 private function load($productID)
 {
     // if parameter is wrong or GET is blocked
     if (!InputValidator::isProductId($productID) || !RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         return;
     }
     $content = RESTClient::send("products/" . $productID . "/" . self::RESTPATH);
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         return;
     }
     // if there is items
     if (InputValidator::isEmptyArrayKey($content, "items")) {
         Logger::error("Respond for product/" . $productID . "/" . self::RESTPATH . " can not be interpreted.");
         return;
     }
     // is there any images found: load the images.
     foreach ($content['items'] as $number => $image) {
         // parse every image size
         if (!InputValidator::isEmptyArrayKey($image, "sizes")) {
             $object = null;
             foreach ($image["sizes"] as $size) {
                 // if there is "url" and "classifier" set in the image
                 if (!InputValidator::isEmptyArrayKey($size, "url") && !InputValidator::isEmptyArrayKey($size, "classifier")) {
                     $object[$size["classifier"]] = $size["url"];
                 }
             }
             // if all needed sizes are available, save it
             if (!InputValidator::isEmptyArrayKey($object, "Thumbnail") && !InputValidator::isEmptyArrayKey($object, "Small") && !InputValidator::isEmptyArrayKey($object, "HotDeal") && !InputValidator::isEmptyArrayKey($object, "MediumSmall") && !InputValidator::isEmptyArrayKey($object, "Medium") && !InputValidator::isEmptyArrayKey($object, "MediumLarge") && !InputValidator::isEmptyArrayKey($object, "Large")) {
                 array_push($this->images, $object);
             }
         }
     }
 }
コード例 #5
0
 /**
  * Gets the default and possible currencies of the shop.
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.0.0
  * @since 0.1.0 Use HTTPRequestMethod enum
  * @since 0.1.0 Save timestamp of the last request.
  * @since 0.1.0 Add configured used Currency.
  * @api
  */
 private static function load()
 {
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         return;
     }
     $content = RESTClient::send(self::RESTPATH);
     // if respond is empty or there are no default AND items element
     if (InputValidator::isEmptyArrayKey($content, "default") || InputValidator::isEmptyArrayKey($content, "items")) {
         Logger::error("Respond for " . self::RESTPATH . " can not be interpreted.");
         return;
     }
     // reset values
     self::resetValues();
     // save the default currency
     self::$DEFAULT = $content["default"];
     // parse the possible currencies
     self::$ITEMS = $content["items"];
     // set the configured shop Locale if it is empty.
     if (InputValidator::isEmpty(self::$USED)) {
         self::$USED = $content["default"];
     }
     // update timestamp when make the next request
     $timestamp = (int) (microtime(true) * 1000);
     self::$NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME;
 }
コード例 #6
0
function apiCall($url, $data, $method, $usertoken, $tokenkey)
{
    $rtn = RESTClient::init($url)->params($data)->headers(array('User-Token:' . $usertoken, 'User-TokenKey:' . $tokenkey))->{$method}();
    $response = json_decode($rtn, true);
    unset($rtn);
    return $response;
}
コード例 #7
0
 public function __construct($config)
 {
     $this->_config = $config;
     /*if(empty($this->_config->APIURL) || empty($this->_config->APIKey) || empty($this->_config->SecretKey)){
           throw new exception('Invalid API URL or API key or Secret key, please check config.inc.php');
       }*/
     parent::__construct();
 }
コード例 #8
0
 /**
  * construct function
  *
  * @author tom.wang<*****@*****.**>
  */
 public function __construct()
 {
     global $config;
     parent::__construct();
     $this->_config = $config;
     if (empty($this->_config->AUTHORIZEURL) || empty($this->_config->ACCESSTOKENURL) || empty($this->_config->SESSIONKEYURL) || empty($this->_config->CALLBACK)) {
         throw new exception('Invalid AUTHORIZEURL or ACCESSTOKENURL or SESSIONKEYURL or CALLBACK, please check config.inc.php');
     }
 }
コード例 #9
0
 /**
  * @group utility
  */
 function testSend()
 {
     @RESTClient::setRequestMethod();
     @RESTClient::connect("www.google.de", "Shopname", "AuthToken");
     $this->assertNull(@RESTClient::send("locale"));
     @RESTClient::setRequestMethod("NOTVALID");
     $this->assertNull(@RESTClient::send("locale"));
     @RESTClient::disconnect();
     @RESTClient::setRequestMethod("GET");
     $this->assertNull(@RESTClient::send("locale"));
     @RESTClient::setRequestMethod("NOTVALID");
     $this->assertNull(@RESTClient::send("locale"));
 }
コード例 #10
0
 /**
  * Reload the REST information.
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.0.0
  * @since 0.0.1 Use HTTPRequestMethod enum.
  * @since 0.1.0 Use a default Locale.
  */
 private static function load()
 {
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         return;
     }
     $content = RESTClient::sendWithLocalization(self::$RESTPATH, Locales::getLocale());
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         return;
     }
     // reset values
     self::resetValues();
     if (!InputValidator::isEmptyArrayKey($content, "name")) {
         self::$NAME = $content["name"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "title")) {
         self::$TITLE = $content["title"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "navigationCaption")) {
         self::$NAVIGATIONCAPTION = $content["navigationCaption"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "shortDescription")) {
         self::$SHORTDESCRIPTION = $content["shortDescription"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "description")) {
         self::$DESCRIPTION = $content["description"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "company")) {
         self::$COMPANY = $content["company"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "contactPerson")) {
         self::$CONTACTPERSON = $content["contactPerson"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "contactPersonJobTitle")) {
         self::$CONTACTPERSONJOBTITLE = $content["contactPersonJobTitle"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "address")) {
         self::$ADDRESS = $content["address"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "phone")) {
         self::$PHONE = $content["phone"];
     }
     if (!InputValidator::isEmptyArrayKey($content, "email")) {
         self::$EMAIL = $content["email"];
     }
     // update timestamp when make the next request
     $timestamp = (int) (microtime(true) * 1000);
     self::$NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::NEXT_RESPONSE_WAIT_TIME;
 }
コード例 #11
0
ファイル: RenRenClient.class.php プロジェクト: yunsite/snshub
 public function __construct()
 {
     parent::__construct();
     $this->_config = new stdClass();
     $this->_config->APIURL = 'http://api.xiaonei.com/restserver.do';
     //RenRen网的API调用地址,不需要修改
     $this->_config->APIVersion = '1.0';
     //当前API的版本号,不需要修改
     $this->_config->decodeFormat = 'json';
     //默认的返回格式,根据实际情况修改,支持:json,xml
     /*
      *@ 以下接口内容来自http://wiki.dev.renren.com/wiki/API,编写时请遵守以下规则:
      *  key  (键名)		: API方法名,直接Copy过来即可,请区分大小写
      *  value(键值)		: 把所有的参数,包括required及optional,除了api_key,method,v,format不需要填写之外,
      *					  其它的都可以根据你的实现情况来处理,以英文半角状态下的逗号来分割各个参数。
      */
     $this->_config->APIMapping = array('admin.getAllocation' => '', 'connect.getUnconnectedFriendsCount' => '', 'friends.areFriends' => 'uids1,uids2', 'friends.get' => 'page,count', 'friends.getFriends' => 'page,count', 'notifications.send' => 'to_ids,notification', 'users.getInfo' => 'uids,fields');
 }
コード例 #12
0
 /**
  * Gets the default and possible locales of the shop.
  */
 private static function load()
 {
     // if request method is blocked
     if (!RESTClient::setRequestMethod("GET")) {
         return;
     }
     $content = JSONParser::parseJSON(RESTClient::send(self::RESTPATH));
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         return;
     }
     // if there is no default AND items element
     if (!array_key_exists("default", $content) || !array_key_exists("items", $content)) {
         Logger::error("Respond for " . self::RESTPATH . " can not be interpreted.");
         return;
     }
     // reset values
     self::resetValues();
     // save the default localization
     self::$DEFAULT = $content["default"];
     // parse the possible localizations
     self::$ITEMS = $content["items"];
 }
コード例 #13
0
 /**
  * @group utility
  */
 function testSetRequestTime()
 {
     $this->assertFalse(RESTClient::setRequestWaitTime("NoInt"));
     $this->assertTrue(RESTClient::error());
     $this->assertEquals("RESTC-10", RESTClient::errorNumber());
     $this->assertFalse(RESTClient::setRequestWaitTime(-1));
     $this->assertTrue(RESTClient::error());
     $this->assertEquals("RESTC-10", RESTClient::errorNumber());
     $this->assertTrue(RESTClient::setRequestWaitTime(600));
     $this->assertFalse(RESTClient::error());
     $this->assertNull(RESTClient::errorNumber());
 }
コード例 #14
0
 /**
  * Get soap clients for all good storages
  *
  * @return array RESTClient for all good storages
  */
 protected function getClients()
 {
     $clients = array();
     $user = User::getInstance();
     $uid = $user->getId();
     $mac = $user->getMac();
     if ($mac) {
         RESTClient::$from = $mac;
     } elseif ($uid) {
         RESTClient::$from = $uid;
     } else {
         RESTClient::$from = $this->stb->mac;
     }
     RESTClient::setAccessToken($this->createAccessToken());
     foreach ($this->storages as $name => $storage) {
         $clients[$name] = new RESTClient('http://' . $storage['storage_ip'] . '/stalker_portal/storage/rest.php?q=');
     }
     return $clients;
 }
コード例 #15
0
 /**
  * This function gets the product images.
  *
  * @author David Pauli <*****@*****.**>
  * @param String $productID The product ID to get images.
  * @since 0.1.0
  * @since 0.1.1 Fix bug with nonsetted product URL and delete reload functionality.
  * @since 0.1.1 Use unstatic variables.
  * @since 0.1.2 Add error reporting.
  * @since 0.2.1 Implement REST client fixes.
  */
 private function load($productID)
 {
     // if parameter is wrong
     if (!InputValidator::isProductId($productID)) {
         $this->errorSet("PS-1");
         Logger::warning("ep6\\ProductSlideshow\nInvalid product ID " . $productId . " to load slideshow.");
         return;
     }
     // if GET is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         $this->errorSet("RESTC-9");
         return;
     }
     RESTClient::send("products/" . $productID . "/" . self::RESTPATH);
     $content = RESTClient::getJSONContent();
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         $this->errorSet("PS-2");
         Logger::warning("ep6\\ProductSlideshow\nEmpty response while getting product slideshow.");
         return;
     }
     // if there is items
     if (InputValidator::isEmptyArrayKey($content, "items")) {
         $this->errorSet("PS-3");
         Logger::error("Respond for product slidehows can not be interpreted.");
         return;
     }
     // is there any images found: load the images.
     foreach ($content['items'] as $number => $image) {
         // parse every image size
         if (!InputValidator::isEmptyArrayKey($image, "sizes")) {
             $object = null;
             foreach ($image["sizes"] as $size) {
                 // if there is "url" and "classifier" set in the image
                 if (!InputValidator::isEmptyArrayKey($size, "url") && !InputValidator::isEmptyArrayKey($size, "classifier")) {
                     $object[$size["classifier"]] = $size["url"];
                 }
             }
             // if all needed sizes are available, save it
             if (!InputValidator::isEmptyArrayKey($object, "Thumbnail") && !InputValidator::isEmptyArrayKey($object, "Small") && !InputValidator::isEmptyArrayKey($object, "HotDeal") && !InputValidator::isEmptyArrayKey($object, "MediumSmall") && !InputValidator::isEmptyArrayKey($object, "Medium") && !InputValidator::isEmptyArrayKey($object, "MediumLarge") && !InputValidator::isEmptyArrayKey($object, "Large")) {
                 array_push($this->images, $object);
             }
         }
     }
 }
コード例 #16
0
 public function execute($action)
 {
     $msgs = Localization::getInstance();
     $forwards = $action->getForwards();
     // Recebe os valores enviados
     $roomCourse = $_POST["group"];
     $roomManager = $_POST['manager'];
     $userName = utf8_decode($_POST["name"]);
     $userEmail = $_POST["email"];
     $userPasswordPlataform = "mude";
     if (!empty($roomCourse) && !empty($roomManager) && !empty($userName) && !empty($userEmail)) {
         /**
          * Routine that checks which the browser used
          * If an error occurs during the login, the system should return to the previous page
          * If the browser used is Firefox, the system must go back two pages
          * If is Chrome should back 1 page
          * TODO Test with Internet Explorer
          */
         $useragent = $_SERVER['HTTP_USER_AGENT'];
         if (preg_match('|Firefox/([0-9\\.]+)|', $useragent, $matched)) {
             $browser_version = $matched[1];
             $browser = 'Firefox';
             $numReturnPages = 2;
         } else {
             $numReturnPages = 1;
         }
         /**
          * Via rest, it checks if this tool (in this case the Whiteboard)
          * have permission to use information from the Core
          */
         $host = $_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"];
         $pass = md5(date("d/m/Y") . $host);
         $server = "http://code.inf.poa.ifrs.edu.br/core/index.php/rest";
         $action = str_replace("%40", "@", $userEmail);
         $rest = new RESTClient();
         $rest->initialize(array('server' => $server, 'http_user' => $host, 'http_pass' => $pass));
         $granted = $rest->get($action);
         if ($granted == 1) {
             // Caso o usuário esteja cadastrado na Plataform
             // CHECKING USER IN WHITEBOARD
             $user = $this->dao->login($userEmail, $userPasswordPlataform);
             if (count($user) <= 0) {
                 // Not in database, create new user
                 if (!empty($userEmail) && !empty($userName)) {
                     // Instantiates a new user;
                     $user = new User();
                     $user->setName($userName);
                     $user->setEmail($userEmail);
                     $user->setPassword($userPasswordPlataform);
                     $user->setRoomcreator(0);
                     $resultUser = $this->dao->saveNewUser($user);
                     $user = $this->dao->login($userEmail, $userPasswordPlataform);
                 }
             }
             if ($user->getName() != $userName) {
                 // Upadate user;
                 $resultUser = $this->dao->updateUserName($user->getUserId(), $userName);
             }
             // User contained in the database, loggin
             $_SESSION['id'] = $user->getUserId();
             $_SESSION['name'] = $user->getName();
             $_SESSION['roomCreator'] = $user->getRoomcreator();
             $_SESSION['email'] = $user->getEmail();
             $_SESSION['user'] = $user;
             // Verifies and creates, if necessary, the room of course
             $roomPlataform = $this->dao->getRoomByCourse($roomCourse);
             if (count($roomPlataform) <= 0) {
                 $roomName = "Turma: " . $roomCourse;
                 if ($user->getEmail() == $roomManager) {
                     $managerId = $user->getUserId();
                 } else {
                     $manager = $this->dao->login($roomManager, $userPasswordPlataform);
                     if (count($manager) <= 0) {
                         // Not in database, create new user coordinator
                         $manager = new User();
                         $manager->setName("Professor " . $roomCourse);
                         $manager->setEmail($roomManager);
                         $manager->setPassword($userPasswordPlataform);
                         $manager->setRoomcreator(1);
                         $resultManager = $this->dao->saveNewUser($manager);
                         $manager = $this->dao->login($manager->getEmail(), $userPasswordPlataform);
                     }
                     $managerId = $manager->getUserId();
                 }
                 // Instantiates a new room;
                 $roomPlataform = new Room();
                 $roomPlataform->setName($roomName);
                 $roomPlataform->setUserId($managerId);
                 $roomPlataform->setActive(0);
                 $roomPlataform->setActiveProduction(0);
                 $roomPlataform->setCourse($roomCourse);
                 $resultRoom = $this->dao->saveNewRoom($roomPlataform);
                 $roomPlataform = $this->dao->getRoomByCourse($roomCourse);
                 // Set manager permission of room
                 $permission = new Permission();
                 $permission->setUserId($managerId);
                 $permission->setRoomId($roomPlataform->getRoomId());
                 $resultPermission = $this->dao->savePermission($permission);
             }
             // Checks permissions
             $permissions = $this->dao->listPermissions($roomPlataform->getRoomId());
             $havePermission = false;
             foreach ($permissions as $permission) {
                 if ($permission->getUserId() == $user->getUserId()) {
                     $havePermission = true;
                 }
             }
             if (!$havePermission) {
                 $permission = new Permission();
                 $permission->setUserId($user->getUserId());
                 $permission->setRoomId($roomPlataform->getRoomId());
                 $resultPermission = $this->dao->savePermission($permission);
             }
             $roomPlataform = $this->dao->getRoomByCourse($roomCourse);
             $_SESSION['plataform'] = true;
             unset($_POST["group"]);
             unset($_POST['manager']);
             unset($_POST["name"]);
             unset($_POST["email"]);
             // If the room is active, will be given a join
             if ($roomPlataform->getActive() == 1) {
                 $_SESSION["idRoom"] = $roomPlataform->getRoomId();
                 $room = $this->dao->getRoom($roomPlataform->getRoomId());
                 // put the production in the session
                 $idProduction = $room->getActiveProduction();
                 $_SESSION['idProduction'] = $idProduction;
                 $history = new History();
                 $history->setUserId($_SESSION["id"]);
                 $history->setProductionId($idProduction);
                 $history->setDate(date('Y-m-d'));
                 $resultHistory = $this->dao->saveHistory($history);
                 // Retrieving the users in the room
                 $_REQUEST["users"] = $this->dao->getRoomUsers($_SESSION['idProduction']);
                 // Showing the page
                 $this->pageController->run($forwards['success']);
             } else {
                 if ($user->getUserId() == $roomPlataform->getUserId()) {
                     // If it is not active and the user is the owner of the room, will be given a start in the room
                     $production = new Production();
                     $production->setCreationDate(date('Y-m-d'));
                     $production->setUpdateDate(date('Y-m-d'));
                     $production->setRoomId($roomPlataform->getRoomId());
                     $resultProduction = $this->dao->createProduction($production);
                     if ($resultProduction) {
                         $_SESSION['idProduction'] = $production->getProductionId();
                     }
                     $resultUpdateRoom = $this->dao->updateRoomState($roomPlataform->getRoomId(), true, $_SESSION['idProduction']);
                     if ($resultUpdateRoom) {
                         $_SESSION["idRoom"] = $roomPlataform->getRoomId();
                     }
                     $resultRoom = $this->dao->getRoom($roomPlataform->getRoomId());
                     if ($resultRoom) {
                         $_SESSION["currentRoomManager"] = $resultRoom->getUserId();
                     }
                     $history = new History();
                     $history->setUserId($_SESSION["id"]);
                     $history->setProductionId($_SESSION['idProduction']);
                     $history->setDate(date('Y-m-d'));
                     $resultHistory = $this->dao->saveHistory($history);
                     // Retrieving the users in the room
                     $_REQUEST["users"] = $this->dao->getRoomUsers($_SESSION['idProduction']);
                     $this->pageController->run($forwards['success']);
                 } else {
                     // Otherwise, the room is closed and the user must wait until she opens
                     unset($_SESSION['id']);
                     unset($_SESSION['name']);
                     unset($_SESSION['roomCreator']);
                     unset($_SESSION['email']);
                     unset($_SESSION['user']);
                     // Closed room
                     echo "<script type='text/javascript'>";
                     echo "alert('" . $msgs->getText('error.plataform.closeRoom') . "');";
                     // Without permission			echo "history.go(-{$numReturnPages});";
                     echo "</script>";
                 }
             }
         } else {
             // Without permission
             echo "<script type='text/javascript'>";
             echo "alert('" . $msgs->getText('error.plataform.withoutPermission') . "');";
             echo "history.go(-{$numReturnPages});";
             echo "</script>";
         }
     } else {
         // Insufficient data
         echo "<script type='text/javascript'>";
         echo "alert('" . $msgs->getText('error.plataform.insufficientData') . "');";
         echo "history.go(-{$numReturnPages});";
         echo "</script>";
     }
 }
コード例 #17
0
 /**
  * This function returns the products by using the product filter.
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.0.0
  * @since 0.1.0 Use a default Locale.
  * @since 0.1.1 Unstatic every attributes.
  * @api
  * @return Products[] Returns an array of products.
  */
 public function getProducts()
 {
     $parameter = $this->getParameter();
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         return;
     }
     $content = RESTClient::send(self::RESTPATH . "?" . $parameter);
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         return;
     }
     // if there is no results, page AND resultsPerPage element
     if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) {
         Logger::error("Respond for " . self::RESTPATH . " can not be interpreted.");
         return;
     }
     $products = array();
     // is there any product found: load the products.
     if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) {
         foreach ($content['items'] as $item) {
             $product = new Product($item);
             array_push($products, $product);
         }
     }
     return $products;
 }
コード例 #18
0
ファイル: Document.php プロジェクト: marklogic/mlphp
 /**
  * Create a Document object.
  *
  * @param RESTClient $client A REST client object.
  * @param string $uri A document URI.
  */
 public function __construct($client, $uri = null)
 {
     $this->client = $client;
     $this->logger = $client->getLogger();
     $this->uri = (string) $uri;
 }
コード例 #19
0
ファイル: renren.php プロジェクト: valency/love-profile
<?php

require_once "../../cgi-bin/common.php";
require_once './renren-api-php-sdk/RESTClient.class.php';
$str = file_get_contents("https://graph.renren.com/renren_api/session_key?oauth_token=" . $_POST["access_token"]);
$str = json_decode($str, true);
$session_key = $str["renren_token"]["session_key"];
$client = new RESTClient();
// Get user info
$time = time();
$data = array();
$data["api_key"] = "b51f02b7589141ada95efcd9d3168906";
$data["method"] = "users.getInfo";
$data["session_key"] = $session_key;
$data["v"] = "1.0";
$data["callid"] = $time;
$data["format"] = "json";
$data["fields"] = "uid,name,sex,star,zidou,vip,birthday,email_hash,tinyurl,headurl,mainurl,hometown_location,work_history,university_history";
$data["sig"] = md5("api_key=b51f02b7589141ada95efcd9d3168906callid=" . $time . "fields=" . $data["fields"] . "format=jsonmethod=" . $data["method"] . "session_key=" . $session_key . "v=1.0f5e9fac903da4c37ac500a53789a5535");
$res = $client->_POST('http://api.renren.com/restserver.do', $data);
echo json_encode($res);
// Get user id
$res = json_decode(json_encode($res), true);
$uid = $res[0]["uid"];
// Insert userinfo into database
$query = "INSERT INTO RENREN VALUES ('" . $uid . "','" . urlencode(substr(json_encode($res), 1, sizeof($userinfo) - 3)) . "');";
$res = mysql_query($query, $dblink);
// Insert token into database
$query = "INSERT INTO RENREN_TOKENS VALUES ('" . $uid . "','" . urlencode($_POST["access_token"]) . "');";
$res = mysql_query($query, $dblink);
// Get friends list
コード例 #20
0
 public function _request($url, $method, $body, $content_type = null)
 {
     $rest = new RESTClient($this->key, $this->secret, $content_type);
     $rest->createRequest($url, $method, $body);
     $rest->sendRequest();
     $response = $rest->getResponse();
     if ($response[0] == 401) {
         throw new Unauthorized();
     }
     return $response;
 }
コード例 #21
0
 public static function setAccessToken($token)
 {
     self::$access_token = $token;
 }
コード例 #22
0
 /**
  * This function returns the products by using the product filter.
  *
  * @author David Pauli <*****@*****.**>
  * @return Product[] Returns an array of products.
  * @since 0.0.0
  * @since 0.1.0 Use a default Locale.
  * @since 0.1.1 Unstatic every attributes.
  * @since 0.1.2 Add error reporting.
  * @since 0.1.3 Get all results.
  * @since 0.2.0 Set error message for empty responses to notify.
  * @since 0.2.1 Implement REST client fixes.
  */
 public function getProducts()
 {
     $this->errorReset();
     $parameter = $this->getParameter();
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         $this->errorSet("RESTC-9");
         return;
     }
     RESTClient::send(self::RESTPATH . "?" . $parameter);
     $content = RESTClient::getJSONContent();
     // if respond is empty
     if (InputValidator::isEmpty($content)) {
         $this->errorSet("PF-8");
         Logger::notify("ep6\\ProductFilter\nREST respomd for getting products is empty.");
         return;
     }
     // if there is no results, page AND resultsPerPage element
     if (InputValidator::isEmptyArrayKey($content, "results") || InputValidator::isEmptyArrayKey($content, "page") || InputValidator::isEmptyArrayKey($content, "resultsPerPage")) {
         $this->errorSet("PF-9");
         Logger::error("ep6\\ProductFilter\nRespond for " . self::RESTPATH . " can not be interpreted.");
         return;
     }
     $this->results = $content['results'];
     $products = array();
     // is there any product found: load the products.
     if (!InputValidator::isEmptyArrayKey($content, "items") && sizeof($content['items']) != 0) {
         foreach ($content['items'] as $item) {
             $product = new Product($item);
             // go to every filter
             foreach ($this->filters as $filter) {
                 switch ($filter->getAttribute()) {
                     case 'stocklevel':
                         $value = array();
                         $value["stocklevel"] = $product->getStocklevel();
                         break;
                     case 'price':
                         $value = array();
                         $value["price"] = $product->getPrice()->getAmount();
                         break;
                     case 'category':
                         $value = array();
                         $value["category"] = $product->getCategories();
                         break;
                     default:
                         $value = $item;
                         break;
                 }
                 if (!InputValidator::isEmptyArrayKey($value, $filter->getAttribute()) || $filter->getOperator() == FilterOperation::UNDEF) {
                     if (!InputValidator::isArray($value[$filter->getAttribute()])) {
                         if (!$filter->isElementInFilter($value)) {
                             continue 2;
                         }
                     }
                 } else {
                     continue 2;
                 }
             }
             array_push($products, $product);
         }
     }
     return $products;
 }
コード例 #23
0
ファイル: Shop.class.php プロジェクト: dpauli/epages-rest-php
 /**
  * Loads the shop data.
  *
  * @author David Pauli <*****@*****.**>
  * @param Array $product The product in an array.
  * @since 0.1.3
  */
 private function load()
 {
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::GET)) {
         return;
     }
     $content = RESTClient::send();
     // if respond has no name, slogan, logoUrl, sfUrl and mboUrl
     if (InputValidator::isExistsArrayKey($content, "name") || InputValidator::isExistsArrayKey($content, "slogan") || InputValidator::isExistsArrayKey($content, "logoUrl") || InputValidator::isExistsArrayKey($content, "sfUrl") || InputValidator::isExistsArrayKey($content, "mboUrl")) {
         Logger::error("Respond for " . $this->shop . " can not be interpreted.");
         self::errorSet("C-1");
         return;
     }
     // reset values
     $this->resetValues();
     // save the attributes
     $this->name = $content['name'];
     $this->slogan = $content['slogan'];
     $this->logo = new Image($content['logoUrl']);
     $this->storefrontURL = new URL($content['sfUrl']);
     $this->backofficeURL = new URL($content['mboUrl']);
     // update timestamp when make the next request
     $timestamp = (int) (microtime(true) * 1000);
     $this->NEXT_REQUEST_TIMESTAMP = $timestamp + RESTClient::$NEXT_RESPONSE_WAIT_TIME;
 }
コード例 #24
0
 /**
  * Prints the connection status via "FORCE".
  */
 public function printStatus()
 {
     RESTClient::printStatus();
 }
コード例 #25
0
 /**
  * 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)
 {
     $response = CJSON::decode($this->rest->post('api/cost', ['origin' => $origin, 'destination' => $destination, 'weight' => $weight, 'courier' => $courier]));
     return isset($response['rajaongkir']['results']) ? $response['rajaongkir']['results'] : null;
 }
コード例 #26
0
ファイル: Util.php プロジェクト: andryluthfi/annotation-tools
 /**
  * Get soundcloud rest API from URL
  * @param type $url
  * @return type
  */
 public static function soundcloudRest($url)
 {
     $rest = new RESTClient();
     $rest->initialize(array('server' => 'http://api.soundcloud.com/'));
     $rest->option('SSL_VERIFYPEER', false);
     $soundcloud = $rest->get('resolve.json', array('url' => $url, 'client_id' => Yii::app()->params['soundcloud']['clientID']));
     return CJSON::decode($soundcloud);
 }
コード例 #27
0
 /**
  * Fungsi untuk melacak paket/nomor resi
  * 
  * @param string Nomor resi
  * @param string Kode kurir
  * @return string Response dari cURL, berupa string JSON balasan dari RajaOngkir
  */
 function waybill($waybill_number, $courier)
 {
     $params = array('waybill' => $waybill_number, 'courier' => $courier);
     $rest_client = new RESTClient($this->api_key, 'waybill', $this->account_type);
     return $rest_client->post($params);
 }
コード例 #28
0
 /**
  * Unsets an attribute value of the order.
  *
  * @author David Pauli <*****@*****.**>
  * @param String $path The path to this attribute.
  * @since 0.2.0
  * @since 0.2.1 Implement REST client fixes.
  */
 private function unsetAttribute($path)
 {
     // if PATCH does not work
     if (!RESTClient::setRequestMethod("PATCH")) {
         self::errorSet("RESTC-9");
         return;
     }
     $parameter = array("op" => "remove", "path" => $path);
     RESTClient::send(self::RESTPATH, $parameter);
     $orderParameter = RESTClient::getJSONContent();
     // update the product
     $this->parseData($orderParameter);
 }
コード例 #29
0
 /**
  * Deletes itself.
  *
  * Dont use this function. To delete a product its better to use $shop->deleteProduct($product).
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.1.0
  * @return boolean True if the deletion was successful, false if not.
  */
 public function delete()
 {
     // if request method is blocked
     if (!RESTClient::setRequestMethod(HTTPRequestMethod::DELETE)) {
         return false;
     }
     RESTClient::send(self::$RESTPATH . "/" . $this->productID);
     return true;
 }
コード例 #30
0
ファイル: Shop.class.php プロジェクト: Quaese/ep6client-php
 /**
  * The destructor for the main class.
  *
  * @author David Pauli <*****@*****.**>
  * @since 0.0.0
  * @since 0.1.1 Unset the own shop credentials.
  * @api
  * @source 2 1 Disconnect the REST client.
  */
 function __destruct()
 {
     $this->host = null;
     $this->shop = null;
     $this->authToken = null;
     $this->isssl = null;
     RESTClient::disconnect();
 }