Sample Class for making api call using twillo

<?php
require __DIR__ . ‘/third_party_apps/twilio-php-master/Twilio/autoload.php’;
use Twilio\Rest\Client;
Class SMS
{
public $to;
public $message;
public $parameter;
private $messageTemplete;

public function pleaseSendMessage()
{
// Use the REST API Client to make requests to the Twilio REST API
// Your Account SID and Auth Token from twilio.com/console
$sid = ”;
$token = ”;
$client = new Client($sid, $token);

// Use the client to do fun stuff like send text messages!
print_r($client->messages->create(
// the number you’d like to send the message to
“”,
array(
// A Twilio phone number you purchased at twilio.com/console
‘from’ => ”,
// the body of the text message you’d like to send
‘body’ => $this->getFinalMessage()
)
));

echo $this->getFinalMessage();

}

public function set($key,$value)
{
$this->parameter[“$key”] =$value;
}

public function get($key)
{
return $this->parameter[“$key”] ;
}
private function getFinalMessage()
{
if(strlen($this->messageTemplete)>10)
{
return $this->messageTemplete;
}
else
{
return $this->message;
}
}

public function pleaseKeeplog()
{
$rb = R::xdispense(“sms_log”);
$rb->current_time = R::isoDateTime();
$rb->message = $this->getFinalMessage();

if(isset($this->parameter[“pay_to_id”]))
{
$rb->pay_to_id = intval($this->parameter[“pay_to_id”]);
}

if(isset($this->parameter[“pay_from_id”]))
{
$rb->pay_from_id = intval($this->parameter[“pay_from_id”]);
}

if(isset($this->parameter[“local_charge”]))
{
$rb->local_charge = intval($this->parameter[“local_charge”]);
}

if(isset($this->parameter[“store_id”]))
{
$rb->store_id = intval($this->parameter[“store_id”]);
}

if(isset($this->parameter[“shift_number”]))
{
$rb->shift_number= intval($this->parameter[“shift_number”]);
}
if(isset($this->parameter[“shift_date”]))
{
$rb->shift_date= intval($this->parameter[“shift_date”]);
}

if(isset($this->parameter[“shift_from_time”]))
{
$rb->shift_from_time= intval($this->parameter[“shift_from_time”]);
}
if(isset($this->parameter[“shift_to_time”]))
{
$rb->shift_to_time= intval($this->parameter[“shift_to_time”]);
}
R::store($rb);
}
public function prepareMessage()
{
$this->messageTemplete = “Sample Message”;
}

}
?>

 
$sms = new SMS();
$sms->set(“to”,””);
$sms->set(“pay_to_name”,””);
$sms->prepareMessage();
$sms->pleaseKeeplog();
$sms->pleaseSendMessage();

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s