Skip to content

Commit

Permalink
ready for first test
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrax committed Mar 15, 2021
1 parent f2ce54e commit d6020f7
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":222:{a:2:{s:7:"defects";a:1:{s:43:"Epmnzava\Bulksms\Tests\SendSmsTest::sendSms";i:5;}s:5:"times";a:2:{s:48:"Epmnzava\Bulksms\Tests\ExampleTest::true_is_true";d:0.556;s:43:"Epmnzava\Bulksms\Tests\SendSmsTest::sendSms";d:1.787;}}}
4 changes: 2 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

"sender_id"=>env("BULKSMS_SENDERID","INFO"),

"api_secret"=>env("BULKSMS_SECRET"),
"token_secret"=>env("BULKSMS_SECRET","ltTQfMQWrJF*cocCx2meq2u4kIbH_"),

"api_id"=>env("BULKSMS_ID"),
"token_id"=>env("BULKSMS_ID"),



Expand Down
32 changes: 32 additions & 0 deletions src/ApiUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,36 @@
class ApiUtil
{

/**
* @param $post_body
* @param $url
* @param $username
* @param $password
* @return array
*
*/
public function send_message ( $post_body, $url, $username, $password) {
$ch = curl_init( );
$headers = array(
'Content-Type:application/json',
'Authorization:Basic '. base64_encode("$username:$password")
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_body );
// Allow cUrl functions 20 seconds to execute
curl_setopt ( $ch, CURLOPT_TIMEOUT, 20 );
// Wait 10 seconds while trying to connect
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
$output = array();
$output['server_response'] = curl_exec( $ch );
$curl_info = curl_getinfo( $ch );
$output['http_status'] = $curl_info[ 'http_code' ];
$output['error'] = curl_error($ch);
curl_close( $ch );
return $output;
}

}
31 changes: 30 additions & 1 deletion src/Bulksms.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ class Bulksms
{


protected static $statusMessages = array(
0 => 'In progress',
10 => 'Delivered upstream',
11 => 'Delivered mobile',
12 => 'Delivered upstream unacknowledged (presume in progress)',
1 => 'Scheduled',
22 => 'Internal fatal error',
23 => 'Authentication error',
24 => 'Data validation failed',
25 => 'Insufficient credits',
26 => 'Upstream credits not available',
27 => 'Daily quota exceeded',
28 => 'Upstream quota exceeded',
40 => 'Temporarily unavailable',
201 => 'Maximum batch size exceeded',
);
/**
* @param $recepient
* @param String $message
Expand All @@ -23,9 +39,22 @@ class Bulksms
* /messages?auto-unicode=true&longMessageMaxParts=30
* Functiont to send sms
*/
public function sendMessage($recepient,String $message)
public function sendMessage($recepient,String $message) : Array
{

$username = config('bulksms.token_id');
$password = config('bulksms.secret');
$messages = array(
array('to'=>$recepient, $message),
);

$api=new ApiUtil;

$result=$api->send_message(json_encode($messages),config('bulksms.base_endpoint').'/messages?auto-unicode=true&longMessageMaxParts=30',$username,$password);

return $result;



}

Expand Down
30 changes: 30 additions & 0 deletions tests/SendSmsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php


namespace Epmnzava\Bulksms\Tests;


use Epmnzava\Bulksms\Bulksms;
use Epmnzava\Bulksms\BulksmsServiceProvider;
use Orchestra\Testbench\TestCase;

class SendSmsTest extends TestCase
{

protected function getPackageProviders($app)
{
return [BulksmsServiceProvider::class];
}

/** @test */
public function sendSms()
{

$sms=new Bulksms;

$sms->sendMessage("255679079774","hellow man");

//$this->assertTrue(true);
}

}

0 comments on commit d6020f7

Please sign in to comment.