Skip to content

Commit

Permalink
Address + Inbound Channel (#26)
Browse files Browse the repository at this point in the history
* Update ApiRequestor.php

Fixed params for isset()

* Added OutboundVoiceProfile

Added OutboundVoiceProfile

* Create OutboundVoiceProfileTest.php

Create OutboundVoiceProfileTest.php

* Updated Tests

Updated Tests

* Add Address + Inbound Channels

Added Address.php
Added InboudnChannel.php
Added tests for both

* Update InboundChannelsTest.php

Updated InboundChannelsTest.php to use correct params
  • Loading branch information
weroh committed Mar 18, 2020
1 parent cb230b4 commit aafe0a4
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 2 deletions.
4 changes: 3 additions & 1 deletion init.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
require(dirname(__FILE__) . '/lib/ShortCode.php');
require(dirname(__FILE__) . '/lib/OutboundVoiceProfile.php');

// Telnyx API: Billing
// Telnyx API: Misc
require(dirname(__FILE__) . '/lib/Address.php');
require(dirname(__FILE__) . '/lib/BillingGroup.php');
require(dirname(__FILE__) . '/lib/InboundChannel.php');

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

namespace Telnyx;

/**
* Class Address
*
* @package Telnyx
*/
class Address extends ApiResource
{
const OBJECT_NAME = "address";

use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;

/**
* @return string The endpoint associated with this singleton class.
*/
public static function classUrl()
{
// Replace dots with slashes for namespaced resources, e.g. if the object's name is
// "foo.bar", then its URL will be "/v2/foo/bar".
// NOTE: This endpoint is special because object name is "address" and endpoint is "addresses"
return "/v2/addresses";
}
}
48 changes: 48 additions & 0 deletions lib/InboundChannel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Telnyx;

/**
* Class InboundChannel
*
* @package Telnyx
*/
class InboundChannel extends ApiResource
{
const OBJECT_NAME = "inbound_channels";
const OBJECT_URL = "/v2/phone_numbers/inbound_channels";

/**
* @param array|null $params
* @param array|string|null $options
*
* @return Returns the inbound channels for your account.
*/
public static function retrieve()
{
$url = self::OBJECT_URL;

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

/**
* @param array|null $params
* @param array|string|null $options
*
* @return Update the inbound channels for the account
*/
public static function update($params = null)
{
self::_validateParams($params);
$url = self::OBJECT_URL;

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

}
4 changes: 3 additions & 1 deletion lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ public static function convertToTelnyxObject($resp, $opts)
\Telnyx\ShortCode::OBJECT_NAME => 'Telnyx\\ShortCode',
\Telnyx\OutboundVoiceProfile::OBJECT_NAME => 'Telnyx\\OutboundVoiceProfile',

// Telnyx API: Billing
// Telnyx API: Misc
\Telnyx\Address::OBJECT_NAME => 'Telnyx\\Address',
\Telnyx\BillingGroup::OBJECT_NAME => 'Telnyx\\BillingGroup',
\Telnyx\InboundChannel::OBJECT_NAME => 'Telnyx\\InboundChannel',

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

namespace Telnyx;

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


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

public function testIsCreatable()
{
$this->expectsRequest(
'post',
'/v2/addresses'
);
$resource = Address::create(['administrative_area'=>'IL']);
$this->assertInstanceOf(\Telnyx\Address::class, $resource);
}

public function testIsDeletable()
{
$resource = Address::retrieve(self::TEST_RESOURCE_ID);
$this->expectsRequest(
'delete',
'/v2/addresses/' . urlencode(self::TEST_RESOURCE_ID)
);
$resource->delete();
$this->assertInstanceOf(\Telnyx\Address::class, $resource);
}

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

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

namespace Telnyx;

class InboundChannelTest extends TestCase
{

public function testIsRetrievable()
{
$this->expectsRequest(
'get',
'/v2/phone_numbers/inbound_channels'
);
$resource = InboundChannel::retrieve();
$this->assertInstanceOf(\Telnyx\InboundChannel::class, $resource);
}

public function testIsUpdatable()
{
$this->expectsRequest(
'patch',
'/v2/phone_numbers/inbound_channels'
);
$resource = InboundChannel::update([
"channels" => 10,
]);
$this->assertInstanceOf(\Telnyx\InboundChannel::class, $resource);
}

}

0 comments on commit aafe0a4

Please sign in to comment.