Blame | Last modification | View Log | RSS feed
<?phpApp::uses('AppModel', 'Model');/*** UserUrl Model** @property User $User*/class Api extends AppModel {var $useTable = false;public function getDeals($userId=null,$page=1) {$apihost = Configure::read('apihost');$url = $apihost."store_products/index/$userId/page:$page";// $params = array('client_id'=>$this->instagramconfig['client_id'],'client_secret'=>$this->instagramconfig['client_secret'],'grant_type'=>$this->instagramconfig['grant_type'],'redirect_uri'=>$this->instagramconfig['redirect_uri']);return $this->make_request($url,null);}public function getDealsByCategory($userId=null,$categoryId=null,$page=1) {$apihost = Configure::read('apihost');$url = $apihost."store_products/category/$userId/$categoryId/page:$page";// $params = array('client_id'=>$this->instagramconfig['client_id'],'client_secret'=>$this->instagramconfig['client_secret'],'grant_type'=>$this->instagramconfig['grant_type'],'redirect_uri'=>$this->instagramconfig['redirect_uri']);return $this->make_request($url,null);}public function getCategoryDeals($userId=null,$page=1) {$apihost = Configure::read('apihost');$url = $apihost."store_products/bycategory/$userId/page:$page";// $params = array('client_id'=>$this->instagramconfig['client_id'],'client_secret'=>$this->instagramconfig['client_secret'],'grant_type'=>$this->instagramconfig['grant_type'],'redirect_uri'=>$this->instagramconfig['redirect_uri']);return $this->make_request($url,null);}public function getMyActions($userId=null) {$apihost = Configure::read('apihost');$url = $apihost."user_actions/by/$userId";// $params = array('client_id'=>$this->instagramconfig['client_id'],'client_secret'=>$this->instagramconfig['client_secret'],'grant_type'=>$this->instagramconfig['grant_type'],'redirect_uri'=>$this->instagramconfig['redirect_uri']);return $this->make_request($url,null);}public function getLiveScore($userId=null) {$apihost = Configure::read('pythonapihost');$url = $apihost."liveCricketScore/";return $this->make_request($url,null);}public function make_request($url,$fields,$format='json'){$fields_string = '';if(!empty($fields)){foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }rtrim($fields_string, '&');}//open connection$ch = curl_init();$additionalHeaders = '';//set the url, number of POST vars, POST datacurl_setopt($ch,CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);curl_setopt($ch, CURLOPT_USERPWD, "dtr:dtr18Feb2015");if(!empty($fields)) {curl_setopt($ch,CURLOPT_POST, count($fields));curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);}//execute post$result = curl_exec($ch);//close connectioncurl_close($ch);switch($format){case 'json':$response = json_decode($result,1);break;}return $response;}}