Twilio
view release on metacpan or search on metacpan
lib/Twilio/Rest/IpMessaging/V1/Credential.pm view on Meta::CPAN
# Generated by tools/generate.pl from Twilio's OpenAPI specs. Do not edit this file.
package Twilio::Rest::IpMessaging::V1::Credential;
use 5.016;
use warnings;
our $VERSION = '2.002';
package Twilio::Rest::IpMessaging::V1::CredentialList;
use parent 'Twilio::ListResource';
use Twilio::Serialize;
sub new {
my ($class, $version) = @_;
my $self = $class->SUPER::new($version);
$self->{solution} = {};
$self->{uri} = '/Credentials';
return $self;
}
sub create {
my ($self, $type, $options) = @_;
$options //= {};
my $data = {
Type => $type,
ApiKey => $options->{api_key},
Certificate => $options->{certificate},
FriendlyName => $options->{friendly_name},
PrivateKey => $options->{private_key},
Sandbox => Twilio::Serialize::boolean_to_string($options->{sandbox}),
Secret => $options->{secret},
};
my $response =
$self->{version}->handle_request('POST', $self->{uri}, 'create', { data => $data });
return Twilio::Rest::IpMessaging::V1::CredentialInstance->new($self->{version},
$response->get_content);
}
sub read {
my ($self, @arguments) = @_;
return $self->read_records(@arguments);
}
sub stream {
my ($self, @arguments) = @_;
return $self->stream_records(@arguments);
}
sub page {
my ($self, $options, $page_size, $page_token, $page_number) = @_;
$options //= {};
my $params = {
PageToken => $page_token,
Page => $page_number,
PageSize => $page_size,
};
my $response = $self->{version}->page('GET', $self->{uri}, { params => $params });
return $self->_build_page($response);
}
sub get_page {
my ($self, $target_url) = @_;
my $client = $self->{version}->get_domain->get_client;
return $self->_build_page($client->request('GET', $target_url));
}
sub _build_page {
my ($self, $response) = @_;
return Twilio::Rest::IpMessaging::V1::CredentialPage->new($self->{version}, $response,
$self->{solution});
}
sub get_context {
my ($self, $sid) = @_;
return Twilio::Rest::IpMessaging::V1::CredentialContext->new($self->{version}, $sid);
}
package Twilio::Rest::IpMessaging::V1::CredentialPage;
use parent 'Twilio::Page';
sub records_key { return 'credentials' }
sub build_instance {
my ($self, $payload) = @_;
return Twilio::Rest::IpMessaging::V1::CredentialInstance->new($self->{version}, $payload);
}
package Twilio::Rest::IpMessaging::V1::CredentialContext;
use parent 'Twilio::InstanceContext';
use Twilio::Serialize;
sub new {
my ($class, $version, $sid) = @_;
my $self = $class->SUPER::new($version);
$self->{solution} = { sid => $sid };
$self->{uri} = join q{}, '/Credentials/', Twilio::Serialize::path_segment($sid);
return $self;
}
sub delete {
my ($self) = @_;
$self->{version}->handle_request('DELETE', $self->{uri}, 'delete');
return 1;
}
sub fetch {
my ($self) = @_;
my $response = $self->{version}->handle_request('GET', $self->{uri}, 'fetch');
return $self->_build_instance($response);
}
sub update {
my ($self, $options) = @_;
$options //= {};
my $data = {
ApiKey => $options->{api_key},
Certificate => $options->{certificate},
FriendlyName => $options->{friendly_name},
PrivateKey => $options->{private_key},
Sandbox => Twilio::Serialize::boolean_to_string($options->{sandbox}),
Secret => $options->{secret},
};
my $response =
$self->{version}->handle_request('POST', $self->{uri}, 'update', { data => $data });
return $self->_build_instance($response);
}
sub _build_instance {
my ($self, $response) = @_;
return Twilio::Rest::IpMessaging::V1::CredentialInstance->new($self->{version},
$response->get_content, $self->{solution}{sid});
}
package Twilio::Rest::IpMessaging::V1::CredentialInstance;
use parent 'Twilio::InstanceResource';
use Twilio::Deserialize;
sub new {
my ($class, $version, $payload, $sid) = @_;
my $self = $class->SUPER::new($version, $payload);
$self->{solution} = { sid => $sid // $self->{properties}{sid} };
return $self;
}
sub delete {
my ($self, @arguments) = @_;
return $self->_context->delete(@arguments);
}
sub fetch {
my ($self, @arguments) = @_;
return $self->_context->fetch(@arguments);
}
sub update {
my ($self, @arguments) = @_;
return $self->_context->update(@arguments);
}
sub _context {
my ($self) = @_;
return Twilio::Rest::IpMessaging::V1::CredentialContext->new($self->{version},
$self->{solution}{sid});
}
sub account_sid { return $_[0]{properties}{account_sid} }
sub date_created { return Twilio::Deserialize::date_time($_[0]{properties}{date_created}) }
sub date_updated { return Twilio::Deserialize::date_time($_[0]{properties}{date_updated}) }
sub friendly_name { return $_[0]{properties}{friendly_name} }
sub sandbox { return $_[0]{properties}{sandbox} }
sub sid { return $_[0]{properties}{sid} }
sub type { return $_[0]{properties}{type} }
sub url { return $_[0]{properties}{url} }
1;
lib/Twilio/Rest/IpMessaging/V1/Credential.pm view on Meta::CPAN
=head1 NAME
Twilio::Rest::IpMessaging::V1::Credential - The Credential resource
=head1 SYNOPSIS
my $client = Twilio::Rest::Client->new($account_sid, $auth_token);
my $credential = $client->ip_messaging->v1->credentials->create($type, \%options);
for my $credential ($client->ip_messaging->v1->credentials->read({}, 20)) {
...
}
my $credential = $client->ip_messaging->v1->credentials($sid)->fetch;
$client->ip_messaging->v1->credentials($sid)->update(\%options);
$client->ip_messaging->v1->credentials($sid)->delete;
=head1 DESCRIPTION
This file holds C<CredentialList>, C<CredentialPage>, C<CredentialContext> and
C<CredentialInstance>. Methods that make a request throw
L<Twilio::Exceptions::RestException> on an error response.
=head1 CredentialList
Returned by C<< $client->ip_messaging->v1->credentials >>. See also
L<Twilio::ListResource>.
=head2 create
my $credential = $client->ip_messaging->v1->credentials->create($type, \%options);
Returns a C<CredentialInstance>.
The required values are:
=over
=item C<$type>
One of C<gcm>, C<apn> or C<fcm>.
=back
The options are:
=over
=item C<api_key>
No description in the specification.
=item C<certificate>
No description in the specification.
=item C<friendly_name>
No description in the specification.
=item C<private_key>
No description in the specification.
=item C<sandbox>
No description in the specification.
=item C<secret>
No description in the specification.
=back
=head2 read
my @records = $client->ip_messaging->v1->credentials->read(\%options, $limit, $page_size);
Returns the records as a list, fetching as many pages as it needs.
=head2 stream
my $stream = $client->ip_messaging->v1->credentials->stream(\%options, $limit, $page_size);
Takes the same arguments as L</read>, and returns a L<Twilio::Stream>.
=head2 page
my $page = $client->ip_messaging->v1->credentials->page(\%options, $page_size, $page_token, $page_number);
Fetches one page, and returns a L<Twilio::Page>.
=head2 get_page
my $page = $client->ip_messaging->v1->credentials->get_page($url);
Fetches the page at a URL given by Twilio.
=head2 get_context
my $context = $client->ip_messaging->v1->credentials->get_context($sid);
Returns a C<CredentialContext>, and makes no request.
=head1 CredentialPage
A L<Twilio::Page> of C<CredentialInstance> objects.
=head2 records_key
=head2 build_instance
Used by L<Twilio::Page>.
=head1 CredentialContext
Returned by C<< $client->ip_messaging->v1->credentials($sid) >>. It makes no
request until one of these methods is called.
=head2 fetch
my $credential = $client->ip_messaging->v1->credentials($sid)->fetch;
Returns a C<CredentialInstance>.
=head2 update
my $credential = $client->ip_messaging->v1->credentials($sid)->update(\%options);
Returns a C<CredentialInstance>.
The options are:
=over
=item C<api_key>
No description in the specification.
=item C<certificate>
No description in the specification.
=item C<friendly_name>
No description in the specification.
=item C<private_key>
No description in the specification.
=item C<sandbox>
No description in the specification.
=item C<secret>
No description in the specification.
=back
=head2 delete
$client->ip_messaging->v1->credentials($sid)->delete;
Returns true.
=head1 CredentialInstance
See also L<Twilio::InstanceResource>.
It has C<fetch>, C<update> and C<delete>, which work as they do on the context.
Its fields are:
=over
=item account_sid
No description in the specification.
=item date_created
A L<Time::Piece> object in UTC. See L<Twilio::Deserialize/date_time>.
=item date_updated
A L<Time::Piece> object in UTC. See L<Twilio::Deserialize/date_time>.
=item friendly_name
No description in the specification.
=item sandbox
No description in the specification.
=item sid
No description in the specification.
=item type
One of C<gcm>, C<apn> or C<fcm>.
=item url
No description in the specification.
( run in 0.976 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )