Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portout + Sim Card + Tests #27

Merged
merged 10 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
require(dirname(__FILE__) . '/lib/Address.php');
require(dirname(__FILE__) . '/lib/BillingGroup.php');
require(dirname(__FILE__) . '/lib/InboundChannel.php');
require(dirname(__FILE__) . '/lib/SimCard.php');
require(dirname(__FILE__) . '/lib/Portout.php');

// Telnyx API: Connections
require(dirname(__FILE__) . '/lib/Connection.php');
Expand Down
60 changes: 60 additions & 0 deletions lib/Portout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Telnyx;

/**
* Class Portout
*
* @package Telnyx
*/
class Portout extends ApiResource
{

const OBJECT_NAME = "portout";

use ApiOperations\All;
use ApiOperations\Retrieve;

/**
* @param array|null $params
* @param array|string|null $options
*
* @return Authorize or reject portout request
*/
public function update_status($status)
{
$url = $this->instanceUrl() . '/' . $status;
list($response, $opts) = $this->_request('patch', $url, null, null);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $params
* @param array|string|null $options
*
* @return List all comments for a portout request
*/
public function list_comments()
{
$url = $this->instanceUrl() . '/comments';
list($response, $opts) = $this->_request('get', $url, null, null);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $params
* @param array|string|null $options
*
* @return List all comments for a portout request
*/
public function create_comment($params = null, $options = null)
{
$url = $this->instanceUrl() . '/comments';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}

}
64 changes: 64 additions & 0 deletions lib/SimCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Telnyx;

/**
* Class SimCard
*
* @package Telnyx
*/
class SimCard extends ApiResource
{

const OBJECT_NAME = "sim_card";

use ApiOperations\All;
use ApiOperations\Retrieve;
use ApiOperations\Update;

/**
* @param array|null $params
* @param array|string|null $options
*
* @return Request a SIM card activation
*/
public function activate($params = null, $options = null)
{
$url = $this->instanceUrl() . '/actions/activate';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $params
* @param array|string|null $options
*
* @return Request a SIM card deactivation
*/
public function deactivate($params = null, $options = null)
{
$url = $this->instanceUrl() . '/actions/deactivate';
list($response, $opts) = $this->_request('post', $url, $params, $options);
$this->refreshFrom($response, $opts);
return $this;
}

/**
* @param array|null $params
* @param array|string|null $options
*
* @return Register the SIM cards associated with the provided registration codes to the current user's account.
*/
public static function register($params = null, $options = null)
{
self::_validateParams($params);
$url = '/v2/register/sim_cards';

list($response, $opts) = static::_staticRequest('post', $url, $params, null);
$obj = \Telnyx\Util\Util::convertToTelnyxObject($response->json, $opts);
$obj->setLastResponse($response);
return $obj;
}

}
2 changes: 2 additions & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public static function convertToTelnyxObject($resp, $opts)
\Telnyx\Address::OBJECT_NAME => 'Telnyx\\Address',
\Telnyx\BillingGroup::OBJECT_NAME => 'Telnyx\\BillingGroup',
\Telnyx\InboundChannel::OBJECT_NAME => 'Telnyx\\InboundChannel',
\Telnyx\SimCard::OBJECT_NAME => 'Telnyx\\SimCard',
\Telnyx\Portout::OBJECT_NAME => 'Telnyx\\Portout',

// Telnyx API: Connections
\Telnyx\Connection::OBJECT_NAME => 'Telnyx\\Connection',
Expand Down
66 changes: 66 additions & 0 deletions tests/api_resources/PortoutTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Telnyx;

class PortoutTest extends TestCase
{
const TEST_RESOURCE_ID = '123';


public function testIsListable()
{
$this->expectsRequest(
'get',
'/v2/portouts'
);
$resources = Portout::all();
$this->assertInstanceOf(\Telnyx\Collection::class, $resources);
$this->assertInstanceOf(\Telnyx\Portout::class, $resources[0]);
}

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v2/portouts/' . urlencode(self::TEST_RESOURCE_ID)
);
$resource = Portout::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf(\Telnyx\Portout::class, $resource);
}

public function testUpdateStatus()
{
$portout_status = 'authorized';
$portout = Portout::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'patch',
'/v2/portouts/' . urlencode(self::TEST_RESOURCE_ID) . '/' . $portout_status
);
$resources = $portout->update_status($portout_status);
$this->assertInstanceOf(\Telnyx\Portout::class, $resources);
}

public function testListComments()
{
$portout = Portout::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'get',
'/v2/portouts/' . urlencode(self::TEST_RESOURCE_ID) . '/comments'
);
$resources = $portout->list_comments();
$this->assertInstanceOf(\Telnyx\Collection::class, $resources);
$this->assertInstanceOf(\Telnyx\Portout::class, $resources[0]);
}

public function testCreateComments()
{
$portout = Portout::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v2/portouts/' . urlencode(self::TEST_RESOURCE_ID) . '/comments'
);
$resources = $portout->list_comments();
$this->assertInstanceOf(\Telnyx\Portout::class, $resources);
}

}
75 changes: 75 additions & 0 deletions tests/api_resources/SimCardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Telnyx;

class SimCardTest extends TestCase
{

const TEST_RESOURCE_ID = '6a09cdc3-8948-47f0-aa62-74ac943d6c58';

public function testIsListable()
{
$this->expectsRequest(
'get',
'/v2/sim_cards'
);
$resources = SimCard::all();
$this->assertInstanceOf(\Telnyx\Collection::class, $resources);
$this->assertInstanceOf(\Telnyx\SimCard::class, $resources[0]);
}

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v2/sim_cards/' . urlencode(self::TEST_RESOURCE_ID)
);
$resource = SimCard::retrieve(self::TEST_RESOURCE_ID);
$this->assertInstanceOf(\Telnyx\SimCard::class, $resource);
}

public function testIsUpdatable()
{
$this->expectsRequest(
'patch',
'/v2/sim_cards/' . urlencode(self::TEST_RESOURCE_ID)
);
$resource = SimCard::update(self::TEST_RESOURCE_ID, [
"name" => "Test",
]);
$this->assertInstanceOf(\Telnyx\SimCard::class, $resource);
}

public function testRequestActivation()
{
$simcard = SimCard::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v2/sim_cards/' . urlencode(self::TEST_RESOURCE_ID) . '/actions/activate'
);
$resources = $simcard->activate();
$this->assertInstanceOf(\Telnyx\SimCard::class, $resources);
}

public function testRequestDeactivation()
{
$simcard = SimCard::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'post',
'/v2/sim_cards/' . urlencode(self::TEST_RESOURCE_ID) . '/actions/deactivate'
);
$resources = $simcard->deactivate();
$this->assertInstanceOf(\Telnyx\SimCard::class, $resources);
}

public function testRegister()
{
$this->expectsRequest(
'post',
'/v2/actions/register/sim_cards'
);
$resources = SimCard::register(["registration_codes" => ["1234567890, 123456332601"]]);
$this->assertInstanceOf(\Telnyx\SimCard::class, $resources);
}

}