Skip to content

Commit

Permalink
add history, numbers, reports and numbers actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ossycodes committed Sep 21, 2023
1 parent ae98acc commit 0b1c899
Show file tree
Hide file tree
Showing 13 changed files with 376 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Actions/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

namespace Ossycodes\Nigeriabulksms\Actions;

use Ossycodes\Nigeriabulksms\Objects\Balance;
use Ossycodes\Nigeriabulksms\Objects\History;
use Ossycodes\Nigeriabulksms\Objects\Numbers;
use Ossycodes\Nigeriabulksms\Objects\Profile;
use Ossycodes\Nigeriabulksms\Objects\Reports;
use Ossycodes\Nigeriabulksms\Objects\BaseList;
use Ossycodes\Nigeriabulksms\Objects\Contacts;
use Ossycodes\Nigeriabulksms\Objects\Payments;
use Ossycodes\Nigeriabulksms\Common\HttpClient;
use Ossycodes\Nigeriabulksms\Common\ResponseError;
use Ossycodes\Nigeriabulksms\Objects\BalanceResponse;
use Ossycodes\Nigeriabulksms\Objects\HistoryResponse;
use Ossycodes\Nigeriabulksms\Objects\ProfileResponse;
use Ossycodes\Nigeriabulksms\Objects\ReportsResponse;
use Ossycodes\Nigeriabulksms\Objects\ContactsResponse;
use Ossycodes\Nigeriabulksms\Objects\PaymentsResponse;
use Ossycodes\Nigeriabulksms\Exceptions\ServerException;
use Ossycodes\Nigeriabulksms\Exceptions\RequestException;

Expand All @@ -25,12 +37,12 @@ class Base
protected $actionName;

/**
* @var Objects\Hlr|Objects\Message|Objects\Balance|Objects\Verify|Objects\Lookup|Objects\VoiceMessage|Objects\Conversation\Conversation
* @var Balance|Contacts|History|Numbers|Payments|Profile|Reports
*/
protected $object;

/**
* @var BalanceResponse
* @var BalanceResponse|ContactsResponse|HistoryResponse|PaymentsResponse|ProfileResponse|ReportsResponse
*/
protected $responseObject;

Expand Down
24 changes: 24 additions & 0 deletions src/Actions/History.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Ossycodes\Nigeriabulksms\Actions;

use Ossycodes\Nigeriabulksms\Common\HttpClient;
use Ossycodes\Nigeriabulksms\Objects\HistoryResponse;
use Ossycodes\Nigeriabulksms\Objects\History as HistoryObject;

/**
* Class History
*/
class History extends Base
{
public function __construct(HttpClient $httpClient)
{
$this->object = new HistoryObject();

$this->setActionName('history');

$this->setResponseObject(new HistoryResponse());

parent::__construct($httpClient);
}
}
24 changes: 24 additions & 0 deletions src/Actions/Numbers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Ossycodes\Nigeriabulksms\Actions;

use Ossycodes\Nigeriabulksms\Common\HttpClient;
use Ossycodes\Nigeriabulksms\Objects\NumbersResponse;
use Ossycodes\Nigeriabulksms\Objects\Numbers as NumbersObject;

/**
* Class Numbers
*/
class Numbers extends Base
{
public function __construct(HttpClient $httpClient)
{
$this->object = new NumbersObject();

$this->setActionName('numbers');

$this->setResponseObject(new NumbersResponse());

parent::__construct($httpClient);
}
}
24 changes: 24 additions & 0 deletions src/Actions/Reports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Ossycodes\Nigeriabulksms\Actions;

use Ossycodes\Nigeriabulksms\Common\HttpClient;
use Ossycodes\Nigeriabulksms\Objects\ReportsResponse;
use Ossycodes\Nigeriabulksms\Objects\Reports as ReportsObject;

/**
* Class Reports
*/
class Reports extends Base
{
public function __construct(HttpClient $httpClient)
{
$this->object = new ReportsObject();

$this->setActionName('reports');

$this->setResponseObject(new ReportsResponse());

parent::__construct($httpClient);
}
}
21 changes: 21 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Ossycodes\Nigeriabulksms\Actions\Contacts;
use Ossycodes\Nigeriabulksms\Actions\Payments;
use Ossycodes\Nigeriabulksms\Actions\Profile;
use Ossycodes\Nigeriabulksms\Actions\History;
use Ossycodes\Nigeriabulksms\Actions\Numbers;
use Ossycodes\Nigeriabulksms\Actions\Reports;
use Ossycodes\Nigeriabulksms\Common\HttpClient;

/**
Expand Down Expand Up @@ -48,6 +51,21 @@ class Client
*/
public $contacts;

/**
* @var History
*/
public $history;

/**
* @var Numbers
*/
public $numbers;

/**
* @var Reports
*/
public $reports;

public function __construct(Configuration $config, ?HttpClient $httpClient = null)
{
$this->config = $config;
Expand All @@ -68,6 +86,9 @@ public function __construct(Configuration $config, ?HttpClient $httpClient = nul
$this->payments = new Payments($this->httpClient);
$this->profile = new Profile($this->httpClient);
$this->contacts = new Contacts($this->httpClient);
$this->history = new History($this->httpClient);
$this->numbers = new Numbers($this->httpClient);
$this->reports = new Reports($this->httpClient);
}

private function getPhpVersion(): string
Expand Down
26 changes: 26 additions & 0 deletions src/Examples/historyView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

require_once(__DIR__ . '/../autoload.php');

$config = \Ossycodes\Nigeriabulksms\Configuration::getDefaultConfiguration()
->setUsername('YOUR_USERNAME')
->setPassword('YOUR_PASSWORD')
->setTimeout(10) //optional defaults to 10
->setConnectionTimeout(2); //optional defaults to 2

$client = new \Ossycodes\Nigeriabulksms\Client($config);

try {
$history = $client->history->read();
var_dump($history);
} catch (\Ossycodes\Nigeriabulksms\Exceptions\AuthenticateException $e) {
// That means that your username and/or password is incorrect
echo 'wrong login';
}
catch (\Ossycodes\Nigeriabulksms\Exceptions\BalanceException $e) {
// That means that your balance is insufficient
echo 'insufficient balance';
}
catch (\Exception $e) {
var_dump($e->getMessage());
}
34 changes: 34 additions & 0 deletions src/Examples/listNumbers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

require_once(__DIR__ . '/../autoload.php');

$config = \Ossycodes\Nigeriabulksms\Configuration::getDefaultConfiguration()
->setUsername('YOUR_USERNAME')
->setPassword('YOUR_PASSWORD')
->setTimeout(10) //optional defaults to 10
->setConnectionTimeout(2); //optional defaults to 2

$client = new \Ossycodes\Nigeriabulksms\Client($config);

try {
$numbers = $client->numbers->getList();
var_dump($numbers);

//iterate through each payment item
foreach($client->numbers->getList()->getItems() as $number) {
dump($payment->amount);
dump($payment->reference);
dump($payment->date);
}

} catch (\Ossycodes\Nigeriabulksms\Exceptions\AuthenticateException $e) {
// That means that your username and/or password is incorrect
echo 'wrong login';
}
catch (\Ossycodes\Nigeriabulksms\Exceptions\BalanceException $e) {
// That means that your balance is insufficient
echo 'insufficient balance';
}
catch (\Exception $e) {
var_dump($e->getMessage());
}
39 changes: 39 additions & 0 deletions src/Objects/History.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Ossycodes\Nigeriabulksms\Objects;

use stdClass;

/**
* Class History
*/
class History extends Base
{
/**
* @var string
*/
public $name;

/**
* @var string
*/
public $username;

/**
* @var string
*/
public $mobile;

/**
* @var string
*/
public $sender;


public function loadFromStdclass(stdClass $object): self
{
parent::loadFromStdclass($object);

return $this;
}
}
38 changes: 38 additions & 0 deletions src/Objects/HistoryResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Ossycodes\Nigeriabulksms\Objects;

use stdClass;

/**
* Class HistoryResponse
*/
class HistoryResponse extends Base
{
/**
* @var string
*/
public $name;

/**
* @var string
*/
public $username;

/**
* @var string
*/
public $mobile;

/**
* @var string
*/
public $sender;

public function loadFromStdclass(stdClass $object): self
{
parent::loadFromStdclass($object);

return $this;
}
}
33 changes: 33 additions & 0 deletions src/Objects/Numbers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Ossycodes\Nigeriabulksms\Objects;

use stdClass;

/**
* Class Numbers
*/
class Numbers extends Base
{
/**
* @var int
*/
public $id;

/**
* @var string
*/
public $name;

/**
* @var string
*/
public $mobile;

public function loadFromStdclass(stdClass $object): self
{
parent::loadFromStdclass($object);

return $this;
}
}
33 changes: 33 additions & 0 deletions src/Objects/NumbersResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Ossycodes\Nigeriabulksms\Objects;

use stdClass;

/**
* Class NumbersResponse
*/
class NumbersResponse extends Base
{
/**
* @var int
*/
public $id;

/**
* @var string
*/
public $name;

/**
* @var string
*/
public $mobile;

public function loadFromStdclass(stdClass $object): self
{
parent::loadFromStdclass($object);

return $this;
}
}
33 changes: 33 additions & 0 deletions src/Objects/Reports.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Ossycodes\Nigeriabulksms\Objects;

use stdClass;

/**
* Class Reports
*/
class Reports extends Base
{
/**
* @var string
*/
public $amount;

/**
* @var null|string
*/
public $reference;

/**
* @var string
*/
public $date;

public function loadFromStdclass(stdClass $object): self
{
parent::loadFromStdclass($object);

return $this;
}
}
Loading

0 comments on commit 0b1c899

Please sign in to comment.