Exemplo n.º 1
0
 public static function callRest($aConfig, $aData)
 {
     try {
         $sRawDataSign = '';
         foreach ($aData as $k => $v) {
             if ($k != 'checksum' && $k != 'addInfo' && $k != 'description') {
                 $sRawDataSign .= $v;
             }
         }
         $sign = sha1($sRawDataSign . $aConfig['key']);
         $aData['checksum'] = $sign;
         $request = new RestRequest($aConfig['url'], 'POST');
         $request->buildPostBody($aData);
         $request->execute();
         $http_code = $request->getHTTPCode();
         $rs->return = array();
         $rs->return['httpcode'] = $http_code;
         if ($http_code == '200') {
             $result = json_decode($request->getResponseBody(), true);
             $rs->return = $result;
             $rs->return['httpcode'] = $http_code;
         } else {
             $rs->return['message'] = $request->getResponseBody();
         }
         return $rs;
     } catch (Exception $fault) {
         throw $fault;
     }
 }
Exemplo n.º 2
0
function setCapabilities($username, $authuser, $authpw)
{
    global $SERVER_URL, $APIVERSION;
    $url = $SERVER_URL . 'capabilities/' . $APIVERSION . '/' . $username;
    $request = new RestRequest($url, 'PUT', null, $authuser, $authpw);
    $request->execute();
    echo $request->getResponseBody();
}
 public function getRepositoryNames()
 {
     $url = $this->baseUrl . "/names";
     $method = "GET";
     $rest = new RestRequest($url, $method);
     //$rest->setAcceptType("application/xml");
     $rest->execute();
     $output = $rest->getResponseBody();
     echo $output;
 }
Exemplo n.º 4
0
function getWeather($location)
{
    global $SERVER_URL, $APIKEY;
    $request = new RestRequest("http://free.worldweatheronline.com/feed/weather.ashx?q=" . $location . "&format=json&num_of_days=2&key=" . $APIKEY, 'GET', "");
    //echo "http://free.worldweatheronline.com/feed/weather.ashx?q=".$location."&format=json&num_of_days=2&key=".$APIKEY;
    $request->execute();
    $info = $request->getResponseInfo();
    if ($info['http_code'] == 200) {
        echo $request->getResponseBody();
    } else {
        echo "Error - cannot gather weather info";
    }
}
 public function check_session()
 {
     session_start();
     if (!isset($_SESSION['session_id'])) {
         header('HTTP/1.1 302 Undefined Redirect');
         header('Location: about:blank');
         die;
     } else {
         // TO DO validate!
         // send request
         include 'RestRequest.inc.php';
         include 'config.php';
         $request = new RestRequest($base_api_url . 'path_data.php', 'POST', $user, $password, array('session_id' => $_SESSION['session_id'], 'from_url' => $_REQUEST['from'], 'from_title' => $_REQUEST['from_title'], 'to_url' => $_REQUEST['to'], 'custom_variable' => $_REQUEST[$custom_request_variable]));
         $request->execute();
         // debug:
         //echo '<pre>' . print_r($request, true) . '</pre>';
     }
 }
Exemplo n.º 6
0
 public function process()
 {
     $stop = 0;
     if ($this->start == 0) {
         $this->modx->exec("TRUNCATE TABLE {$this->modx->getTableName('mSkladProductExchange')}");
     }
     $request = new RestRequest($this->config['restUrl'] . 'Good/list?start=' . $this->start . '&count=500', 'GET');
     $request->setUsername($this->config['Username']);
     $request->setPassword($this->config['Password']);
     $request->execute();
     $responseInfo = $request->getResponseInfo();
     $http_code = $responseInfo['http_code'];
     if ($this->config['debug']) {
         $this->modx->msklad->restLog('loadProduct', $request);
     }
     if ($http_code == '200') {
         $xml = simplexml_load_string($request->getResponseBody());
         $this->total = $xml->attributes()->total;
         foreach ($xml->good as $val) {
             $code = isset($val->code) && preg_match("/^[\\d\\+]+\$/", $val->code) ? intval($val->code) : 0;
             $uuid = isset($val->uuid) ? (string) $val->uuid : '';
             $uuid1c = isset($val->externalcode) ? (string) $val->externalcode : '';
             $priceUuid = '';
             foreach ($val->salePrices->price as $price) {
                 if ($price->attributes()->priceTypeUuid == $this->config['SalePriceType']) {
                     $priceUuid = $price->uuid;
                 }
             }
             $newProduct = $this->modx->newObject('mSkladProductExchange');
             $newProduct->fromArray(array('product_id' => $code, 'uuid_1c' => $uuid1c, 'uuid' => $uuid, 'price_uuid' => $priceUuid));
             if (!$newProduct->save()) {
                 return $this->failure($this->modx->lexicon('msklad_api_err_db'));
             }
         }
         unset($xml);
     } else {
         return $this->failure($this->modx->lexicon('msklad_api_err_connect'));
     }
     if ($this->start + 500 > $this->total) {
         $stop = 1;
     }
     return $this->success(array('total' => $this->total, 'stop' => $stop));
 }
Exemplo n.º 7
0
function lasthope($username, $authuser, $authpw, $cometurl)
{
    global $SERVER_URL, $APIVERSION;
    $request = new RestRequest($cometurl, 'POST', "", $authuser, $authpw);
    $request->execute();
    $requestAsArray = json_decode($request->getResponseBody(), true);
    // create object in php [messageID, text, sender, status, dateTime]
    $info = $request->getResponseInfo();
    if ($info['http_code'] == 200 && (array_key_exists('notificationList', $requestAsArray) || $requestAsArray == null)) {
        $requestAsArray = $requestAsArray['notificationList'];
        $returnArray = array();
        foreach ($requestAsArray as $key => $value) {
            $onemessage = array("sessionID" => "", "messageID" => "", "text" => "", "sender" => "", "status" => "", "dateTime" => "");
            if (array_key_exists('messageStatusNotification', $value)) {
                $onemessage["messageID"] = $value['messageStatusNotification']['messageId'];
                $onemessage["status"] = $value['messageStatusNotification']['status'];
                $onemessage["sessionID"] = $value['messageStatusNotification']['link'][0]['href'];
                $onemessage["sessionID"] = explode("/", $onemessage["sessionID"])[8];
            }
            if (array_key_exists('messageNotification', $value)) {
                $onemessage["messageID"] = $value['messageNotification']['messageId'];
                $onemessage["text"] = $value['messageNotification']['chatMessage']['text'];
                $onemessage["sender"] = $value['messageNotification']['senderAddress'];
                $onemessage["sender"] = str_replace("sip:+", "", $onemessage["sender"]);
                $onemessage["sender"] = str_replace("tel:+", "", $onemessage["sender"]);
                $onemessage["sender"] = str_replace("@rcstestconnect.net", "", $onemessage["sender"]);
                $onemessage["dateTime"] = $value['messageNotification']['dateTime'];
                $onemessage["sessionID"] = $value['messageNotification']['sessionId'];
            }
            if (array_key_exists('chatEventNotification', $value)) {
                $onemessage["sessionID"] = $value['chatEventNotification']['sessionId'];
            }
            $returnArray[] = $onemessage;
        }
        $returnArray = json_encode($returnArray);
        echo $returnArray;
    } else {
        echo $info['http_code'];
    }
}
 public function setUomUuid()
 {
     $request = new RestRequest($this->config['restUrl'] . 'Uom/list', 'GET');
     $request->setUsername($this->config['Username']);
     $request->setPassword($this->config['Password']);
     $request->execute();
     $responseInfo = $request->getResponseInfo();
     $http_code = $responseInfo['http_code'];
     if ($http_code == '200') {
         $xml = simplexml_load_string($request->getResponseBody());
         $cc = 0;
         foreach ($xml->uom as $val) {
             $name = (string) $val->attributes()->name;
             if ($name == 'шт') {
                 $uomType = $this->modx->getObject('modSystemSetting', 'msklad_uom_type_uuid');
                 $uomType->set('value', $val->uuid);
                 $uomType->save();
             }
             ++$cc;
         }
         unset($xml);
     }
 }
Exemplo n.º 9
0
 /**
  * Return objectives from the University of Nottingham Curriculum Mapping system
  * @param $moduleID
  * @param $session
  * @return mixed Array of session and objective data in format required by Rogō
  */
 public function getObjectives($moduleID, $session)
 {
     $this->_sess_year = strstr($session, '/', true);
     $this->_root_url = sprintf($this->_root_url, $this->_sess_year);
     $this->_module_id = $moduleID;
     $req = new RestRequest($this->_root_url . "api/find_json?search={$moduleID}&type=module&where=attribute&attrib=code&output=module_session_obs");
     $req->execute();
     $res = $req->getResponseBody();
     $response = $req->getResponseInfo();
     if ($response['http_code'] == 0) {
         $objectives = 'error';
     } else {
         switch ($this->_mapping_level) {
             case self::LEVEL_MODULE:
                 $objectives = $this->transformCMResponseModule($res, $session);
                 break;
             default:
                 $objectives = $this->transformCMResponse($res, $session);
                 break;
         }
     }
     return $objectives;
 }
Exemplo n.º 10
0
  * @param   (string)    $image      Image name to search for
  * @param   (string)    $path       Directory path to search for image
  * @return  (string,boolean)        Returns path of image if found, false if not found
  */
 public static function find_image_path($image, $path = "", $depth = 0)
 {
     # If no path supplied, get current working directory
     if ($path == "") {
Exemplo n.º 11
0
 private function offsetGet()
 {
     if (!Auth::$authenticated) {
         Auth::handleAuth();
         return;
     }
     switch (Site::$action) {
         case 'tasks':
             $tasker = new Tasker();
             $tasker->offsetGet(Site::$section, Site::$subsection, Site::$do);
             //#FB::info($tasker, 'Tasker');
             break;
         case 'api':
             $request = new RestRequest($_SERVER['REQUEST_URI'], Site::$section);
             $request->execute();
             echo '<pre>' . print_r($request, true) . '</pre>';
             break;
     }
 }
Exemplo n.º 12
0
function getNotificationChanList($username, $authuser, $authpw)
{
    global $SERVER_URL, $APIVERSION;
    $usernameNoPlus = '%2B' . substr($username, 1);
    $url = $SERVER_URL . 'notificationchannel/' . $APIVERSION . '/' . $usernameNoPlus . '/channels';
    echo $url;
    $request = new RestRequest($url, 'GET', null, $authuser, $authpw);
    $request->execute();
    echo $request->getResponseBody();
}
 public function process()
 {
     $stop = 0;
     $c = $this->modx->newQuery('mSkladProductData');
     $c->innerJoin('msProduct', 'msProduct', 'msProduct.id=mSkladProductData.product_id');
     $c->innerJoin('msProductData', 'msProductData', 'msProductData.id=mSkladProductData.product_id');
     $c->sortby('mSkladProductData.product_id', 'ASC');
     $c->select('mSkladProductData.product_id,mSkladProductData.uuid,mSkladProductData.uuid_1c,mSkladProductData.price_uuid,mSkladProductData.active,msProduct.parent,msProduct.pagetitle,msProduct.longtitle,msProduct.description,msProductData.*');
     $c->where(array('active:=' => '1'));
     $this->total = $this->modx->getCount('mSkladProductData', $c);
     $c->limit(100, $this->start);
     $c->prepare();
     if ($c->stmt->execute()) {
         //$c->prepare() &&
         $productsData = $c->stmt->fetchAll(PDO::FETCH_ASSOC);
         $collection = array();
         if (is_array($productsData) && count($productsData) > 0) {
             foreach ($productsData as $productData) {
                 $name = trim(htmlspecialchars(html_entity_decode($productData['pagetitle'], ENT_COMPAT, 'UTF-8'), ENT_QUOTES));
                 $description = trim(htmlspecialchars(html_entity_decode($productData['description'], ENT_COMPAT, 'UTF-8'), ENT_QUOTES));
                 $price = str_replace(".", "", $productData['price']) . '.0';
                 $weight = $productData['weight'];
                 $code = $productData['product_id'];
                 $productCode = trim(htmlspecialchars(html_entity_decode($productData['article'], ENT_COMPAT, 'UTF-8'), ENT_QUOTES));
                 $uuid = $productData['uuid'];
                 $priceUuid = $productData['price_uuid'];
                 $priceTypeUuid = $this->config['SalePriceType'];
                 $uomUuid = $this->config['Uom'];
                 $externalCode = $uuid_1c = $productData['uuid_1c'];
                 $parentUuid = '';
                 if ($productData['parent']) {
                     $parent_q = $this->modx->newQuery('msCategory', array('id' => $productData['parent']));
                     $parent_q->leftJoin('mSkladCategoryData', 'Data', 'Data.category_id = msCategory.id');
                     $parent_q->select('msCategory.id, Data.uuid');
                     $parent_q->limit(1);
                     if ($parent_q->prepare() && $parent_q->stmt->execute()) {
                         $parentRes = $parent_q->stmt->fetch(PDO::FETCH_ASSOC);
                         $parentUuid = !empty($parentRes['uuid']) ? 'parentUuid="' . $parentRes['uuid'] . '"' : '';
                     }
                 }
                 $collection[] = '
                         <good isSerialTrackable="false" uomUuid="' . $uomUuid . '" productCode="' . $productCode . '" name="' . $name . '" weight="' . $weight . '" ' . $parentUuid . '>
                             <uuid>' . $uuid . '</uuid>
                             <code>' . $code . '</code>
                             <externalcode>' . $externalCode . '</externalcode>
                             <description>' . $description . '</description>
                             <salePrices>
                                 <price value="' . $price . '" priceTypeUuid="' . $priceTypeUuid . '">
                                     <uuid>' . $priceUuid . '</uuid>
                                 </price>
                             </salePrices>
                         </good>
                     ';
             }
             $xml = '<?xml version="1.0" encoding="UTF-8"?>
                     <collection>
                     ' . implode('', $collection) . '
                     </collection>';
             $request = new RestRequest($this->config['restUrl'] . 'Good/list/update', 'PUT', $xml);
             $request->setUsername($this->config['Username']);
             $request->setPassword($this->config['Password']);
             $request->execute();
             $responseInfo = $request->getResponseInfo();
             $http_code = $responseInfo['http_code'];
             if ($this->config['debug']) {
                 $this->modx->msklad->restLog('updateProductSklad_' . $this->start, $request);
             }
             if ($http_code == '200') {
                 $xml = simplexml_load_string($request->getResponseBody());
                 $cc = 0;
                 foreach ($xml->id as $val) {
                     if ($productData = $this->modx->getObject('mSkladProductData', array('product_id' => $productsData[$cc]['product_id']))) {
                         $productData->set('uuid', $val);
                         $productData->save();
                     }
                     ++$cc;
                 }
                 unset($xml);
             }
             unset($productsData);
         }
     }
     if ($this->start + 100 > $this->total) {
         $stop = 1;
     }
     return $this->success(array('total' => $this->total, 'stop' => $stop));
 }
Exemplo n.º 14
0
    }
    public function getUrl()
    {
        return $this->url;
    }
    public function setUrl($url)
    {
        $this->url = $url;
    }
    public function getUsername()
    {
        return $this->username;
    }
    public function setUsername($username)
    {
        $this->username = $username;
    }
    public function getVerb()
    {
        return $this->verb;
    }
    public function setVerb($verb)
    {
        $this->verb = $verb;
    }
}
//$request = new RestRequest('http://domain.com/api/user/1', 'GET');
$request = new RestRequest('http://www.abc-cooking.com.cn/', 'GET');
$request->execute();
echo '<pre>' . var_dump($request) . '</pre>';
die;
Exemplo n.º 15
0
 function searchInboxQ($keywords = null, $settings = null)
 {
     if (!empty($keywords)) {
         $params = array();
         //$params['terms'] = str_replace( " ", ",", $keywords );
         $params['terms'] = '"' . $keywords . '"';
         // Reuben: I'm commenting this before param because it's an
         // optional param and I think we always want the
         // latest and freshest tweets
         //$params['before'] = !empty( $settings['numDays'] ) ? strtotime( $settings['numDays'] ) : strtotime( 'now' );
         // Reuben: various options for this param are (decreasing order by
         // quality): qualityInboxQ, qip, unicorn, filtered
         $params['type'] = !empty($settings['inboxType']) ? $settings['inboxType'] : 'qualityInboxQ';
         $url = 'https://api.inboxq.com/v0.4/questions';
         $rr = new RestRequest($url, 'GET', $params);
         $rr->execute();
         $response = $rr->displayResponse();
         return $response;
     } else {
         return false;
     }
 }
 public function process()
 {
     $stop = 0;
     $c = $this->modx->newQuery('mSkladCategoryData');
     $c->select('category_id,uuid,level,active');
     $c->where(array('active:=' => '1', 'level:=' => $this->level));
     $this->total = $this->modx->getCount('mSkladCategoryData', $c);
     $c->limit(100, $this->start);
     if ($c->prepare() && $c->stmt->execute()) {
         $categoriesData = $c->stmt->fetchAll(PDO::FETCH_ASSOC);
         $collection = array();
         if (is_array($categoriesData) && count($categoriesData) > 0) {
             foreach ($categoriesData as $categoryData) {
                 if ($category = $this->modx->getObject('msCategory', array('id' => $categoryData['category_id']))) {
                     $name = trim(htmlspecialchars(html_entity_decode($category->get('pagetitle'), ENT_COMPAT, 'UTF-8'), ENT_QUOTES));
                     $description = trim(htmlspecialchars(html_entity_decode($category->get('description'), ENT_COMPAT, 'UTF-8'), ENT_QUOTES));
                     $parentUuid = '';
                     if ($categoryData['level'] > 1) {
                         $parent_q = $this->modx->newQuery('msCategory', array('id' => $category->get('parent')));
                         $parent_q->leftJoin('mSkladCategoryData', 'Data', 'Data.category_id = msCategory.id');
                         $parent_q->select('msCategory.id, Data.uuid, Data.uuid_1c');
                         $parent_q->limit(1);
                         //                        $parent_q->prepare();
                         //                        $this->modx->msklad->restLog('toSQL',print_r($parent_q->toSQL(),true));
                         if ($parent_q->prepare() && $parent_q->stmt->execute()) {
                             $parentRes = $parent_q->stmt->fetch(PDO::FETCH_ASSOC);
                             $parentUuid = !empty($parentRes['uuid']) ? 'parentUuid="' . $parentRes['uuid'] . '"' : '';
                         }
                     }
                     $collection[] = '
                         <goodFolder ' . $parentUuid . ' productCode="" name="' . $name . '">
                             <uuid>' . $categoryData['uuid'] . '</uuid>
                             <description>' . $description . '</description>
                             <code>' . $categoryData['category_id'] . '</code>
                             <externalcode>' . $categoryData['uuid_1c'] . '</externalcode>
                         </goodFolder>
                     ';
                 }
             }
             $xml = '<?xml version="1.0" encoding="UTF-8"?>
                     <collection>
                     ' . implode('', $collection) . '
                     </collection>';
             $request = new RestRequest($this->config['restUrl'] . 'GoodFolder/list/update', 'PUT', $xml);
             $request->setUsername($this->config['Username']);
             $request->setPassword($this->config['Password']);
             $request->execute();
             $responseInfo = $request->getResponseInfo();
             $http_code = $responseInfo['http_code'];
             if ($this->config['debug']) {
                 $this->modx->msklad->restLog('updateCategorySklad_' . $this->start . '_' . $this->level, $request);
             }
             if ($http_code == '200') {
                 $xml = simplexml_load_string($request->getResponseBody());
                 $cc = 0;
                 foreach ($xml->id as $val) {
                     if ($categoryData = $this->modx->getObject('mSkladCategoryData', array('category_id' => $categoriesData[$cc]['category_id']))) {
                         $categoryData->set('uuid', $val);
                         $categoryData->save();
                     }
                     ++$cc;
                 }
                 unset($xml);
             }
             unset($categoriesData);
         } else {
             $this->level += 1;
         }
     }
     if ($this->start == 0 && !$this->total) {
         $stop = 1;
     }
     return $this->success(array('total' => $this->total, 'level' => $this->level, 'stop' => $stop));
 }
Exemplo n.º 17
0
 /**
  * Return objectives from the University of Nottingham Medical School Networked Learning Environment
  * @param $moduleID
  * @param $session
  * @return mixed Array of session and objective data in format required by Rogō
  */
 public function getObjectives($moduleID, $session)
 {
     $req = new RestRequest("http://www.nle.nottingham.ac.uk/webServices/RogoRestAPI.php?url=getObjectives/{$moduleID}/{$session}");
     $req->execute();
     return $req->getResponseBody();
 }
Exemplo n.º 18
0
function deleteAttribute($username, $authuser, $authpw, $attributeName)
{
    global $SERVER_URL, $APIVERSION;
    $url = $SERVER_URL . 'addressbook/' . $APIVERSION . '/' . $username . '/contacts/' . $contactID . '/attributes/' . $attributeName;
    //echo $url;
    $request = new RestRequest($url, 'DELETE', null, $authuser, $authpw);
    $request->execute();
    echo $request->getResponseBody();
}
 public function testRestRequestPost()
 {
     $url = "http://*****:*****@' . $this->testingFileWithPath);
     //var_dump( $data );
     $rest = new RestRequest($url, $verb, $data);
     //$rest->setUrl("http://145.247.163.52:8080/BIM_Facility_Management/rest/tests/testPut/ttt");
     // http://145.247.163.52:8080/BIM_Facility_Management/rest/uploadIfc
     $rest->setAcceptType("text/html");
     $rest->setLocalFile($this->testingFileWithPath);
     $rest->execute();
     echo $rest->getResponseBody();
     echo "\n resp info \n";
     var_dump($rest->getResponseInfo());
 }
Exemplo n.º 20
0
function loginUnregister($username, $authuser, $authpw)
{
    //HTTP DELETE http://{serverRoot}/register/{apiVersion}/{userId}/sessions
    global $SERVER_URL, $APIVERSION;
    $usernameNoPlus = '%2B' . substr($username, 1);
    $url = $SERVER_URL . 'register/' . $APIVERSION . '/' . $usernameNoPlus . '/sessions';
    $action = "";
    $request = new RestRequest($url, 'DELETE', $action, $authuser, $authpw);
    $request->execute();
    $info = $request->getResponseInfo();
    if ($info['http_code'] == 204) {
        echo "1";
    } else {
        echo "0";
    }
}
Exemplo n.º 21
0
function getGroupParticipants($username, $authuser, $authpw, $sessionID)
{
    global $SERVER_URL, $APIVERSION;
    $url = $SERVER_URL . 'chat/' . $APIVERSION . '/' . $username . '/group/' . $sessionID . '/participants';
    $request = new RestRequest($url, 'GET', null, $authuser, $authpw);
    $request->execute();
    echo $request->getResponseBody();
}