Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15403 manish.sha 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
 
11
	public function getDeals($userId=null,$page=1) {
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']);
15
		return $this->make_request($url,null);
16
	}
17
 
18
	public function getDealsByCategory($userId=null,$categoryId=null,$page=1) {
19
		$apihost = Configure::read('apihost');
20
		$url = $apihost."store_products/category/$userId/$categoryId/page:$page";
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
 
25
	public function getCategoryDeals($userId=null,$page=1) {
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
 
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
 
39
	public function getLiveScore($userId=null) {
40
        $apihost = Configure::read('pythonapihost');
41
        $url = $apihost."liveCricketScore/";
42
        return $this->make_request($url,null);
43
    }
44
 
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
		$additionalHeaders = '';
54
		//set the url, number of POST vars, POST data
55
		curl_setopt($ch,CURLOPT_URL, $url);
56
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
57
		curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
58
		curl_setopt($ch, CURLOPT_USERPWD, "dtr:dtr18Feb2015");
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
}