Skip to content

Commit

Permalink
Merge pull request #7 from descom-es/senderid
Browse files Browse the repository at this point in the history
new function getSenderID
  • Loading branch information
cesargb authored Sep 15, 2017
2 parents f35f915 + 1d167fc commit 6f1cf15
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ $balance = $sms->getBalance();
echo 'Your balance is '.$balance."\n";
```

### Get list of senderID authorized

The function `getSenderID` allows you get the list of senderID authorized. Example:

```php
$sms = new Sms(new AuthUser('replace_by_your_usernme', 'replace_by_your_password'));

$senderID = $sms->getSenderID();

echo 'Your balance is '.PHP_EOL;
print_r($senderID);
```

### Setup your sender ID

Alphanumeric sender ID allows you to set your name or business brand as the sender ID. Use the function `setSenderID` at `Descom\Sms\Sms` class
Expand Down
21 changes: 21 additions & 0 deletions examples/getSenderID.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Descom\Sms\Auth\AuthUser;
use Descom\Sms\Sms;

require '../vendor/autoload.php';

if ($argc < 3) {
echo 'Usage '.$argv[0]." username password.\n";
exit(1);
}

$sms = new Sms(new AuthUser($argv[1], $argv[2]));

$serderID = $sms->getSenderID();

echo 'senderID Authorized:'.PHP_EOL;

foreach ($serderID as $value) {
echo "\t".'- '.$value.PHP_EOL;
}
20 changes: 20 additions & 0 deletions src/Sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ public function getBalance()
}
}

/**
* Get the list with authorized senderID.
*
* @return array
*/
public function getSenderID()
{
$http = new Http();

$response = $http->sendHttp('GET', 'senderID', $this->headers);

if ($response->status == 200) {
$data = json_decode($response->message);

return $data;
} else {
throw new RequestFail($response->message, $response->status);
}
}

/**
* Send SMS's to the platform.
*
Expand Down
26 changes: 26 additions & 0 deletions tests/SmsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,30 @@ public function test_if_get_id_of_shipment_when_send_sms()

$this->assertGreaterThan(1, $result->id);
}

/** @test */
public function test_if_senderID_info_is_authorized()
{
$sms = new Sms($this->authOK);

$senderID = $sms->getSenderID();

$this->assertContains(
'info',
$senderID
);
}

/** @test */
public function test_if_senderID_perverso_is_not_authorized()
{
$sms = new Sms($this->authOK);

$senderID = $sms->getSenderID();

$this->assertNotContains(
'perverso',
$senderID
);
}
}

0 comments on commit 6f1cf15

Please sign in to comment.