<commit_before><?php
/**
 * Mailin REST client
 */ 
class Mailin
{
	public $access_key;
	public $secret_key;
	public $base_url;
	public $curl_opts = array();
	public function __construct($base_url,$access_key,$secret_key) 
	{
		if(!function_exists('curl_init')) 
		{
			throw new Exception('Mailin requires CURL module');
		}
		$this->base_url = $base_url;
		$this->access_key = $access_key;
		$this->secret_key = $secret_key;
	}
	/**
	 * Do CURL request with authorization
	 */
	private function do_request($resource,$method,$input)
	{
		$called_url = $this->base_url."/".$resource;
		$ch = curl_init($called_url);
		$c_date_time = date("r");
		$md5_content = "";
		if($input!="") {
		  $md5_content = md5($input);
		}
		$content_type = "application/json";
		$sign_string = $method."\n".$md5_content."\n".$content_type."\n".$c_date_time."\n".$called_url;
		$time_header = 'X-mailin-date:'.$c_date_time;
		$auth_header = 'Authorization:'.$this->access_key.":".base64_encode(hash_hmac('sha1' , utf8_encode($sign_string) ,$this->secret_key));
		$content_header = "Content-Type:application/json";
		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
			// Windows only over-ride
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		}
		curl_setopt($ch, CURLOPT_HTTPHEADER, array($time_header,$auth_header,$content_header));
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
		$data = curl_exec($ch);
		if(curl_errno($ch))
		{
    		echo 'Curl error: ' . curl_error($ch). '\n';
		}
		curl_close($ch);
		return json_decode($data,true);
	}
	public function get($resource,$input)
	{
		return $this->do_request($resource,"GET",$input);
	}	
	public function put($resource,$input)
	{
		return $this->do_request($resource,"PUT",$input);
	}
	public function post($resource,$input)
	{
		return $this->do_request($resource,"POST",$input);
	}
	public function delete($resource,$input)
	{
		return $this->do_request($resource,"DELETE",$input);
	}
        public function get_account()
        {
                return $this->get("account","");
        }
        public function create_child_account($email,$password,$company_org,$first_name,$last_name,$credits)
        {
                return $this->post("account",json_encode(array("email"=>$email,"password"=>$password,"company_org"=>$company_org,"first_name"=>$first_name,"last_name"=>$last_name,"credits"=>$credits)));
        }
        public function send_sms($to,$from,$text,$web_url,$tag)
        {
                return $this->post("sms",json_encode(array("text"=>$text,"tag"=>$tag,"web_url"=>$web_url,"from"=>$from,"to"=>$to)));
        }
        public function create_sms_campaign($camp_name,$sender,$content,$bat_sent,$listids,$exclude_list,$scheduled_date)
        {
                return $this->post("sms",json_encode(array("name"=>$camp_name,"sender"=>$sender,"content"=>$content,"bat"=>$bat_sent,"listid"=>$listids,"exclude_list"=>$exclude_list, "scheduled_date"=>$scheduled_date)));
        }
        public function update_sms_campaign($id,$camp_name,$sender,$content,$bat_sent,$listids,$exclude_list,$scheduled_date)
        {
                return $this->put("sms/".$id,json_encode(array("name"=>$camp_name,"sender"=>$sender,"content"=>$content,"bat"=>$bat_sent,"listid"=>$listids,"exclude_list"=>$exclude_list, "scheduled_date"=>$scheduled_date)));
        }
        public function send_bat_sms($campid,$mobilephone)
        {
                return $this->get("sms/".$campid,json_encode(array("to"=>$mobilephone)));
        }
        public function get_campaigns($type)
        {
                return $this->get("campaign",json_encode(array("type"=>$type)));
        }
        public function get_campaign($id)
        {
                return $this->get("campaign/".$id,"");
        }
        public function create_campaign($category,$from_name,$name,$bat_sent,$html_content,$html_url,$listid,$scheduled_date,$subject,$from_email,$reply_to,$to_field,$exclude_list)
        {
                return $this->post("campaign",json_encode(array("category"=>$category,"from_name"=>$from_name,"name"=>$name,"bat"=>$bat_sent,"html_content"=>$html_content,"html_url"=>$html_url,"listid"=>$listid,"scheduled_date"=>$scheduled_date,"subject"=>$subject,"from_email"=>$from_email,"reply_to"=>$reply_to,"to_field"=>$to_field,'exclude_list'=>$exclude_list)));
        }
        public function delete_campaign($id)
        {<commit_msg>modified email parameter in create_child_account<commit_after><?php
/**
 * Mailin REST client
 */ 
class Mailin
{
	public $access_key;
	public $secret_key;
	public $base_url;
	public $curl_opts = array();
	public function __construct($base_url,$access_key,$secret_key) 
	{
		if(!function_exists('curl_init')) 
		{
			throw new Exception('Mailin requires CURL module');
		}
		$this->base_url = $base_url;
		$this->access_key = $access_key;
		$this->secret_key = $secret_key;
	}
	/**
	 * Do CURL request with authorization
	 */
	private function do_request($resource,$method,$input)
	{
		$called_url = $this->base_url."/".$resource;
		$ch = curl_init($called_url);
		$c_date_time = date("r");
		$md5_content = "";
		if($input!="") {
		  $md5_content = md5($input);
		}
		$content_type = "application/json";
		$sign_string = $method."\n".$md5_content."\n".$content_type."\n".$c_date_time."\n".$called_url;
		$time_header = 'X-mailin-date:'.$c_date_time;
		$auth_header = 'Authorization:'.$this->access_key.":".base64_encode(hash_hmac('sha1' , utf8_encode($sign_string) ,$this->secret_key));
		$content_header = "Content-Type:application/json";
		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
			// Windows only over-ride
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		}
		curl_setopt($ch, CURLOPT_HTTPHEADER, array($time_header,$auth_header,$content_header));
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $input);
		$data = curl_exec($ch);
		if(curl_errno($ch))
		{
    		echo 'Curl error: ' . curl_error($ch). '\n';
		}
		curl_close($ch);
		return json_decode($data,true);
	}
	public function get($resource,$input)
	{
		return $this->do_request($resource,"GET",$input);
	}	
	public function put($resource,$input)
	{
		return $this->do_request($resource,"PUT",$input);
	}
	public function post($resource,$input)
	{
		return $this->do_request($resource,"POST",$input);
	}
	public function delete($resource,$input)
	{
		return $this->do_request($resource,"DELETE",$input);
	}
        public function get_account()
        {
                return $this->get("account","");
        }
        public function create_child_account($email,$password,$company_org,$first_name,$last_name,$credits)
        {
                return $this->post("account",json_encode(array("child_email"=>$email,"password"=>$password,"company_org"=>$company_org,"first_name"=>$first_name,"last_name"=>$last_name,"credits"=>$credits)));
        }
        public function send_sms($to,$from,$text,$web_url,$tag)
        {
                return $this->post("sms",json_encode(array("text"=>$text,"tag"=>$tag,"web_url"=>$web_url,"from"=>$from,"to"=>$to)));
        }
        public function create_sms_campaign($camp_name,$sender,$content,$bat_sent,$listids,$exclude_list,$scheduled_date)
        {
                return $this->post("sms",json_encode(array("name"=>$camp_name,"sender"=>$sender,"content"=>$content,"bat"=>$bat_sent,"listid"=>$listids,"exclude_list"=>$exclude_list, "scheduled_date"=>$scheduled_date)));
        }
        public function update_sms_campaign($id,$camp_name,$sender,$content,$bat_sent,$listids,$exclude_list,$scheduled_date)
        {
                return $this->put("sms/".$id,json_encode(array("name"=>$camp_name,"sender"=>$sender,"content"=>$content,"bat"=>$bat_sent,"listid"=>$listids,"exclude_list"=>$exclude_list, "scheduled_date"=>$scheduled_date)));
        }
        public function send_bat_sms($campid,$mobilephone)
        {
                return $this->get("sms/".$campid,json_encode(array("to"=>$mobilephone)));
        }
        public function get_campaigns($type)
        {
                return $this->get("campaign",json_encode(array("type"=>$type)));
        }
        public function get_campaign($id)
        {
                return $this->get("campaign/".$id,"");
        }
        public function create_campaign($category,$from_name,$name,$bat_sent,$html_content,$html_url,$listid,$scheduled_date,$subject,$from_email,$reply_to,$to_field,$exclude_list)
        {
                return $this->post("campaign",json_encode(array("category"=>$category,"from_name"=>$from_name,"name"=>$name,"bat"=>$bat_sent,"html_content"=>$html_content,"html_url"=>$html_url,"listid"=>$listid,"scheduled_date"=>$scheduled_date,"subject"=>$subject,"from_email"=>$from_email,"reply_to"=>$reply_to,"to_field"=>$to_field,'exclude_list'=>$exclude_list)));
        }
        public function delete_campaign($id)
        {
{'fraction_non_alphanumeric': 0.1866492431667211, 'fraction_numerical': 0.002831318741152129, 'mean_word_length': 4.7652228499686125, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 121, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '41865', 'n_tokens_mistral': 3353, 'n_tokens_neox': 3142, 'n_words': 346}