Skip to content

Commit

Permalink
Merge pull request #6 from elmage/v0.2.0
Browse files Browse the repository at this point in the history
V0.2.0
  • Loading branch information
elmage authored Aug 20, 2020
2 parents c7b2fc3 + cc42307 commit 1258a6a
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 12 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

All notable changes to `elmage/textng-php` will be documented in this file.
All notable changes to this project will be documented in this file.

Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.

## [Unreleased]
## [0.2.0] - 2020-08-20
### Added
- Wrapper method for createCustomer endpoint
- Wrapper method for removeCustomer endpoint
### Changed
- Updated the `README.md` file to show usage for both `createCustomer` and
`removeCustomer` methods
- Populated this CHANGELOG file
## [0.1.1] - 2020-08-19
### Fixed
- A bug with the HttpClient where post request parameters could not be read by the API
server due to the wrong `Content-Type` Header

## [0.1.0] - 2020-08-19
### Added
- TextNg API Library

[unreleased]: https://github.com/elmage/textng-php/compare/v0.2.0...HEAD
[0.2.0]: https://github.com/elmage/textng-php/compare/post-content-type-fix...v0.2.0
[0.1.1]: https://github.com/elmage/textng-php/releases/tag/v0.1.1
[0.1.0]: https://github.com/elmage/textng-php/releases/tag/v0.1.0
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ This is not intended to provide complete documentation of the API. For more deta
**Get Unit Balance**

```php
$currencies = $client->getBalance();
$response = $client->getBalance();
```
**Send SMS**

```php
$currencies = $client->sendSMS($route, $phoneNumbers, $message, $bypassCode, $optionalParamsArray);
$response = $client->sendSMS($route, $phoneNumbers, $message, $bypassCode, $optionalParamsArray);
```


Expand All @@ -48,16 +48,28 @@ $currencies = $client->sendSMS($route, $phoneNumbers, $message, $bypassCode, $op
// and calls $client->sendSMS(..., [$phoneNumber], ...)
// passing the supplied phone number as the single element in an array

$currencies = $client->sendOTP($route = 3, $phoneNumber, $message, $bypassCode, $optionalParamsArray);
$response = $client->sendOTP($route, $phoneNumber, $message, $bypassCode, $optionalParamsArray);
```

**Get Delivery Report**

```php
$currencies = $client->getDeliveryReport($reference, $req, $used_route);
$response = $client->getDeliveryReport($reference, $req, $used_route);
```
```$req``` can take one of the 3 values ```all```, ```dnd``` or ```success``` (as specified in the [API DOCs](https://textng.xyz/api))
```$req``` can take one of the 3 values ```all```, ```dnd``` or ```success``` (as specified in the [API DOC](https://textng.xyz/api))

**Create Customer**

```php
$response = $client->createCustomer($customerName, $customerPhone, $categoryID);
```
```$categoryID``` is the category url ID generated for each url link you create. (as specified in the [API DOC](https://textng.xyz/api/#addcustomer))

**Remove Customer**

```php
$response = $client->removeCustomer($customerPhone, $categoryID);
```

## Change log

Expand Down
46 changes: 46 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,52 @@ public function sendSMS(
return $this->makeRequest('/pushsms/', 'post', $params);
}

/**
* add customer to category list.
*
* @param string $customerName
* @param string $customerPhone
* @param $categoryID
*
* @return array
*/
public function createCustomer(string $customerName, string $customerPhone, string $categoryID): array
{
$params = array(
Param::CUSTOMER_NAME => $customerName,
Param::CUSTOMER_PHONE => $customerPhone,
Param::CATEGORY_ID => $categoryID,
);

return $this->makeRequest('/addcustomer/', 'get', $params);
}

/**remove customer from category list
*
*
* @param string $customerPhone
* @param $categoryID
* @return array
*/
public function removeCustomer(string $customerPhone, string $categoryID): array
{
$params = array(
Param::CUSTOMER_PHONE => $customerPhone,
Param::CATEGORY_ID => $categoryID,
);

return $this->makeRequest('/removecustomer/', 'get', $params);
}

/**
* Get delivery report for an SMS transaction.
*
* @param string $reference
* @param $req
* @param $used_route
*
* @return array
*/
public function getDeliveryReport(string $reference, $req, $used_route)
{
if (!in_array($used_route, Route::$routes)) {
Expand Down
4 changes: 4 additions & 0 deletions src/Enum/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ class Param
const REFERENCE = 'reference';
const REQ = 'req';
const USED_ROUTE = 'used_route';

const CUSTOMER_NAME = 'customername';
const CUSTOMER_PHONE = 'customerphone';
const CATEGORY_ID = 'catid';
}
136 changes: 132 additions & 4 deletions tests/Unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ protected function tearDown(): void

public function testGetBalance()
{
$resText = '{"D":{"details":[' .
'{"key":"TEST_KEY","unitsbalance":"20","time":"2000-01-01 01:10:15","status":"successful"}' .
']}}';

$this->http->expects($this->any())
->method('get')
->with('/smsbalance/', [Param::CHECK_BALANCE => 1])
->willReturn($this->getMockResponse('{"D":{"details":[{"key":"TEST_KEY","unitsbalance":"20","time":"2000-01-01 01:10:15","status":"successful"}]}}'));
->willReturn($this->getMockResponse(
$resText
));

$actual = $this->client->getBalance();
$this->assertIsArray($actual, "Array expected, got " . gettype($actual));
Expand All @@ -69,7 +75,7 @@ public function testGetBalance()
}

/**
* @dataProvider provideFortestSendSMS
* @dataProvider provideForTestSendSMS
*/
public function testSendSMS(int $route, string $phone, string $message, string $sender, string $bypasscode)
{
Expand All @@ -82,7 +88,9 @@ public function testSendSMS(int $route, string $phone, string $message, string $
Param::SENDER => $sender,
Param::BYPASSCODE => $bypasscode
])
->willReturn($this->getMockResponse('5 units used|| Status:Successful|| Route:5|| Type:single number|| Reference:4567ygfrthyi'));
->willReturn($this->getMockResponse(
'5 units used|| Status:Successful|| Route:5|| Type:single number|| Reference:4567ygfrthyi'
));

$actual = $this->client->sendOTP($route, $phone, $message, $bypasscode);

Expand All @@ -95,7 +103,7 @@ public function testSendSMS(int $route, string $phone, string $message, string $
}
}

public function provideFortestSendSMS(): array
public function provideForTestSendSMS(): array
{
return [
//route phone message sender bypasscode
Expand All @@ -106,6 +114,126 @@ public function provideFortestSendSMS(): array
];
}


/**
* @dataProvider provideForTestCreateCustomer
*/
public function testCreateCustomer(
string $customerName,
string $customerPhone,
string $categoryID,
string $response,
array $keys = []
)
{
$this->http->expects($this->any())
->method('get')
->with('/addcustomer/', [
Param::CUSTOMER_NAME => $customerName,
Param::CUSTOMER_PHONE => $customerPhone,
Param::CATEGORY_ID => $categoryID,
])
->willReturn($this->getMockResponse($response));

$actual = $this->client->createCustomer($customerName, $customerPhone, $categoryID);
$this->assertIsArray($actual, "Array expected, got " . gettype($actual));

foreach ($keys as $key) {
$this->assertArrayHasKey($key, $actual, "Expected array to contain {$key}");
}
}

public function provideForTestCreateCustomer(): array
{
return [
//route phone message sender bypasscode
[
"Chidi",
'08060000000',
"675543987",
'{"D":{"details":[
{"customerphone":"08060000000","customername":"Chidi","catid":"675543987","status":"successful"}
]}}',
['customerphone', 'customername', 'catid', 'status']
],
[
"Samuel",
'08060000001',
"675543987",
'{"D":{"details":[
{"customerphone":"08060000001","customername":"Samuel","catid":"675543876",
"status":"error-customerphone-exists-in-category"}
]}}',
['customerphone', 'customername', 'catid', 'status']
],
[
"Grace",
'08060000002',
"675543987",
'{"D":{"details":[{"status":"customerphone-not-exists"}]}}',
['status']
]
];
}


/**
* @dataProvider provideForTestRemoveCustomer
*/
public function testRemoveCustomer(
string $customerPhone,
string $categoryID,
string $response,
array $keys = []
)
{
$this->http->expects($this->any())
->method('get')
->with('/removecustomer/', [
Param::CUSTOMER_PHONE => $customerPhone,
Param::CATEGORY_ID => $categoryID,
])
->willReturn($this->getMockResponse($response));

$actual = $this->client->removeCustomer($customerPhone, $categoryID);
$this->assertIsArray($actual, "Array expected, got " . gettype($actual));

foreach ($keys as $key) {
$this->assertArrayHasKey($key, $actual, "Expected array to contain {$key}");
}
}

public function provideForTestRemoveCustomer(): array
{
return [
//route phone message sender bypasscode
[
'08060000000',
"675543987",
'{"D":{"details":[
{"customerphone":"08060000000","customername":"Chidi","catid":"675543987","status":"successful"}
]}}',
['customerphone', 'customername', 'catid', 'status']
],
[
'08060000001',
"675543987",
'{"D":{"details":[
{"customerphone":"08060000001","customername":"Samuel","catid":"675543876",
"status":"error-customerphone-does-not-exists-in-category"}
]}}',
['customerphone', 'customername', 'catid', 'status']
],
[
'08060000002',
"675543987",
'{"D":{"details":[{"status":"customerphone-not-exists"}]}}',
['status']
]
];
}


public function testSendSMSErrorCase()
{
$this->http->expects($this->any())
Expand Down
2 changes: 0 additions & 2 deletions tests/Unit/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,4 @@ private function createHttpClient(ApiKeyAuthentication $auth): HttpClient
$this->transport
);
}

}

0 comments on commit 1258a6a

Please sign in to comment.