Skip to content
Closed
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
37 changes: 37 additions & 0 deletions example/test_new_error_response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
require(__DIR__.'/../src/Twilio/autoload.php');

use Twilio\Exceptions\RestExceptionV1;
use Twilio\Rest\Client;


function createServices(Client $client)
{
try {
$requestBody = $client->accounts->v1->service->create([
'name' => "friendlyName",
]);
print $requestBody->id . "\n";
} catch (RestExceptionV1 $e) {
print "Error ------------------------------------------------------------------------------------ " . $e->getCode() . "\n" . $e->getMessage() . "\n" . $e->getHttpStatusCode() . "\n" . $e->getParams() . "\n" . $e->getUserError() . "\n";
}
}

function readServices(Client $client)
{
$services = $client->accounts->v1->service->read([
'Type' => 'sip',
'pageSize' => 2,
]);
foreach ($services as $record) {
print $record->id . "\n";
}
}


$sid = getenv('TWILIO_ACCOUNT_SID');
$token = getenv('TWILIO_AUTH_TOKEN');
$client = new Client($sid, $token);

createServices($client);
//readServices($client);
12 changes: 12 additions & 0 deletions src/Twilio/Rest/Accounts/V1.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Twilio\Rest\Accounts\V1\MessagingGeopermissionsList;
use Twilio\Rest\Accounts\V1\SafelistList;
use Twilio\Rest\Accounts\V1\SecondaryAuthTokenList;
use Twilio\Rest\Accounts\V1\ServiceList;
use Twilio\Version;

/**
Expand All @@ -35,6 +36,7 @@
* @property MessagingGeopermissionsList $messagingGeopermissions
* @property SafelistList $safelist
* @property SecondaryAuthTokenList $secondaryAuthToken
* @property ServiceList $service
*/
class V1 extends Version
{
Expand All @@ -45,6 +47,8 @@ class V1 extends Version
protected $_messagingGeopermissions;
protected $_safelist;
protected $_secondaryAuthToken;
protected $_service;


/**
* Construct the V1 version of Accounts
Expand Down Expand Up @@ -113,6 +117,14 @@ protected function getSecondaryAuthToken(): SecondaryAuthTokenList
return $this->_secondaryAuthToken;
}

protected function getService(): ServiceList
{
if (!$this->_service) {
$this->_service = new ServiceList($this);
}
return $this->_service;
}

/**
* Magic getter to lazy load root resources
*
Expand Down
91 changes: 91 additions & 0 deletions src/Twilio/Rest/Accounts/V1/ServiceInstance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

/**
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - REQUEST BODY TEST
* This is the public Twilio REST API.
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/


namespace Twilio\Rest\Accounts\V1;

use Twilio\Exceptions\TwilioException;
use Twilio\ListResource;
use Twilio\InstanceResource;
use Twilio\Options;
use Twilio\Stream;
use Twilio\Values;
use Twilio\Version;
use Twilio\ApiV1Version;
use Twilio\InstanceContext;
use Twilio\Deserialize;
use Twilio\Serialize;
use Twilio\Base\PhoneNumberCapabilities;


/**
* @property string $id
* @property string $name
*/
class ServiceInstance extends InstanceResource
{
/**
* Initialize the ServiceInstance
*
* @param Version $version Version that contains the resource
* @param mixed[] $payload The response payload
*/
public function __construct(Version $version, array $payload)
{
$apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
parent::__construct($apiV1Version);

// Marshaled Properties
$this->properties = [
'id' => Values::array_get($payload, 'id'),
'name' => Values::array_get($payload, 'name'),
];

$this->solution = [];
}

/**
* Magic getter to access properties
*
* @param string $name Property to access
* @return mixed The requested property
* @throws TwilioException For unknown properties
*/
public function __get(string $name)
{
if (\array_key_exists($name, $this->properties)) {
return $this->properties[$name];
}

if (\property_exists($this, '_' . $name)) {
$method = 'get' . \ucfirst($name);
return $this->$method();
}

throw new TwilioException('Unknown property: ' . $name);
}

/**
* Provide a friendly representation
*
* @return string Machine friendly representation
*/
public function __toString(): string
{
return '[Twilio.Accounts.V1.ServiceInstance]';
}
}

191 changes: 191 additions & 0 deletions src/Twilio/Rest/Accounts/V1/ServiceList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php

/**
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - REQUEST BODY TEST
* This is the public Twilio REST API.
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/

namespace Twilio\Rest\Accounts\V1;

use Twilio\Exceptions\TwilioException;
use Twilio\ListResource;
use Twilio\InstanceResource;
use Twilio\Options;
use Twilio\Stream;
use Twilio\Values;
use Twilio\Version;
use Twilio\ApiV1Version;
use Twilio\InstanceContext;
use Twilio\Deserialize;
use Twilio\Serialize;
use Twilio\Base\PhoneNumberCapabilities;


class ServiceList extends ListResource
{
/**
* Construct the ServiceList
*
* @param Version $version Version that contains the resource
*/
public function __construct(
Version $version
) {
$apiV1Version = new ApiV1Version($version->getDomain(), $version->version);
parent::__construct($apiV1Version);

// Path Solution
$this->solution = [
];

$this->uri = '/Services';
}

/**
* Create the ServiceInstance
*
* @param array|Options $options Optional Arguments
* @return ServiceInstance Created ServiceInstance
* @throws TwilioException When an HTTP error occurs.
*/
public function create(array $options = []): ServiceInstance
{

$options = new Values($options);

$data = Values::of([
'name' =>
$options['name'],
]);

$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json' ]);
$payload = $this->version->create('POST', $this->uri, [], $data, $headers);

return new ServiceInstance(
$this->version,
$payload
);
}


/**
* Reads ServiceInstance records from the API as a list.
* Unlike stream(), this operation is eager and will load `limit` records into
* memory before returning.
*
* @param array|Options $options Optional Arguments
* @param int $limit Upper limit for the number of records to return. read()
* guarantees to never return more than limit. Default is no
* limit
* @param mixed $pageSize Number of records to fetch per request, when not set
* will use the default value of 50 records. If no
* page_size is defined but a limit is defined, read()
* will attempt to read the limit with the most
* efficient page size, i.e. min(limit, 1000)
* @return ServiceInstance[] Array of results
*/
public function read(array $options = [], ?int $limit = null, $pageSize = null): array
{
return \iterator_to_array($this->stream($options, $limit, $pageSize), false);
}

/**
* Streams ServiceInstance records from the API as a generator stream.
* This operation lazily loads records as efficiently as possible until the
* limit
* is reached.
* The results are returned as a generator, so this operation is memory
* efficient.
*
* @param array|Options $options Optional Arguments
* @param int $limit Upper limit for the number of records to return. stream()
* guarantees to never return more than limit. Default is no
* limit
* @param mixed $pageSize Number of records to fetch per request, when not set
* will use the default value of 50 records. If no
* page_size is defined but a limit is defined, stream()
* will attempt to read the limit with the most
* efficient page size, i.e. min(limit, 1000)
* @return Stream stream of results
*/
public function stream(array $options = [], ?int $limit = null, $pageSize = null): Stream
{
$pageSize = $options['pageSize'] ?? $pageSize;
$limits = $this->version->readLimits($limit, $pageSize);

$page = $this->page($options, $limits['pageSize']);

return $this->version->stream($page, $limits['limit'], $limits['pageLimit']);
}

/**
* Retrieve a single page of ServiceInstance records from the API.
* Request is executed immediately
*
* @param mixed $pageSize Number of records to return, defaults to 50
* @param string $pageToken PageToken provided by the API
* @param mixed $pageNumber Page Number, this value is simply for client state
* @return ServicePage Page of ServiceInstance
*/
public function page(
array $options = [],
$pageSize = Values::NONE,
string $pageToken = Values::NONE,
$pageNumber = Values::NONE
): ServicePage
{
$options = new Values($options);

$params = Values::of([
'pageSize' =>
$options['pageSize'],
'pageToken' =>
$options['pageToken'],
'Type' =>
$options['type'],

]);

$headers = Values::of(['Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json']);
$response = $this->version->page('GET', $this->uri, $params, [], $headers);

return new ServicePage($this->version, $response, $this->solution);
}

/**
* Retrieve a specific page of ServiceInstance records from the API.
* Request is executed immediately
*
* @param string $targetUrl API-generated URL for the requested results page
* @return ServicePage Page of ServiceInstance
*/
public function getPage(string $targetUrl): ServicePage
{
$response = $this->version->getDomain()->getClient()->request(
'GET',
$targetUrl
);

return new ServicePage($this->version, $response, $this->solution);
}


/**
* Provide a friendly representation
*
* @return string Machine friendly representation
*/
public function __toString(): string
{
return '[Twilio.Accounts.V1.ServiceList]';
}
}
Loading
Loading