Subversion Repositories SmartDukaan

Rev

Rev 13583 | Rev 14654 | 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
 
13565 anikendra 39
	public function make_request($url,$fields,$format='json'){
40
		$fields_string = '';
41
		if(!empty($fields)){
42
			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
43
			rtrim($fields_string, '&');
44
		}
45
		//open connection
46
		$ch = curl_init();
47
 
48
		//set the url, number of POST vars, POST data
49
		curl_setopt($ch,CURLOPT_URL, $url);
14318 anikendra 50
		curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
13565 anikendra 51
		curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
14318 anikendra 52
		curl_setopt($ch, CURLOPT_USERPWD, "dtr:dtr18Feb2015");
13565 anikendra 53
		if(!empty($fields)) {
54
			curl_setopt($ch,CURLOPT_POST, count($fields));
55
			curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
56
		}
57
		//execute post
58
		$result = curl_exec($ch);
59
		//close connection
60
		curl_close($ch);
61
		switch($format){
62
			case 'json':
63
			$response = json_decode($result,1);
64
			break;
65
		}
66
		return $response;	
67
	}
68
 
69
}