Twilio

 view release on metacpan or  search on metacpan

lib/Twilio/Rest/Chat/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::Chat::V1::Credential;

use 5.016;
use warnings;

our $VERSION = '2.002';

package Twilio::Rest::Chat::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::Chat::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::Chat::V1::CredentialPage->new($self->{version}, $response,
    $self->{solution});
}

sub get_context {
  my ($self, $sid) = @_;
  return Twilio::Rest::Chat::V1::CredentialContext->new($self->{version}, $sid);
}

package Twilio::Rest::Chat::V1::CredentialPage;

use parent 'Twilio::Page';

sub records_key { return 'credentials' }

sub build_instance {
  my ($self, $payload) = @_;
  return Twilio::Rest::Chat::V1::CredentialInstance->new($self->{version}, $payload);
}

package Twilio::Rest::Chat::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::Chat::V1::CredentialInstance->new($self->{version}, $response->get_content,
    $self->{solution}{sid});
}

package Twilio::Rest::Chat::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::Chat::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;

__END__

lib/Twilio/Rest/Chat/V1/Credential.pm  view on Meta::CPAN

  my $client = Twilio::Rest::Client->new($account_sid, $auth_token);

  my $credential = $client->chat->v1->credentials->create($type, \%options);
  for my $credential ($client->chat->v1->credentials->read({}, 20)) {
    ...
  }
  my $credential = $client->chat->v1->credentials($sid)->fetch;
  $client->chat->v1->credentials($sid)->update(\%options);
  $client->chat->v1->credentials($sid)->delete;

=head1 DESCRIPTION

Credentials for push notifications channels

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->chat->v1->credentials >>. See also
L<Twilio::ListResource>.

=head2 create

  my $credential = $client->chat->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>

[GCM only] The API key for the project that was obtained from the Google
Developer console for your GCM Service application credential.

=item C<certificate>

[APN only] The URL encoded representation of the certificate. For example,
C<-----BEGIN CERTIFICATE-----
MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A==
-----END CERTIFICATE----->

=item C<friendly_name>

A descriptive string that you create to describe the new resource. It can be up
to 64 characters long.

=item C<private_key>

[APN only] The URL encoded representation of the private key. For example,
C<-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----END RSA
PRIVATE KEY----->

=item C<sandbox>

[APN only] Whether to send the credential to sandbox APNs. Can be C<true> to
send to sandbox APNs or C<false> to send to production.

=item C<secret>

[FCM only] The B<Server key> of your project from the Firebase console, found
under Settings / Cloud messaging.

=back

=head2 read

  my @records = $client->chat->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->chat->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->chat->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->chat->v1->credentials->get_page($url);

Fetches the page at a URL given by Twilio.

=head2 get_context

  my $context = $client->chat->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->chat->v1->credentials($sid) >>. It makes no request
until one of these methods is called.

=head2 fetch

  my $credential = $client->chat->v1->credentials($sid)->fetch;

Returns a C<CredentialInstance>.

=head2 update

  my $credential = $client->chat->v1->credentials($sid)->update(\%options);

Returns a C<CredentialInstance>.

The options are:

=over

=item C<api_key>

[GCM only] The API key for the project that was obtained from the Google
Developer console for your GCM Service application credential.

=item C<certificate>

[APN only] The URL encoded representation of the certificate. For example,
C<-----BEGIN CERTIFICATE-----
MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A==
-----END CERTIFICATE----->

=item C<friendly_name>

A descriptive string that you create to describe the resource. It can be up to
64 characters long.

=item C<private_key>

[APN only] The URL encoded representation of the private key. For example,
C<-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----END RSA
PRIVATE KEY----->

=item C<sandbox>

[APN only] Whether to send the credential to sandbox APNs. Can be C<true> to
send to sandbox APNs or C<false> to send to production.

=item C<secret>

[FCM only] The B<Server key> of your project from the Firebase console, found
under Settings / Cloud messaging.

=back

=head2 delete

  $client->chat->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

The SID of the L<Account|https://www.twilio.com/docs/api/rest/account> that
created the Credential resource.

=item date_created

The date and time in GMT when the resource was created specified in L<RFC
2822|http://www.ietf.org/rfc/rfc2822.txt> format. A L<Time::Piece> object in
UTC. See L<Twilio::Deserialize/date_time>.

=item date_updated

The date and time in GMT when the resource was last updated specified in L<RFC
2822|http://www.ietf.org/rfc/rfc2822.txt> format. A L<Time::Piece> object in
UTC. See L<Twilio::Deserialize/date_time>.

=item friendly_name

The string that you assigned to describe the resource.

=item sandbox

[APN only] Whether to send the credential to sandbox APNs. Can be C<true> to
send to sandbox APNs or C<false> to send to production.



( run in 0.562 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )