public static function processRequest() { // get the request method $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // store the request data $data = array(); switch ($request_method) { // put data case 'put': $data = $_GET; break; // get data // get data case 'get': $data = $_GET; break; // post request // post request case 'post': $data = $_POST; break; } // store the method $return_obj->setMethod($request_method); // set the raw data, so we can access it if needed (there may be // other pieces to your requests) $return_obj->setRequestVars($data); if (isset($data['data'])) { // translate the JSON to an Object for use however you want $return_obj->setData($json->decode($data['data'])); } return $return_obj; }
function testTypes() { $r = new RestRequest(); $this->assertTrue($r->acceptMime("text/html")); $this->assertFalse($r->acceptMime("application/json")); $this->assertEquals($r->getExtension(), "php"); }
public static function processRequest() { $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); $data = array(); switch ($request_method) { case 'get': $data = $_GET; break; case 'post': $data = $_POST; break; case 'put': // read a string from PHP's special input location, and then parse it out into an array via parse_str... per the PHP docs: // parses str as if it were the query string passed via a URL and sets variables in the current scope. parse_str(file_get_contents('php://input'), $put_vars); $data = $put_vars; break; } $return_obj->setMethod($request_method); $return_obj->setRequestVars($data); if (isset($data['data'])) { $return_obj->setData(json_decode($data['data'])); } return $return_obj; }
/** create a basket, put the article in and return the spreadshirt checkout url */ public function checkout($article, $shopId, $size, $appearance) { // create a new basketitem $payload = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><basketItem xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://api.spreadshirt.net">'; // if no shopId is set, use the marketplace checkout if (isset($shopId)) { $payload .= '<shop id="' . $shopId . '" xlink:href="http://api.spreadshirt.net/api/v1/shops/' . $shopId . '"/>'; } // prepare the upload, which is a xml document // some elements are not necessary/ignored (see price element) $payload .= '<description>bla</description>' . '<quantity>1</quantity>' . '<element id="' . $article->getArticleID() . '" type="sprd:article" xlink:href="' . $article->getArticleUrl() . '">' . '<properties>' . '<property key="appearance">' . $appearance . '</property>' . '<property key="size">' . $size . '</property>' . '</properties>' . '</element>' . '<price><vatIncluded>34.40</vatIncluded><currency id="1"/></price>' . '</basketItem>'; $customBasket = $this->createBasket($shopId); // the basket url has some extra parameters, for security reasons // we never send our secret over the network. We send only a evidence // which is called signature $url = $customBasket . "/items"; $stamp = time() * 1000; $signature = $this->getSignature('POST', $url, $stamp); // construct the basket url and add the required parameter $url = $url . "?apiKey=" . $this->API_KEY . "&sig=" . $signature . '&time=' . $stamp; // call api, put item into the current basket $this->performPostRequest($url, $payload); //basket api url - debug // $url=$customBasket; // $signature=$this->getSignature('GET', $url, $stamp); // $url=$url."?apiKey=".$this->API_KEY."&sig=".$signature.'&time='.$stamp; // echo "basket url is :".$url."<br>"; // request the checkout url for redirect $url = $customBasket . "/checkout"; $signature = $this->getSignature('GET', $url, $stamp); $url = $url . "?apiKey=" . $this->API_KEY . "&sig=" . $signature . '&time=' . $stamp; $rest = new RestRequest(); $xml = simplexml_load_string($rest->doGetCall($url)); return (string) $xml->attributes('http://www.w3.org/1999/xlink'); }
public static function processRequest() { // get our verb $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // store the method $return_obj->setMethod($request_method); //06.08.2012 naj - parse the uri elements $urirequest = $_SERVER['REQUEST_URI']; switch ($request_method) { case 'get': //here we need to strip off only the method call that was //tagged at the end of the URL $pos = strpos($urirequest, '?'); $requesttype = strtolower(substr($urirequest, 1, $pos - 1)); $urirequest = substr($urirequest, $pos + 1); parse_str($urirequest, $data); break; case 'post': $pos = strpos($urirequest, '?'); $requesttype = strtolower(substr($urirequest, 1, $pos - 1)); $urirequest = substr($urirequest, $pos + 1); parse_str($urirequest, $data); $data['Data'] = $_POST; break; } //06.08.2012 naj - set the request type $return_obj->setRequestType($requesttype); //06.08.2012 naj - set the request vars $return_obj->setRequestVars($data); return $return_obj; }
public static function processRequest() { // get our verb $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // we'll store our data here $data = array(); switch ($request_method) { // gets are easy... case 'get': $data = $_GET; break; // so are posts // so are posts case 'post': $data = $_POST; break; // here's the tricky bit... // here's the tricky bit... case 'put': parse_str(file_get_contents('php://input'), $put_vars); $data = $put_vars; break; } // store the method $return_obj->setMethod($request_method); // set the raw data, so we can access it if needed (there may be // other pieces to your requests) $return_obj->setRequestVars($data); if (isset($data['data'])) { // translate the JSON to an Object for use however you want $return_obj->setData(json_decode($data['data'])); } return $return_obj; }
public static function processRequest() { // get our verb $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // we'll store our data here $data = array(); switch ($request_method) { case 'get': $data = $_GET; break; case 'post': $data = $_POST; break; case 'put': // basically, we read a string from PHP's special input location, // and then parse it out into an array via parse_str... per the PHP docs: // Parses str as if it were the query string passed via a URL and sets // variables in the current scope. parse_str(file_get_contents('php://input'), $put_vars); $data = $put_vars; break; } // store the method $return_obj->setMethod($request_method); // set the raw data, so we can access it if needed (there may be // other pieces to your requests) $return_obj->setRequestVars($data); if (isset($data['data'])) { // translate the JSON to an Object for use however you want $return_obj->setData(json_decode($data['data'])); } return $return_obj; }
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 execute($http_verb, $signed_url, $params = array()) { $curl = new RestRequest(); $ch = curl_init($signed_url); try { switch (strtoupper($http_verb)) { case 'GET': $curl->setCurlOpts($ch); $output = curl_exec($ch); $contentype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { $output = curl_error($ch); } curl_close($ch); break; case 'POST': curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $curl->setCurlOpts($ch); $output = curl_exec($ch); $contentype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case 'PUT': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $curl->setCurlOpts($ch); $output = curl_exec($ch); $contentype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case 'DELETE': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); $curl->setCurlOpts($ch); $output = curl_exec($ch); $contentype = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (curl_errno($ch)) { $output = curl_error($ch); } curl_close($ch); break; default: throw new InvalidArgumentException('Current verb (' . $http_verb . ') is an invalid REST verb.'); } } catch (InvalidArgumentException $e) { curl_close($ch); throw $e; } catch (Exception $e) { curl_close($ch); throw $e; } return array($output, $contentype, $httpcode); }
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; }
public function __construct($uri) { $rest = new RestRequest(); $this->requestUri = $uri; $xml = simplexml_load_string($rest->submit($uri)); $this->productID = (string) $xml->attributes()->id; $this->productTypeLink = (string) $xml->productType->attributes('http://www.w3.org/1999/xlink'); $this->resourceLink = (string) $xml->resources->resource[1]->attributes('http://www.w3.org/1999/xlink'); $this->defaultAppearanceID = (string) $xml->appearance['id']; }
public function __construct($shopId, $articleId) { $rest = new RestRequest(); $this->requestUri = 'http://api.spreadshirt.net/api/v1/shops/' . $shopId . '/articles/' . $articleId; $xml = simplexml_load_string($rest->submit($this->requestUri)); //->children('http://api.spreadshirt.net'); $this->articleID = (string) $xml->attributes()->id; $this->price = (string) $xml->price->vatIncluded; $this->productLink = (string) $xml->product->attributes('http://www.w3.org/1999/xlink'); $this->productID = (string) $xml->product['id']; $this->resourceLink = (string) $xml->resources->resource->attributes('http://www.w3.org/1999/xlink'); }
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 __construct() { // assign class variables and load data from sprd API // grab the first product/article from shop if the articleID is not set... if (!isset($this->articleID)) { $rest = new RestRequest(); $requestUri = 'http://api.spreadshirt.net/api/v1/shops/' . $this->shopID . '/articles'; $xml = simplexml_load_string($rest->submit($requestUri)); //$this->articleID = (String) $xml->article->attributes()->id; $this->articleID = (string) $xml->article['id']; } $this->article = new ArticleCDO($this->shopID, $this->articleID); $this->product = new ProductCDO($this->article->getProductLink()); $this->productType = new ProductTypeCDO($this->product->getProductTypeLink()); }
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>'; } }
public static function processRequest() { include 'config.php'; $auth_username = $user; $auth_pass = $password; // figure out if we need to challenge the user if (empty($_SERVER['PHP_AUTH_DIGEST'])) { header('HTTP/1.1 401 Unauthorized'); header('WWW-Authenticate: Digest realm="' . AUTH_REALM . '",qop="auth",nonce="' . uniqid() . '",opaque="' . md5(AUTH_REALM) . '"'); // show the error if they hit cancel die(RestUtils::sendResponse(401)); } // now, analayze the PHP_AUTH_DIGEST var if (!($data = self::http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) || $auth_username != $data['username']) { // show the error due to bad auth die(RestUtils::sendResponse(401)); } // so far, everything's good, let's now check the response a bit more... $A1 = md5($data['username'] . ':' . AUTH_REALM . ':' . $auth_pass); $A2 = md5($_SERVER['REQUEST_METHOD'] . ':' . $data['uri']); $valid_response = md5($A1 . ':' . $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $A2); // last check.. if ($data['response'] != $valid_response) { die(RestUtils::sendResponse(401)); } // get our verb $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // we'll store our data here $data = array(); if (strcmp($request_method, 'post') == 0) { $data = $_POST; // store the method $return_obj->setMethod($request_method); // set the raw data, so we can access it if needed (there may be // other pieces to your requests) $return_obj->setRequestVars($data); if (isset($data['data'])) { // translate the JSON to an Object for use however you want $return_obj->setData(json_decode($data['data'])); } return $return_obj; } }
public function __construct($uri) { $rest = new RestRequest(); $this->requestUri = $uri; $xml = simplexml_load_string($rest->submit($uri)); $this->productTypeID = (string) $xml->attributes()->id; $this->name = (string) $xml->name; $this->description = (string) $xml->description; // transform sizes to a 2d array $tmp = array(); $array = (array) $xml->sizes; if (!empty($array)) { foreach ($array['size'] as $key => $values) { if (is_a($values, 'SimpleXMLElement')) { $tmp[(string) $values->attributes()->id] = (string) $values->name; } } } $this->sizes = $tmp; }
public static function processRequest() { // get our verb $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // we'll store our data here $data = array(); // only POST is available switch ($request_method) { case 'post': $data = $_POST; break; } // store the method $return_obj->setMethod($request_method); // set the raw data, so we can access it if needed (there may be // other pieces to your requests) $return_obj->setRequestVars($data); if (isset($data['service'])) { // translate the JSON to an Object for use however you want $return_obj->setService($data['service']); } if (isset($data['text'])) { $return_obj->setTextToProc($data['text']); } return $return_obj; }
public static function initProcess() { $requestMethod = strtolower($_SERVER['REQUEST_METHOD']); $obj = new RestRequest(); $data = array(); $files = array(); $_PUT_VARS = null; switch ($requestMethod) { case 'get': $data = $_GET; break; case 'post': $data = $_POST; if (isset($_FILES) && !empty($_FILES)) { $files = $_FILES; } break; case 'put': parse_str(file_get_contents('php://input'), $_PUT_VARS); $data = $_PUT_VARS; break; } $obj->setMethod($requestMethod); $obj->setRequestVars($data); if (isset($data['data'])) { $obj->setData(json_decode($data['data'])); } if (isset($files)) { $obj->setFiles($files); } return $obj; }
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; } }
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 static function processRequest() { $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // store our data here $data = array(); switch ($request_method) { case 'get': $data = $_GET; break; case 'post': $data = $_POST; break; } $return_obj->setMethod($request_method); $return_obj->setRequestVars($data); if (isset($data['data'])) { // translate the JSON to an Object for use however we want $return_obj->setData(json_decode($data['data'], true)); } return $return_obj; }
/** * 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; }
public static function processRequest() { // get our verb $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // we'll store our query here $query = array(); switch ($request_method) { // gets are easy... case 'get': $query = $_GET; break; // so are posts // so are posts case 'post': $query = $_POST; break; // here's the tricky bit... // here's the tricky bit... case 'put': // basically, we read a string from PHP's special input location, // and then parse it out into an array via parse_str... per the PHP docs: // Parses str as if it were the query string passed via a URL and sets // variables in the current scope. parse_str(file_get_contents('php://input'), $put_vars); $query = $put_vars; break; } // store the method $return_obj->setMethod($request_method); $request_vars = explode('/', $_GET['url']); $return_obj->setRequestVars($request_vars); $data = $query; unset($data['url']); $return_obj->setData($data); return $return_obj; }
/** * Gets the full collection of arguments from the request * * @param array $route The route description for this request * @return array */ protected function getRequestArgs($route) { // This loads the path variables in, so that on the /Accounts/abcd, $module is set to Accounts, and $id is set to abcd $pathVars = $this->request->getPathVars($route); $getVars = $this->request->getQueryVars(); if (!empty($getVars)) { // This has some get arguments, let's parse those in if (!empty($route['jsonParams'])) { foreach ($route['jsonParams'] as $fieldName) { if (isset($getVars[$fieldName]) && !empty($getVars[$fieldName]) && is_string($getVars[$fieldName]) && isset($getVars[$fieldName][0]) && ($getVars[$fieldName][0] == '{' || $getVars[$fieldName][0] == '[')) { // This may be JSON data $jsonData = @json_decode($getVars[$fieldName], true, 32); if (json_last_error() !== 0) { // Bad JSON data, throw an exception instead of trying to process it throw new SugarApiExceptionInvalidParameter(); } // Need to dig through this array and make sure all of the elements in here are safe $getVars[$fieldName] = $jsonData; } } } } $postVars = array(); if (isset($route['rawPostContents']) && $route['rawPostContents']) { // This route wants the raw post contents // We just ignore it here, the function itself has to know how to deal with the raw post contents // this will mostly be used for binary file uploads. } else { if (!empty($_POST)) { // They have normal post arguments $postVars = $_POST; } else { $postContents = $this->request->getPostContents(); if (!empty($postContents)) { // This looks like the post contents are JSON // Note: If we want to support rest based XML, we will need to change this $postVars = @json_decode($postContents, true, 32); if (json_last_error() !== 0) { // Bad JSON data, throw an exception instead of trying to process it throw new SugarApiExceptionInvalidParameter(); } } } } // I know this looks a little weird, overriding post vars with get vars, but // in the case of REST, get vars are fairly uncommon and pretty explicit, where // the posted document is probably the output of a generated form. return array_merge($postVars, $getVars, $pathVars); }
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()); }
/** * Construct request from request data * @param array $request */ public function __construct($request) { $svars = $_SERVER; $rvars = array(); $rvars['__sugar_url'] = parse_url($request['url'], PHP_URL_PATH); if (!empty($request['headers'])) { foreach ($request['headers'] as $hname => $hval) { $svars['HTTP_' . str_replace("-", "_", strtoupper($hname))] = $hval; } } if (!empty($request['method'])) { $svars['REQUEST_METHOD'] = $request['method']; } else { $svars['REQUEST_METHOD'] = 'GET'; } if (isset($request['data'])) { $this->postContents = $request['data']; } $svars['QUERY_STRING'] = parse_url($request['url'], PHP_URL_QUERY); parent::__construct($svars, $rvars); }
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)); }
public static function processRequest() { // cogemos el metodo $request_method = strtolower($_SERVER['REQUEST_METHOD']); $return_obj = new RestRequest(); // aqui almacenaremos los datos$data = array(); switch ($request_method) { // para get y post esto sera sencillo case 'get': $data = $_GET; break; case 'post': $data = $_POST; break; // Aqui esta lo "complicado" // Aqui esta lo "complicado" case 'put': //para put y delete usamos una cadena desde una localizacion de inputespecial de PHP y la parseamos con parse_str. parse_str(file_get_contents('php://input'), $put_vars); $data = $put_vars; break; case 'delete': $data = ''; //delete no acepta parametros break; } // almacenamos el metodo $return_obj->setMethod($request_method); // Almacenamos los parametros pasados en crudo, por si necesitamo sacceder a ellos $return_obj->setRequestVars($data); if (isset($data['data'])) { // asumimos que los datos estan pasados en forjato JSON $return_obj->setData(json_decode($data['data'])); } else { if ($request_method == "get") { $return_obj->setData($data); } } return $return_obj; }
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); } }