Apertur-SDK

 view release on metacpan or  search on metacpan

lib/Apertur/SDK/HTTPClient.pm  view on Meta::CPAN

    my $status = $res->code;

    if ($status >= 400) {
        $self->_handle_error($res);
    }

    if ($status == 204) {
        return undef;
    }

    return decode_json($res->decoded_content);
}

sub request_raw {
    my ($self, $method, $path, %opts) = @_;

    my $url = $self->{base_url} . $path;
    my $headers = $opts{headers} || {};

    $headers->{'Authorization'} = $self->{auth_header}
        if $self->{auth_header};

lib/Apertur/SDK/HTTPClient.pm  view on Meta::CPAN


    return $res->content;
}

sub _handle_error {
    my ($self, $res) = @_;
    my $status = $res->code;

    my $body = {};
    eval {
        $body = decode_json($res->decoded_content);
    };
    if ($@) {
        $body = { message => "HTTP $status" };
    }

    my $message = $body->{message} || "HTTP $status";
    my $code    = $body->{code};

    if ($status == 401) {
        Apertur::SDK::Error::Authentication->throw(message => $message);

lib/Apertur/SDK/HTTPClient.pm  view on Meta::CPAN

=head1 METHODS

=over 4

=item B<new(%args)>

Constructor. Accepts C<base_url>, C<api_key>, and C<oauth_token>.

=item B<request($method, $path, %opts)>

Sends a JSON API request and returns the decoded response as a hashref
or arrayref. Returns C<undef> for 204 No Content responses.

Options: C<body> (JSON string), C<headers> (hashref), C<multipart>
(arrayref for HTTP::Request::Common multipart POST), C<timeout> (per-request
override in seconds for the underlying LWP::UserAgent timeout).

=item B<request_raw($method, $path, %opts)>

Sends a request and returns the raw response body as a byte string.

lib/Apertur/SDK/Signature.pm  view on Meta::CPAN

the format C<sha256=E<lt>hexE<gt>>.

=item B<verify_event_signature($body, $timestamp, $signature, $secret)>

Verifies an event webhook using the HMAC method. The signed payload is
C<${timestamp}.${body}>.

=item B<verify_svix_signature($body, $svix_id, $timestamp, $signature, $secret)>

Verifies an event webhook using the Svix method. The signed payload is
C<${svix_id}.${timestamp}.${body}> and the secret is hex-decoded before
use. The signature is expected in the format C<v1,E<lt>base64E<gt>>.

=back

=cut



( run in 0.944 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )