コード例 #1
0
ファイル: weather.php プロジェクト: nrooney/rcs_oma
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";
    }
}
コード例 #2
0
 public function getFacilityManagementXml()
 {
     $this->checkArgumentsForXmlDownload();
     $restCall = "uploadIfc";
     $url = $this->baseUrl . $restCall;
     $verb = "POST";
     $data = array('file' => '@' . $this->fileToSend);
     $rest = new RestRequest($url, $verb, $data);
     $rest->setAcceptType("application/xml");
     $rest->execute();
     //echo "SObim converter: response info\n";
     //print_r($rest->getResponseInfo());
     if ($rest->isError()) {
         $info = $rest->getResponseInfo();
         $http_code = $info["http_code"];
         if ($http_code == 0) {
             throw new NoResponseException();
         }
         throw new Exception("Rest call error : " . var_export($rest->getResponseInfo()));
     }
     return $rest->getResponseBody();
 }
コード例 #3
0
ファイル: notifications.php プロジェクト: nrooney/rcs_oma
function createNotificationChan($username, $authuser, $authpw)
{
    //NOT WORKING JUST YET!!!
    global $SERVER_URL, $APIVERSION;
    $usernameNoPlus = '%2B' . substr($username, 1);
    $url = $SERVER_URL . 'notificationchannel/' . $APIVERSION . '/' . $usernameNoPlus . '/channels';
    //echo $url . '<br/>';
    //echo 'http://api.oneapi-gw.gsma.com/notificationchannel/0.1/%2B15554000002/channels<br/>';
    $action = '{"notificationChannel": {"channelData": {"maxNotifications": 100},"channelLifetime": 0,"channelType": "LongPolling"}}';
    $request = new RestRequest($url, 'POST', $action, $authuser, $authpw);
    $request->execute();
    $info = $request->getResponseInfo();
    //echo $info['http_code'];
    echo $request->getResponseBody();
}
コード例 #4
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));
 }
コード例 #5
0
ファイル: poll.php プロジェクト: nrooney/rcs_oma
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'];
    }
}
コード例 #6
0
ファイル: CM_UoNCM.class.php プロジェクト: vinod-co/centa
 /**
  * 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;
 }
コード例 #7
0
 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);
     }
 }
コード例 #8
0
 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));
 }
コード例 #9
0
 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));
 }
コード例 #10
0
ファイル: addressbook.php プロジェクト: nrooney/rcs_oma
function removeContact($username, $authuser, $authpw, $contactID)
{
    global $SERVER_URL, $APIVERSION;
    $usernameNoPlus = str_replace('+', '%2B', $username);
    $contactIDNoPlus = str_replace('tel:+', 'tel%3A%2B', $contactID);
    //echo $contactID;
    $url = $SERVER_URL . 'addressbook/' . $APIVERSION . '/' . $usernameNoPlus . '/contacts/sip:+15554000098@rcstestconnect.net ';
    //.$contactIDNoPlus;
    //echo $url;
    $data = [];
    $request = new RestRequest($url, 'DELETE', $data, $authuser, $authpw);
    $request->execute();
    $info = $request->getResponseInfo();
    if ($info['http_code'] == '204') {
        echo 1;
    } else {
        echo 0;
    }
}
コード例 #11
0
 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());
 }
コード例 #12
0
ファイル: chat.php プロジェクト: nrooney/rcs_oma
function sendIM($username, $authuser, $authpw, $contactID, $sessionID, $text)
{
    global $SERVER_URL, $APIVERSION;
    if ($sessionID == "" || $sessionID == null) {
        $sessionID = 'adhoc';
    }
    $usernameNoPlus = '%2B' . substr($username, 1);
    $contactIDNoPlus = 'tel%3A%2B' . substr($contactID, 1);
    $url = $SERVER_URL . 'chat/' . $APIVERSION . '/' . $usernameNoPlus . '/oneToOne/' . $contactIDNoPlus . '/' . $sessionID . '/messages';
    $action = '{"ChatMessage":{"text":"' . $text . '","reportRequest":"Displayed"}}';
    $request = new RestRequest($url, 'POST', $action, $authuser, $authpw);
    $request->execute();
    $requestAsArray = json_decode($request->getResponseBody());
    $info = $request->getResponseInfo();
    if ($info['http_code'] == '201') {
        echo $info['http_code'] . ' ';
        $messageID = $requestAsArray->resourceReference->resourceURL;
        //HERE MAKING THIS WORK!
        $messageID = explode("/", $messageID);
        $messageID = $messageID[count($messageID) - 2];
        echo $messageID;
    } else {
        echo $info['http_code'] . ' Error - ';
        //$requestAsArray = $requestAsArray->requestError->serviceException->variables;
        print_r($requestAsArray);
    }
}
コード例 #13
0
ファイル: FormHelper.php プロジェクト: TiMESPLiNTER/meta-cms
 private function validateYoutube($fieldName)
 {
     $fieldData = $this->fields[$fieldName];
     $required = $fieldData['required'] === true ? true : false;
     $missingError = isset($fieldData['options']['missingError']) ? $fieldData['options']['missingError'] : "missingError for field {$fieldName} not defined";
     $invalidError = isset($fieldData['options']['invalidError']) ? $fieldData['options']['invalidError'] : "invalidError for field {$fieldName} not defined";
     $value = isset($this->rsc[$fieldName]) ? trim($this->rsc[$fieldName]) : '';
     if ($required === true && $value == '') {
         $this->addError($fieldName, $missingError);
     }
     if ($value != '') {
         $request = new RestRequest("http://gdata.youtube.com/feeds/api/videos/{$value}");
         $request->stdRequest(array(), array('Accept: text/xml'));
         $responseInfo = $request->getResponseInfo();
         if (!isset($responseInfo['http_code']) || $responseInfo['http_code'] != '200') {
             $this->addError($fieldName, $invalidError);
         }
     }
     $this->setFieldValue($fieldName, $value);
 }
コード例 #14
0
ファイル: login.php プロジェクト: nrooney/rcs_oma
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";
    }
}