Subversion Repositories SmartDukaan

Rev

Rev 13567 | Go to most recent revision | Details | 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) {
12
		$url = "http://api.profittill.com/store_products/index/$userId/page:$page";
13
		$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']);
14
		return $this->make_request($url,null);
15
	}
16
 
17
	public function make_request($url,$fields,$format='json'){
18
		$fields_string = '';
19
		if(!empty($fields)){
20
			foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
21
			rtrim($fields_string, '&');
22
		}
23
		//open connection
24
		$ch = curl_init();
25
 
26
		//set the url, number of POST vars, POST data
27
		curl_setopt($ch,CURLOPT_URL, $url);
28
		curl_setopt($ch,CURLOPT_RETURNTRANSFER , true);
29
		if(!empty($fields)) {
30
			curl_setopt($ch,CURLOPT_POST, count($fields));
31
			curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
32
		}
33
		//execute post
34
		$result = curl_exec($ch);
35
		//close connection
36
		curl_close($ch);
37
		switch($format){
38
			case 'json':
39
			$response = json_decode($result,1);
40
			break;
41
		}
42
		return $response;	
43
	}
44
 
45
}