Subversion Repositories SmartDukaan

Rev

Rev 13565 | Rev 13570 | 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
 
11
	public function getDeals($userId=2,$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
 
13567 anikendra 18
	public function getDealsByCategory($userId=2,$categoryId=1,$page=1) {
19
		$apihost = Configure::read('apihost');
20
		$url = $apihost."store_products/bycategory/$userId/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=2,$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
 
13565 anikendra 32
	public function make_request($url,$fields,$format='json'){
33
		$fields_string = '';
34
		if(!empty($fields)){
35
			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
36
			rtrim($fields_string, '&');
37
		}
38
		//open connection
39
		$ch = curl_init();
40
 
41
		//set the url, number of POST vars, POST data
42
		curl_setopt($ch,CURLOPT_URL, $url);
43
		curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
44
		if(!empty($fields)) {
45
			curl_setopt($ch,CURLOPT_POST, count($fields));
46
			curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
47
		}
48
		//execute post
49
		$result = curl_exec($ch);
50
		//close connection
51
		curl_close($ch);
52
		switch($format){
53
			case 'json':
54
			$response = json_decode($result,1);
55
			break;
56
		}
57
		return $response;	
58
	}
59
 
60
}