Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
15604 anikendra 1
<?php
2
class UserpusherShell extends AppShell {
3
    public $uses = array('User');
4
 
5
    public function main() {
6
		Configure::load('live');
7
		$options = array('conditions'=>array('activated'=>1),'recursive'=>-1);
8
		$users = $this->User->find('all',$options);
15606 anikendra 9
		$pmaurl = Configure::read('pmaurl');
15604 anikendra 10
		if(!empty($users)) {
11
			foreach($users AS $user) {
12
				$data = array('id'=>$user['User']['id'],'email'=>$user['User']['email'],'mobilenumber'=>$user['User']['mobilenumber'],'name'=>$user['User']['first_name'],'referral_code'=>$user['User']['referrer']);
13
				$this->make_request($pmaurl.'/identify',$data);	
14
			}
15
		}
16
    }
17
 
18
    private function make_request($url,$fields,$format='json'){
18594 amit.gupta 19
		//$this->out("[url] $url");
20
		//$this->out("[fields] ".print_r($fields,1));
21
		//$this->log("[url] $url",'api');
22
		//$this->log("[fields] ".print_r($fields,1),'api');
15604 anikendra 23
		$fields_string = '';
24
		//open connection
25
		$ch = curl_init();
26
		//execute post
27
		foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
28
		rtrim($fields_string, '&');
29
		//set the url, number of POST vars, POST data
30
		curl_setopt($ch,CURLOPT_URL, $url);
31
		curl_setopt($ch,CURLOPT_POST, count($fields));
32
		curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
33
		$result = curl_exec($ch);
34
		$this->out("[response] ".print_r($result,1));
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
}