Subversion Repositories SmartDukaan

Rev

Rev 14318 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13565 anikendra 1
<?php
2
App::uses('AppModel', 'Model');
3
/**
4
 * UserUrl Model
5
 *
6
 * @property User $User
7
 */
8
class Api extends AppModel {
9
	var $useTable = false;
10
 
13570 anikendra 11
	public function getDeals($userId=null,$page=1) {
13567 anikendra 12
		$apihost = Configure::read('apihost');
13
		$url = $apihost."store_products/index/$userId/page:$page";
14
		// $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']);
13565 anikendra 15
		return $this->make_request($url,null);
16
	}
17
 
13583 anikendra 18
	public function getDealsByCategory($userId=null,$categoryId=null,$page=1) {
13567 anikendra 19
		$apihost = Configure::read('apihost');
13579 anikendra 20
		$url = $apihost."store_products/category/$userId/$categoryId/page:$page";
13567 anikendra 21
		// $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']);
22
		return $this->make_request($url,null);
23
	}
24
 
13583 anikendra 25
	public function getCategoryDeals($userId=null,$page=1) {
13567 anikendra 26
		$apihost = Configure::read('apihost');
27
		$url = $apihost."store_products/bycategory/$userId/page:$page";
28
		// $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']);
29
		return $this->make_request($url,null);
30
	}
31
 
13583 anikendra 32
	public function getMyActions($userId=null) {
33
		$apihost = Configure::read('apihost');
34
		$url = $apihost."user_actions/by/$userId";
35
		// $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']);
36
		return $this->make_request($url,null);
37
	}
38
 
14654 anikendra 39
	public function getLiveScore($userId=null) {
40
        $apihost = Configure::read('pythonapihost');
41
        $url = $apihost."liveCricketScore/";
42
        return $this->make_request($url,null);
43
    }
44
 
13565 anikendra 45
	public function make_request($url,$fields,$format='json'){
46
		$fields_string = '';
47
		if(!empty($fields)){
48
			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
49
			rtrim($fields_string, '&');
50
		}
51
		//open connection
52
		$ch = curl_init();
53
 
54
		//set the url, number of POST vars, POST data
55
		curl_setopt($ch,CURLOPT_URL, $url);
14318 anikendra 56
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
13565 anikendra 57
		curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
14318 anikendra 58
		curl_setopt($ch, CURLOPT_USERPWD, "dtr:dtr18Feb2015");
13565 anikendra 59
		if(!empty($fields)) {
60
			curl_setopt($ch,CURLOPT_POST, count($fields));
61
			curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
62
		}
63
		//execute post
64
		$result = curl_exec($ch);
65
		//close connection
66
		curl_close($ch);
67
		switch($format){
68
			case 'json':
69
			$response = json_decode($result,1);
70
			break;
71
		}
72
		return $response;	
73
	}
74
 
75
}