| 1 | package WebService::Async::Onfido; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Webservice to connect to Onfido API | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use parent qw(IO::Async::Notifier); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | WebService::Async::Onfido - unofficial support for the Onfido identity verification service | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use mro; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | no indirect; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | ▶ | use Syntax::Keyword::Try; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 3 | ▶ | use Dir::Self; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use URI::QueryParam; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 3 | ▶ | use URI::Template; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 3 | ▶ | use Ryu::Async; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | ▶ | use Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 3 | ▶ | use Future::Utils qw(repeat); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 3 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 3 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 3 | ▶ | use Net::Async::HTTP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 3 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 3 | ▶ | use JSON::MaybeUTF8 qw(:v1); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 3 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 3 | ▶ | use File::ShareDir; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 3 | ▶ | use URI::Escape qw(uri_escape_utf8); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 3 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 3 | ▶ | use WebService::Async::Onfido::Applicant; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 3 | ▶ | use WebService::Async::Onfido::Address; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | use WebService::Async::Onfido::Document; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 3 | ▶ | use WebService::Async::Onfido::Photo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 48 | 3 | ▶ | use WebService::Async::Onfido::Video; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 49 | 3 | ▶ | use WebService::Async::Onfido::Check; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | 3 | ▶ | use WebService::Async::Onfido::Report; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | ▶ | use Log::Any qw($log); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 3 | ▶ | use constant SUPPORTED_COUNTRIES_URL => 'https://documentation.onfido.com/identityISOsupported.json'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Mapping file extension to mime type for currently | ||||||||||||||||||||||||||||
| 56 | # supported document types | ||||||||||||||||||||||||||||
| 57 | 3 | my %FILE_MIME_TYPE_MAPPING = ( | |||||||||||||||||||||||||||
| 58 | jpg => 'image/jpeg', | ||||||||||||||||||||||||||||
| 59 | jpeg => 'image/jpeg', | ||||||||||||||||||||||||||||
| 60 | png => 'image/png', | ||||||||||||||||||||||||||||
| 61 | pdf => 'application/pdf', | ||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | sub configure { | ||||||||||||||||||||||||||||
| 65 | 2 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
configure: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 2 | for my $k (qw(token requests_per_minute base_uri)) { | |||||||||||||||||||||||||||
| 67 | 6 | ▶ | $self->{$k} = delete $args{$k} if exists $args{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 2 | return $self->next::method(%args); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head2 applicant_list | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Retrieves a list of all known applicants. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Returns a L<Ryu::Source> which will emit one L<WebService::Async::Onfido::Applicant> for | ||||||||||||||||||||||||||||
| 77 | each applicant found. | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub applicant_list { | ||||||||||||||||||||||||||||
| 82 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
applicant_list: called CC=1 SCAR=0.3
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 1 | my $src = $self->source; | |||||||||||||||||||||||||||
| 84 | 1 | my $f = $src->completed; | |||||||||||||||||||||||||||
| 85 | 1 | my $uri = $self->endpoint('applicants'); | |||||||||||||||||||||||||||
| 86 | ( | ||||||||||||||||||||||||||||
| 87 | repeat { | ||||||||||||||||||||||||||||
| 88 | 1 | ▶ | $log->tracef('GET %s', "$uri"); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.5
| |||||||||||||||||||||||||||||
| 89 | $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 90 | sub { | ||||||||||||||||||||||||||||
| 91 | 1 | ▶ | $self->ua->GET($uri, $self->auth_headers,); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | )->then( | ||||||||||||||||||||||||||||
| 94 | sub { | ||||||||||||||||||||||||||||
| 95 | try { | ||||||||||||||||||||||||||||
| 96 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 97 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 98 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 99 | 1 | my ($total) = $res->header('X-Total-Count'); | |||||||||||||||||||||||||||
| 100 | 1 | $log->tracef('Expected total count %d', $total); | |||||||||||||||||||||||||||
| 101 | 1 | for (@{$data->{applicants}}) { | |||||||||||||||||||||||||||
| 102 | 1 | ▶ | return $f if $f->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 1 | $src->emit(WebService::Async::Onfido::Applicant->new(%$_, onfido => $self)); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 1 | $log->tracef('Links are %s', [$res->header('Link')]); | |||||||||||||||||||||||||||
| 106 | 1 | my %links = $self->extract_links($res->header('Link')); | |||||||||||||||||||||||||||
| 107 | 1 | ▶ | if (my $next = $links{next}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | ($uri) = $next; | |||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||
| 110 | 1 | $src->finish; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 1 | return Future->done; | |||||||||||||||||||||||||||
| 113 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=23.7
| |||||||||||||||||||||||||||||
| 114 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 115 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 116 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||
| 119 | sub { | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my ($err, @details) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 121 | 0 | $log->errorf('Failed to request document_list: %s', $err); | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | $src->fail($err, @details) unless $src->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | Future->fail($err, @details); | |||||||||||||||||||||||||||
| 124 | }) | ||||||||||||||||||||||||||||
| 125 | 1 | } | |||||||||||||||||||||||||||
| 126 | 1 | ▶ | until => sub { $f->is_ready })->retain; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 127 | 1 | return $src; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =head2 paging | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | Supports paging through HTTP GET requests. | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =over 4 | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =item * C<$starting_uri> - the initial L<URI> to request | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =item * C<$factory> - a C<sub> that we will call with a L<Ryu::Source> and expect to return | ||||||||||||||||||||||||||||
| 139 | a second response-processing C<sub>. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =back | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Returns a L<Ryu::Source>. | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | sub paging { | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my ($self, $starting_uri, $factory) = @_; | ||||||||||||||||||||||||||
|
Subroutine
paging: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $uri = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | ref($starting_uri) | ||||||||||||||||||||||||||||
| 151 | ? $starting_uri->clone | ||||||||||||||||||||||||||||
| 152 | : URI->new($starting_uri); | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | my $src = $self->source; | |||||||||||||||||||||||||||
| 155 | 0 | my $f = $src->completed; | |||||||||||||||||||||||||||
| 156 | 0 | my $code = $factory->($src); | |||||||||||||||||||||||||||
| 157 | ( | ||||||||||||||||||||||||||||
| 158 | repeat { | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | $log->tracef('GET %s', "$uri"); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 160 | $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 161 | sub { | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $self->ua->GET($uri, $self->auth_headers,); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | )->then( | ||||||||||||||||||||||||||||
| 165 | sub { | ||||||||||||||||||||||||||||
| 166 | try { | ||||||||||||||||||||||||||||
| 167 | 0 | my ($res) = @_; | |||||||||||||||||||||||||||
| 168 | 0 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 169 | 0 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 170 | 0 | my ($total) = $res->header('X-Total-Count'); | |||||||||||||||||||||||||||
| 171 | 0 | $log->tracef('Expected total count %d', $total); | |||||||||||||||||||||||||||
| 172 | 0 | $code->($data); | |||||||||||||||||||||||||||
| 173 | 0 | $log->tracef('Links are %s', [$res->header('Link')]); | |||||||||||||||||||||||||||
| 174 | 0 | my %links = $self->extract_links($res->header('Link')); | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if (my $next = $links{next}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | ($uri) = $next; | |||||||||||||||||||||||||||
| 178 | } else { | ||||||||||||||||||||||||||||
| 179 | 0 | $src->finish; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 0 | return Future->done; | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 183 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 184 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 185 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | }, | ||||||||||||||||||||||||||||
| 188 | sub { | ||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my ($err, @details) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 190 | 0 | $log->errorf('Failed to request %s: %s', $uri, $err); | |||||||||||||||||||||||||||
| 191 | 0 | ▶ | $src->fail($err, @details) unless $src->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | Future->fail($err, @details); | |||||||||||||||||||||||||||
| 193 | }) | ||||||||||||||||||||||||||||
| 194 | 0 | } | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | until => sub { $f->is_ready })->retain; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 196 | 0 | return $src; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head2 extract_links | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Given a set of strings representing the C<Link> headers in an HTTP response, | ||||||||||||||||||||||||||||
| 202 | extracts the URIs based on the C<rel> attribute as described in | ||||||||||||||||||||||||||||
| 203 | L<RFC5988|http://tools.ietf.org/html/rfc5988>. | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | Returns a list of key, value pairs where the key contains the lowercase C<rel> value | ||||||||||||||||||||||||||||
| 206 | and the value is a L<URI> instance. | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | my %links = $self->extract_links($res->header('Link')) | ||||||||||||||||||||||||||||
| 209 | print "Last page would be $links{last}" | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =cut | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | sub extract_links { | ||||||||||||||||||||||||||||
| 214 | 1 | ▶ | my ($self, @links) = @_; | ||||||||||||||||||||||||||
|
Subroutine
extract_links: called CC=3 SCAR=15.1
Pod
documented
| |||||||||||||||||||||||||||||
| 215 | 1 | my %links; | |||||||||||||||||||||||||||
| 216 | 1 | for (map { split /\h*,\h*/ } @links) { | |||||||||||||||||||||||||||
| 217 | # Format is like: | ||||||||||||||||||||||||||||
| 218 | # <https://api.eu.onfido.com/v3.4/applicants?page=2>; rel="next" | ||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if (my ($url, $rel) = m{<(http[^>]+)>;\h*rel="([^"]+)"}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | $links{lc $rel} = URI->new($url); | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | 1 | return %links; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =head2 applicant_create | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | Creates a new applicant record. | ||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | See accessors in L<WebService::Async::Onfido::Applicant> for a full list of supported attributes. | ||||||||||||||||||||||||||||
| 231 | These can be passed as named parameters to this method. | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | Returns a L<Future> which resolves to a L<WebService::Async::Onfido::Applicant> | ||||||||||||||||||||||||||||
| 234 | instance on successful completion. | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =cut | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | sub applicant_create { | ||||||||||||||||||||||||||||
| 239 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
applicant_create: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||
| 240 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 241 | sub { | ||||||||||||||||||||||||||||
| 242 | 1 | ▶ | $self->ua->POST( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 243 | $self->endpoint('applicants'), | ||||||||||||||||||||||||||||
| 244 | encode_json_utf8(\%args), | ||||||||||||||||||||||||||||
| 245 | content_type => 'application/json', | ||||||||||||||||||||||||||||
| 246 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 247 | ); | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | )->then( | ||||||||||||||||||||||||||||
| 250 | sub { | ||||||||||||||||||||||||||||
| 251 | try { | ||||||||||||||||||||||||||||
| 252 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 253 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 254 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 255 | 1 | return Future->done(WebService::Async::Onfido::Applicant->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 256 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 257 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 258 | 0 | $log->errorf('Applicant creation failed - %s', $err); | |||||||||||||||||||||||||||
| 259 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | 1 | }); | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | =head2 applicant_update | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | Updates a single applicant. | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | Returns a L<Future> which resolves to empty on success. | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | =cut | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | sub applicant_update { | ||||||||||||||||||||||||||||
| 273 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
applicant_update: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||
| 274 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 275 | sub { | ||||||||||||||||||||||||||||
| 276 | 1 | ▶ | $self->ua->PUT( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 277 | $self->endpoint('applicant', %args), | ||||||||||||||||||||||||||||
| 278 | encode_json_utf8(\%args), | ||||||||||||||||||||||||||||
| 279 | content_type => 'application/json', | ||||||||||||||||||||||||||||
| 280 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 281 | ); | ||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | )->then( | ||||||||||||||||||||||||||||
| 284 | sub { | ||||||||||||||||||||||||||||
| 285 | try { | ||||||||||||||||||||||||||||
| 286 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 287 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 288 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 289 | 1 | return Future->done(); | |||||||||||||||||||||||||||
| 290 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 291 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 292 | 0 | $log->errorf('Applicant update failed - %s', $err); | |||||||||||||||||||||||||||
| 293 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | 1 | }); | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | =head2 applicant_delete | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | Deletes a single applicant. | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | Returns a L<Future> which resolves to empty on success. | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | =cut | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | sub applicant_delete { | ||||||||||||||||||||||||||||
| 307 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
applicant_delete: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||
| 308 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 309 | sub { | ||||||||||||||||||||||||||||
| 310 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 311 | uri => $self->endpoint('applicant', %args), | ||||||||||||||||||||||||||||
| 312 | method => 'DELETE', | ||||||||||||||||||||||||||||
| 313 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 314 | ); | ||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | )->then( | ||||||||||||||||||||||||||||
| 317 | sub { | ||||||||||||||||||||||||||||
| 318 | try { | ||||||||||||||||||||||||||||
| 319 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 320 | 1 | ▶ | return Future->done if $res->code == 204; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 0 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 322 | 0 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 323 | 0 | return Future->fail($data); | |||||||||||||||||||||||||||
| 324 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=13.0
| |||||||||||||||||||||||||||||
| 325 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 326 | 0 | $log->errorf('Applicant delete failed - %s', $err); | |||||||||||||||||||||||||||
| 327 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | 1 | }); | |||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | =head2 applicant_get | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | Retrieve a single applicant. | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | Returns a L<Future> which resolves to a L<WebService::Async::Onfido::Applicant> | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | =cut | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | sub applicant_get { | ||||||||||||||||||||||||||||
| 341 | 2 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
applicant_get: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||
| 342 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 343 | sub { | ||||||||||||||||||||||||||||
| 344 | 2 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 345 | uri => $self->endpoint('applicant', %args), | ||||||||||||||||||||||||||||
| 346 | method => 'GET', | ||||||||||||||||||||||||||||
| 347 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 348 | ); | ||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | )->then( | ||||||||||||||||||||||||||||
| 351 | sub { | ||||||||||||||||||||||||||||
| 352 | try { | ||||||||||||||||||||||||||||
| 353 | 2 | my ($res) = @_; | |||||||||||||||||||||||||||
| 354 | 2 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 355 | 2 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 356 | 2 | return Future->done(WebService::Async::Onfido::Applicant->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 357 | 2 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 358 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 359 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 360 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | 2 | }); | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | sub check_get { | ||||||||||||||||||||||||||||
| 366 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
check_get: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 367 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 368 | sub { | ||||||||||||||||||||||||||||
| 369 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 370 | uri => $self->endpoint('check', %args), | ||||||||||||||||||||||||||||
| 371 | method => 'GET', | ||||||||||||||||||||||||||||
| 372 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 373 | ); | ||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||
| 375 | )->then( | ||||||||||||||||||||||||||||
| 376 | sub { | ||||||||||||||||||||||||||||
| 377 | try { | ||||||||||||||||||||||||||||
| 378 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 379 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 380 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 381 | 1 | return Future->done(WebService::Async::Onfido::Check->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 382 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 383 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 384 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 385 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | 1 | }); | |||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =head2 document_list | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | List all documents for a given L<WebService::Async::Onfido::Applicant>. | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | =over 4 | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | =item * C<applicant_id> - the L<WebService::Async::Onfido::Applicant/id> for the applicant to query | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | =back | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | Returns a L<Ryu::Source> which will emit one L<WebService::Async::Onfido::Document> for | ||||||||||||||||||||||||||||
| 403 | each document found. | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | =cut | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | sub document_list { | ||||||||||||||||||||||||||||
| 408 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
document_list: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||
| 409 | 1 | my $src = $self->source; | |||||||||||||||||||||||||||
| 410 | 1 | my $uri = $self->endpoint('documents'); | |||||||||||||||||||||||||||
| 411 | 1 | $uri->query('applicant_id=' . uri_escape_utf8($args{applicant_id})); | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 414 | sub { | ||||||||||||||||||||||||||||
| 415 | 1 | ▶ | $self->ua->GET($uri, $self->auth_headers,); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | )->then( | ||||||||||||||||||||||||||||
| 418 | sub { | ||||||||||||||||||||||||||||
| 419 | try { | ||||||||||||||||||||||||||||
| 420 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 421 | 1 | $log->tracef("GET %s => %s", $uri, $res->decoded_content); | |||||||||||||||||||||||||||
| 422 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 423 | 1 | my $f = $src->completed; | |||||||||||||||||||||||||||
| 424 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 425 | 1 | for (@{$data->{documents}}) { | |||||||||||||||||||||||||||
| 426 | 1 | ▶ | return $f if $f->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 1 | $src->emit(WebService::Async::Onfido::Document->new(%$_, onfido => $self)); | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | 1 | $src->finish; | |||||||||||||||||||||||||||
| 430 | 1 | return Future->done; | |||||||||||||||||||||||||||
| 431 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=26.4
| |||||||||||||||||||||||||||||
| 432 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 433 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 434 | 0 | ▶ | $src->fail('Failed to get document list.') unless $src->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 435 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | 1 | })->retain; | |||||||||||||||||||||||||||
| 438 | 1 | return $src; | |||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =head2 get_document_details | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | Gets a document object for a given L<WebService::Async::Onfido::Applicant>. | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||
| 447 | =over 4 | ||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||
| 449 | =item * C<applicant_id> - the L<WebService::Async::Onfido::Applicant/id> for the applicant to query | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | =item * C<document_id> - the L<WebService::Async::Onfido::Document/id> for the document to query | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | =back | ||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||
| 455 | Returns a Future object which consists of a L<WebService::Async::Onfido::Document> | ||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||
| 457 | =cut | ||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||
| 459 | sub get_document_details { | ||||||||||||||||||||||||||||
| 460 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_document_details: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||
| 461 | 1 | my $uri = $self->endpoint('document', %args); | |||||||||||||||||||||||||||
| 462 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 463 | sub { | ||||||||||||||||||||||||||||
| 464 | 1 | ▶ | $self->ua->GET($uri, $self->auth_headers,); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||
| 466 | )->then( | ||||||||||||||||||||||||||||
| 467 | sub { | ||||||||||||||||||||||||||||
| 468 | try { | ||||||||||||||||||||||||||||
| 469 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 470 | 1 | $log->tracef("GET %s => %s", $uri, $res->decoded_content); | |||||||||||||||||||||||||||
| 471 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 472 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 473 | 1 | return Future->done(WebService::Async::Onfido::Document->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 474 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 475 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 476 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 477 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | 1 | }); | |||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | =head2 photo_list | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | List all photos for a given L<WebService::Async::Onfido::Applicant>. | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | =over 4 | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | =item * C<applicant_id> - the L<WebService::Async::Onfido::Applicant/id> for the applicant to query | ||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | =back | ||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | Returns a L<Ryu::Source> which will emit one L<WebService::Async::Onfido::Photo> for | ||||||||||||||||||||||||||||
| 495 | each photo found. | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | =cut | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | sub photo_list { | ||||||||||||||||||||||||||||
| 500 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
photo_list: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||
| 501 | 1 | my $src = $self->source; | |||||||||||||||||||||||||||
| 502 | 1 | my $uri = $self->endpoint('photos', %args); | |||||||||||||||||||||||||||
| 503 | $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 504 | sub { | ||||||||||||||||||||||||||||
| 505 | 1 | ▶ | $self->ua->GET($uri, $self->auth_headers,); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | )->then( | ||||||||||||||||||||||||||||
| 508 | sub { | ||||||||||||||||||||||||||||
| 509 | try { | ||||||||||||||||||||||||||||
| 510 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 511 | 1 | $log->tracef("GET %s => %s", $uri, $res->decoded_content); | |||||||||||||||||||||||||||
| 512 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 513 | 1 | my $f = $src->completed; | |||||||||||||||||||||||||||
| 514 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 515 | 1 | for (@{$data->{live_photos}}) { | |||||||||||||||||||||||||||
| 516 | 1 | ▶ | return $f if $f->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 517 | 1 | $src->emit(WebService::Async::Onfido::Photo->new(%$_, onfido => $self)); | |||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||
| 519 | 1 | $src->finish; | |||||||||||||||||||||||||||
| 520 | 1 | return Future->done; | |||||||||||||||||||||||||||
| 521 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=26.4
| |||||||||||||||||||||||||||||
| 522 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 523 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 524 | 0 | ▶ | $src->fail('Failed to get photo list.') unless $src->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 525 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||
| 527 | 1 | })->retain; | |||||||||||||||||||||||||||
| 528 | 1 | return $src; | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | =head2 get_photo_details | ||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||
| 533 | Gets a live_photo object for a given L<WebService::Async::Onfido::Applicant>. | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | =over 4 | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | =item * C<live_photo_id> - the L<WebService::Async::Onfido::Photo/id> for the document to query | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | =back | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | Returns a Future object which consists of a L<WebService::Async::Onfido::Photo> | ||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | =cut | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | sub get_photo_details { | ||||||||||||||||||||||||||||
| 548 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_photo_details: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||
| 549 | 1 | my $uri = $self->endpoint('photo', %args); | |||||||||||||||||||||||||||
| 550 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 551 | sub { | ||||||||||||||||||||||||||||
| 552 | 1 | ▶ | $self->ua->GET($uri, $self->auth_headers,); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||
| 554 | )->then( | ||||||||||||||||||||||||||||
| 555 | sub { | ||||||||||||||||||||||||||||
| 556 | try { | ||||||||||||||||||||||||||||
| 557 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 558 | 1 | $log->tracef("GET %s => %s", $uri, $res->decoded_content); | |||||||||||||||||||||||||||
| 559 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 560 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 561 | 1 | return Future->done(WebService::Async::Onfido::Photo->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 562 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 563 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 564 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 565 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | 1 | }); | |||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | =head2 document_upload | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | Uploads a single document for a given applicant. | ||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||
| 576 | =over 4 | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | =item * C<type> - can be C<passport>, C<photo>, C<poa> | ||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||
| 580 | =item * C<side> - which side, either C<front> or C<back> | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | =item * C<issuing_country> - which country this document is for | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | =item * C<filename> - the file name to use for this item | ||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | =item * C<data> - the bytes for this image file (must be in JPEG format) | ||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||
| 588 | =back | ||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||
| 590 | =cut | ||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||
| 592 | sub document_upload { | ||||||||||||||||||||||||||||
| 593 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
document_upload: called CC=1 SCAR=0.4
Pod
documented
| |||||||||||||||||||||||||||||
| 594 | 1 | my $uri = $self->endpoint('documents'); | |||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | my $req = HTTP::Request::Common::POST( | ||||||||||||||||||||||||||||
| 597 | $uri, | ||||||||||||||||||||||||||||
| 598 | content_type => 'form-data', | ||||||||||||||||||||||||||||
| 599 | content => [ | ||||||||||||||||||||||||||||
| 600 | 4 | %args{grep { exists $args{$_} } qw(type side issuing_country applicant_id)}, | |||||||||||||||||||||||||||
| 601 | file => [ | ||||||||||||||||||||||||||||
| 602 | undef, $args{filename}, | ||||||||||||||||||||||||||||
| 603 | 'Content-Type' => _get_mime_type($args{filename}), | ||||||||||||||||||||||||||||
| 604 | Content => $args{data} | ||||||||||||||||||||||||||||
| 605 | ], | ||||||||||||||||||||||||||||
| 606 | ], | ||||||||||||||||||||||||||||
| 607 | 1 | %{$self->auth_headers}, | |||||||||||||||||||||||||||
| 608 | ); | ||||||||||||||||||||||||||||
| 609 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 610 | sub { | ||||||||||||||||||||||||||||
| 611 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 612 | request => $req, | ||||||||||||||||||||||||||||
| 613 | ); | ||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | )->catch( | ||||||||||||||||||||||||||||
| 616 | http => sub { | ||||||||||||||||||||||||||||
| 617 | 0 | ▶ | my ($message, undef, $response, $request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 618 | 0 | $log->errorf('Request %s received %s with full response as %s', $request->uri, $message, $response->content,); | |||||||||||||||||||||||||||
| 619 | # Just pass it on | ||||||||||||||||||||||||||||
| 620 | 0 | Future->fail( | |||||||||||||||||||||||||||
| 621 | $message, | ||||||||||||||||||||||||||||
| 622 | http => $response, | ||||||||||||||||||||||||||||
| 623 | $request | ||||||||||||||||||||||||||||
| 624 | ); | ||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||
| 626 | )->then( | ||||||||||||||||||||||||||||
| 627 | sub { | ||||||||||||||||||||||||||||
| 628 | try { | ||||||||||||||||||||||||||||
| 629 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 630 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 631 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 632 | 1 | return Future->done(WebService::Async::Onfido::Document->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 633 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 634 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 635 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 636 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||
| 638 | 1 | }); | |||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||
| 641 | =head2 live_photo_upload | ||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||
| 643 | Uploads a single "live photo" for a given applicant. | ||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | =over 4 | ||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | =item * C<applicant_id> - ID for the person this photo relates to | ||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||
| 651 | =item * C<advanced_validation> - perform additional validation (ensure we only have a single face) | ||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||
| 653 | =item * C<filename> - the file name to use for this item | ||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||
| 655 | =item * C<data> - the bytes for this image file (must be in JPEG format) | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | =back | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | =cut | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | sub live_photo_upload { | ||||||||||||||||||||||||||||
| 662 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
live_photo_upload: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 663 | 1 | my $uri = $self->endpoint('photo_upload'); | |||||||||||||||||||||||||||
| 664 | 1 | ▶ | $args{advanced_validation} = $args{advanced_validation} ? 'true' : 'false'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 665 | my $req = HTTP::Request::Common::POST( | ||||||||||||||||||||||||||||
| 666 | $uri, | ||||||||||||||||||||||||||||
| 667 | content_type => 'form-data', | ||||||||||||||||||||||||||||
| 668 | content => [ | ||||||||||||||||||||||||||||
| 669 | 2 | %args{grep { exists $args{$_} } qw(advanced_validation applicant_id)}, | |||||||||||||||||||||||||||
| 670 | file => [ | ||||||||||||||||||||||||||||
| 671 | undef, $args{filename}, | ||||||||||||||||||||||||||||
| 672 | 'Content-Type' => _get_mime_type($args{filename}), | ||||||||||||||||||||||||||||
| 673 | Content => $args{data} | ||||||||||||||||||||||||||||
| 674 | ], | ||||||||||||||||||||||||||||
| 675 | ], | ||||||||||||||||||||||||||||
| 676 | 1 | %{$self->auth_headers}, | |||||||||||||||||||||||||||
| 677 | ); | ||||||||||||||||||||||||||||
| 678 | 1 | $log->tracef('Photo upload: %s', $req->as_string("\n")); | |||||||||||||||||||||||||||
| 679 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 680 | sub { | ||||||||||||||||||||||||||||
| 681 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 682 | request => $req, | ||||||||||||||||||||||||||||
| 683 | ); | ||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||
| 685 | )->catch( | ||||||||||||||||||||||||||||
| 686 | http => sub { | ||||||||||||||||||||||||||||
| 687 | 0 | ▶ | my ($message, undef, $response, $request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 688 | 0 | $log->errorf('Request %s received %s with full response as %s', $request->uri, $message, $response->content,); | |||||||||||||||||||||||||||
| 689 | # Just pass it on | ||||||||||||||||||||||||||||
| 690 | 0 | Future->fail( | |||||||||||||||||||||||||||
| 691 | $message, | ||||||||||||||||||||||||||||
| 692 | http => $response, | ||||||||||||||||||||||||||||
| 693 | $request | ||||||||||||||||||||||||||||
| 694 | ); | ||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||
| 696 | )->then( | ||||||||||||||||||||||||||||
| 697 | sub { | ||||||||||||||||||||||||||||
| 698 | try { | ||||||||||||||||||||||||||||
| 699 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 700 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 701 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 702 | 1 | return Future->done(WebService::Async::Onfido::Photo->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 703 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 704 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 705 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 706 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||
| 708 | 1 | }); | |||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | =head2 applicant_check | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | Perform an identity check on an applicant. | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | This is the main method for dealing with verification - once you have created | ||||||||||||||||||||||||||||
| 716 | the applicant and uploaded some documents, call this to start the process of | ||||||||||||||||||||||||||||
| 717 | checking the documents and details, and generating the reports. | ||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | L<https://documentation.onfido.com/#check-object> | ||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||
| 723 | =over 4 | ||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||
| 725 | =item * C<applicant_id> - the applicant requesting the check | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | =item * C<document_ids> - arrayref of documents ids to be analyzed on this check | ||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | =item * C<report_names> - arrayref of the reports to be made (e.g: document, facial_similarity_photo) | ||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||
| 731 | =item * C<tags> - custom tags to apply to these reports | ||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||
| 733 | =item * C<suppress_form_emails> - if true, do B<not> send out the email to | ||||||||||||||||||||||||||||
| 734 | the applicant | ||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||
| 736 | =item * C<asynchronous> - return immediately and perform check in the background (default true since v3) | ||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||
| 738 | =item * C<charge_applicant_for_check> - the applicant must enter payment | ||||||||||||||||||||||||||||
| 739 | details for this check, and it will not count towards the quota for this | ||||||||||||||||||||||||||||
| 740 | service account | ||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||
| 742 | =item * C<consider> - used for sandbox API testing only | ||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||
| 744 | =back | ||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||
| 746 | Returns a L<Future> which will resolve with the result. | ||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||
| 748 | =cut | ||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||
| 750 | sub applicant_check { | ||||||||||||||||||||||||||||
| 751 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
applicant_check: called CC=1 SCAR=0.4
Pod
documented
| |||||||||||||||||||||||||||||
| 752 | 3 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 753 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 754 | sub { | ||||||||||||||||||||||||||||
| 755 | 1 | ▶ | $self->ua->POST( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 756 | $self->endpoint('checks'), | ||||||||||||||||||||||||||||
| 757 | encode_json_utf8(\%args), | ||||||||||||||||||||||||||||
| 758 | content_type => 'application/json', | ||||||||||||||||||||||||||||
| 759 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 760 | ); | ||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||
| 762 | )->catch( | ||||||||||||||||||||||||||||
| 763 | http => sub { | ||||||||||||||||||||||||||||
| 764 | 0 | ▶ | my ($message, undef, $response, $request) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||
| 766 | 0 | $log->errorf('Request %s received %s with full response as %s', $request->uri, $message, $response->content,); | |||||||||||||||||||||||||||
| 767 | # Just pass it on | ||||||||||||||||||||||||||||
| 768 | 0 | Future->fail( | |||||||||||||||||||||||||||
| 769 | $message, | ||||||||||||||||||||||||||||
| 770 | http => $response, | ||||||||||||||||||||||||||||
| 771 | $request | ||||||||||||||||||||||||||||
| 772 | ); | ||||||||||||||||||||||||||||
| 773 | } | ||||||||||||||||||||||||||||
| 774 | )->then( | ||||||||||||||||||||||||||||
| 775 | sub { | ||||||||||||||||||||||||||||
| 776 | try { | ||||||||||||||||||||||||||||
| 777 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 778 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 779 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 780 | 1 | return Future->done(WebService::Async::Onfido::Check->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 781 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 782 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 783 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 784 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||
| 786 | 1 | }); | |||||||||||||||||||||||||||
| 787 | } | ||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||
| 789 | sub check_list { | ||||||||||||||||||||||||||||
| 790 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
check_list: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 791 | 1 | ▶ | my $applicant_id = delete $args{applicant_id} or die 'Need an applicant ID'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 792 | 1 | my $src = $self->source; | |||||||||||||||||||||||||||
| 793 | 1 | my $f = $src->completed; | |||||||||||||||||||||||||||
| 794 | 1 | my $uri = $self->endpoint('checks'); | |||||||||||||||||||||||||||
| 795 | 1 | $uri->query('applicant_id=' . uri_escape_utf8($applicant_id)); | |||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||
| 797 | 1 | $log->tracef('GET %s', "$uri"); | |||||||||||||||||||||||||||
| 798 | $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 799 | sub { | ||||||||||||||||||||||||||||
| 800 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 801 | uri => $uri, | ||||||||||||||||||||||||||||
| 802 | method => 'GET', | ||||||||||||||||||||||||||||
| 803 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 804 | ); | ||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||
| 806 | )->then( | ||||||||||||||||||||||||||||
| 807 | sub { | ||||||||||||||||||||||||||||
| 808 | try { | ||||||||||||||||||||||||||||
| 809 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 810 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 811 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 812 | 1 | my ($total) = $res->header('X-Total-Count'); | |||||||||||||||||||||||||||
| 813 | 1 | $log->tracef('Expected total count %d', $total); | |||||||||||||||||||||||||||
| 814 | 1 | for (@{$data->{checks}}) { | |||||||||||||||||||||||||||
| 815 | 1 | ▶ | return $f if $f->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 816 | 1 | $src->emit(WebService::Async::Onfido::Check->new(%$_, onfido => $self)); | |||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||
| 818 | 1 | $src->finish; | |||||||||||||||||||||||||||
| 819 | 1 | Future->done; | |||||||||||||||||||||||||||
| 820 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=19.2
| |||||||||||||||||||||||||||||
| 821 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 822 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 823 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 824 | } | ||||||||||||||||||||||||||||
| 825 | 1 | })->retain; | |||||||||||||||||||||||||||
| 826 | 1 | return $src; | |||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||
| 829 | sub report_get { | ||||||||||||||||||||||||||||
| 830 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
report_get: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 831 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 832 | sub { | ||||||||||||||||||||||||||||
| 833 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 834 | uri => $self->endpoint('report', %args), | ||||||||||||||||||||||||||||
| 835 | method => 'GET', | ||||||||||||||||||||||||||||
| 836 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 837 | ); | ||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||
| 839 | )->then( | ||||||||||||||||||||||||||||
| 840 | sub { | ||||||||||||||||||||||||||||
| 841 | try { | ||||||||||||||||||||||||||||
| 842 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 843 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 844 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 845 | 1 | return Future->done(WebService::Async::Onfido::Report->new(%$data, onfido => $self)); | |||||||||||||||||||||||||||
| 846 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 847 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 848 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 849 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||
| 851 | 1 | }); | |||||||||||||||||||||||||||
| 852 | } | ||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||
| 854 | sub report_list { | ||||||||||||||||||||||||||||
| 855 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
report_list: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||
| 857 | 1 | ▶ | my $check_id = delete $args{check_id} or die 'Need a check ID'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||
| 859 | 1 | my $src = $self->source; | |||||||||||||||||||||||||||
| 860 | 1 | my $f = $src->completed; | |||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||
| 862 | 1 | my $uri = $self->endpoint('reports', check_id => $check_id); | |||||||||||||||||||||||||||
| 863 | 1 | $uri->query('check_id=' . uri_escape_utf8($check_id)); | |||||||||||||||||||||||||||
| 864 | 1 | $log->tracef('GET %s', "$uri"); | |||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||
| 866 | $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 867 | sub { | ||||||||||||||||||||||||||||
| 868 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 869 | uri => $uri, | ||||||||||||||||||||||||||||
| 870 | method => 'GET', | ||||||||||||||||||||||||||||
| 871 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 872 | ); | ||||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||
| 874 | )->then( | ||||||||||||||||||||||||||||
| 875 | sub { | ||||||||||||||||||||||||||||
| 876 | try { | ||||||||||||||||||||||||||||
| 877 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||
| 879 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 880 | 1 | for (@{$data->{reports}}) { | |||||||||||||||||||||||||||
| 881 | 2 | ▶ | return $f if $f->is_ready; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 882 | 2 | $src->emit(WebService::Async::Onfido::Report->new(%$_, onfido => $self)); | |||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||
| 884 | 1 | $src->finish; | |||||||||||||||||||||||||||
| 885 | 1 | Future->done; | |||||||||||||||||||||||||||
| 886 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=19.2
| |||||||||||||||||||||||||||||
| 887 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 888 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 889 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||
| 891 | 1 | })->retain; | |||||||||||||||||||||||||||
| 892 | 1 | return $src; | |||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||
| 895 | =head2 download_photo | ||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||
| 897 | Gets a live_photo in a form of binary data for a given L<WebService::Async::Onfido::Photo>. | ||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||
| 899 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||
| 901 | =over 4 | ||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||
| 903 | =item * C<live_photo_id> - the L<WebService::Async::Onfido::Photo/id> for the document to query | ||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||
| 905 | =back | ||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||
| 907 | Returns a photo file blob | ||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||
| 909 | =cut | ||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||
| 911 | sub download_photo { | ||||||||||||||||||||||||||||
| 912 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
download_photo: called CC=1 SCAR=0.3
Pod
documented
| |||||||||||||||||||||||||||||
| 913 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 914 | sub { | ||||||||||||||||||||||||||||
| 915 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 916 | uri => $self->endpoint('photo_download', %args), | ||||||||||||||||||||||||||||
| 917 | method => 'GET', | ||||||||||||||||||||||||||||
| 918 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 919 | ); | ||||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||
| 921 | )->then( | ||||||||||||||||||||||||||||
| 922 | sub { | ||||||||||||||||||||||||||||
| 923 | try { | ||||||||||||||||||||||||||||
| 924 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 925 | 1 | my $data = $res->content; | |||||||||||||||||||||||||||
| 926 | 1 | return Future->done($data); | |||||||||||||||||||||||||||
| 927 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 928 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 929 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 930 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 931 | } | ||||||||||||||||||||||||||||
| 932 | 1 | }); | |||||||||||||||||||||||||||
| 933 | } | ||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||
| 935 | =head2 download_document | ||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | Gets a document in a form of binary data for a given L<WebService::Async::Onfido::Document>. | ||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||
| 939 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||
| 941 | =over 4 | ||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||
| 943 | =item * C<applicant_id> - the L<WebService::Async::Onfido::Applicant/id> for the applicant to query | ||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||
| 945 | =item * C<document_id> - the L<WebService::Async::Onfido::Document/id> for the document to query | ||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||
| 947 | =back | ||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||
| 949 | Returns a document file blob | ||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||
| 951 | =cut | ||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||
| 953 | sub download_document { | ||||||||||||||||||||||||||||
| 954 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
download_document: called CC=1 SCAR=0.3
Pod
documented
| |||||||||||||||||||||||||||||
| 955 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 956 | sub { | ||||||||||||||||||||||||||||
| 957 | 1 | ▶ | $self->ua->do_request( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 958 | uri => $self->endpoint('document_download', %args), | ||||||||||||||||||||||||||||
| 959 | method => 'GET', | ||||||||||||||||||||||||||||
| 960 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 961 | ); | ||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||
| 963 | )->then( | ||||||||||||||||||||||||||||
| 964 | sub { | ||||||||||||||||||||||||||||
| 965 | try { | ||||||||||||||||||||||||||||
| 966 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 967 | 1 | my $data = $res->content; | |||||||||||||||||||||||||||
| 968 | 1 | return Future->done($data); | |||||||||||||||||||||||||||
| 969 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 970 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 971 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 972 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||
| 974 | 1 | }); | |||||||||||||||||||||||||||
| 975 | } | ||||||||||||||||||||||||||||
| 976 | |||||||||||||||||||||||||||||
| 977 | =head2 countries_list | ||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||
| 979 | Returns a hashref containing 3-letter country codes as keys and supporting status | ||||||||||||||||||||||||||||
| 980 | as their value. | ||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||
| 982 | =cut | ||||||||||||||||||||||||||||
| 983 | |||||||||||||||||||||||||||||
| 984 | sub countries_list { | ||||||||||||||||||||||||||||
| 985 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
countries_list: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||
| 987 | return $self->ua->GET(SUPPORTED_COUNTRIES_URL)->then( | ||||||||||||||||||||||||||||
| 988 | sub { | ||||||||||||||||||||||||||||
| 989 | try { | ||||||||||||||||||||||||||||
| 990 | 0 | my ($res) = @_; | |||||||||||||||||||||||||||
| 991 | 0 | my $onfido_countries = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||
| 993 | 0 | my %countries_list = map { $_->{alpha3} => $_->{supported_identity_report} + 0 } @$onfido_countries; | |||||||||||||||||||||||||||
| 994 | 0 | return Future->done(\%countries_list); | |||||||||||||||||||||||||||
| 995 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 996 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 997 | 0 | $log->errorf('Failed - %s', $err); | |||||||||||||||||||||||||||
| 998 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 999 | } | ||||||||||||||||||||||||||||
| 1000 | 0 | }); | |||||||||||||||||||||||||||
| 1001 | } | ||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||
| 1003 | =head2 supported_documents_list | ||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||
| 1005 | Returns an array of hashes of supported_documents for each country | ||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||
| 1007 | =cut | ||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||
| 1009 | sub supported_documents_list { | ||||||||||||||||||||||||||||
| 1010 | 2 | ▶ | my $path = Path::Tiny::path(__DIR__)->parent(3)->child('share/supported_documents.json'); | ||||||||||||||||||||||||||
|
Subroutine
supported_documents_list: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1011 | 2 | ▶ | $path = Path::Tiny::path(File::ShareDir::dist_file('WebService-Async-Onfido', 'supported_documents.json')) unless $path->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1012 | 2 | my $supported_documents = decode_json_text($path->slurp_utf8); | |||||||||||||||||||||||||||
| 1013 | 2 | return $supported_documents; | |||||||||||||||||||||||||||
| 1014 | } | ||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||
| 1016 | =head2 supported_documents_for_country | ||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||
| 1018 | Returns the supported_documents_list for the country | ||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||
| 1020 | =cut | ||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||
| 1022 | sub supported_documents_for_country { | ||||||||||||||||||||||||||||
| 1023 | 0 | ▶ | my ($self, $country_code) = @_; | ||||||||||||||||||||||||||
|
Subroutine
supported_documents_for_country: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||
| 1025 | 0 | my %country_details = map { $_->{country_code} => $_ } @{supported_documents_list()}; | |||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||
| 1027 | 0 | ▶ | return $country_details{$country_code}->{doc_types_list} // []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$country_details{$country_code}{"doc_types_list"} // []
MC/DC0%0/1
$country_details{$country_code}{"doc_types_list"} // []
$country_details{$country_code}{"doc_types_list"}
Truth table0%0/2
A
A= $country_details{$country_code}{"doc_types_list"}
| |||||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||
| 1030 | =head2 is_country_supported | ||||||||||||||||||||||||||||
| 1031 | |||||||||||||||||||||||||||||
| 1032 | Returns 1 if country supported and 0 for unsupported | ||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||
| 1034 | =cut | ||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||
| 1036 | sub is_country_supported { | ||||||||||||||||||||||||||||
| 1037 | 0 | ▶ | my ($self, $country_code) = @_; | ||||||||||||||||||||||||||
|
Subroutine
is_country_supported: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||
| 1039 | 0 | my %country_details = map { $_->{country_code} => $_ } @{supported_documents_list()}; | |||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||
| 1041 | 0 | ▶ | return $country_details{$country_code} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1042 | } | ||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||
| 1044 | =head2 sdk_token | ||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||
| 1046 | Returns the generated Onfido Web SDK token for the applicant. | ||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||
| 1048 | L<https://documentation.onfido.com/#web-sdk-tokens> | ||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||
| 1050 | Takes the following named parameters: | ||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||
| 1052 | =over 4 | ||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||
| 1054 | =item * C<applicant_id> - ID of the applicant to request the token for | ||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||
| 1056 | =item * C<referrer> - the URL of the web page where the Web SDK will be used | ||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||
| 1058 | =back | ||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||
| 1060 | =cut | ||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||
| 1062 | sub sdk_token { | ||||||||||||||||||||||||||||
| 1063 | 1 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sdk_token: called CC=1 SCAR=0.2
Pod
documented
| |||||||||||||||||||||||||||||
| 1064 | return $self->rate_limiting->then( | ||||||||||||||||||||||||||||
| 1065 | sub { | ||||||||||||||||||||||||||||
| 1066 | 1 | ▶ | $self->ua->POST( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 1067 | $self->endpoint('sdk_token'), | ||||||||||||||||||||||||||||
| 1068 | encode_json_utf8(\%args), | ||||||||||||||||||||||||||||
| 1069 | content_type => 'application/json', | ||||||||||||||||||||||||||||
| 1070 | $self->auth_headers, | ||||||||||||||||||||||||||||
| 1071 | ); | ||||||||||||||||||||||||||||
| 1072 | } | ||||||||||||||||||||||||||||
| 1073 | )->then( | ||||||||||||||||||||||||||||
| 1074 | sub { | ||||||||||||||||||||||||||||
| 1075 | try { | ||||||||||||||||||||||||||||
| 1076 | 1 | my ($res) = @_; | |||||||||||||||||||||||||||
| 1077 | 1 | my $data = decode_json_utf8($res->content); | |||||||||||||||||||||||||||
| 1078 | 1 | $log->tracef('Have response %s', $data); | |||||||||||||||||||||||||||
| 1079 | 1 | return Future->done($data); | |||||||||||||||||||||||||||
| 1080 | 1 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 1081 | 0 | my ($err) = $@; | |||||||||||||||||||||||||||
| 1082 | 0 | $log->errorf('Token generation failed - %s', $err); | |||||||||||||||||||||||||||
| 1083 | 0 | return Future->fail($err); | |||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||
| 1085 | 1 | }); | |||||||||||||||||||||||||||
| 1086 | } | ||||||||||||||||||||||||||||
| 1087 | |||||||||||||||||||||||||||||
| 1088 | =head2 endpoints | ||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||
| 1090 | Returns an accessor for the endpoints data. This is a hashref containing URI | ||||||||||||||||||||||||||||
| 1091 | templates, used by L</endpoint>. | ||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||
| 1093 | =cut | ||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||
| 1095 | sub endpoints { | ||||||||||||||||||||||||||||
| 1096 | 22 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
endpoints: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1097 | 22 | ▶ | return $self->{endpoints} ||= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"endpoints"} ||= do {
MC/DC0%0/2
$self->{"endpoints"} ||= do {
my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json");
$path = Path::Tiny::path(File::ShareDir::dist_file("WebService-Async-Onfido", "endpoints.json")) unless $path->exists;
my $endpoints = decode_json_text($path->slurp_utf8);
my $base_uri = $self->base_uri;
$_ = $base_uri . $_ foreach (values %$endpoints);
$endpoints
}
$self->{"endpoints"}
do {
my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json");
$path = Path::Tiny::path(File::ShareDir::dist_file("WebService-Async-Onfido", "endpoints.json")) unless $path->exists;
my $endpoints = decode_json_text($path->slurp_utf8);
my $base_uri = $self->base_uri;
$_ = $base_uri . $_ foreach (values %$endpoints);
$endpoints
}
Truth table66%2/3
A ||= B
A= $self->{"endpoints"}B= do {
my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json");
$path = Path::Tiny::path(File::ShareDir::dist_file("WebService-Async-Onfido", "endpoints.json")) unless $path->exists;
my $endpoints = decode_json_text($path->slurp_utf8);
my $base_uri = $self->base_uri;
$_ = $base_uri . $_ foreach (values %$endpoints);
$endpoints
}
| |||||||||||||||||||||||||||||
| 1098 | 1 | my $path = Path::Tiny::path(__DIR__)->parent(3)->child('share/endpoints.json'); | |||||||||||||||||||||||||||
| 1099 | 1 | ▶ | $path = Path::Tiny::path(File::ShareDir::dist_file('WebService-Async-Onfido', 'endpoints.json')) unless $path->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1100 | 1 | my $endpoints = decode_json_text($path->slurp_utf8); | |||||||||||||||||||||||||||
| 1101 | 1 | my $base_uri = $self->base_uri; | |||||||||||||||||||||||||||
| 1102 | 1 | $_ = $base_uri . $_ for values %$endpoints; | |||||||||||||||||||||||||||
| 1103 | 1 | $endpoints; | |||||||||||||||||||||||||||
| 1104 | }; | ||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||
| 1106 | |||||||||||||||||||||||||||||
| 1107 | =head2 endpoint | ||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||
| 1109 | Expands the selected URI via L<URI::Template>. Each item is defined in our C<endpoints.json> | ||||||||||||||||||||||||||||
| 1110 | file. | ||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||
| 1112 | Returns a L<URI> instance. | ||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||
| 1114 | =cut | ||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||
| 1116 | sub endpoint { | ||||||||||||||||||||||||||||
| 1117 | 22 | ▶ | my ($self, $endpoint, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
endpoint: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1118 | 22 | return URI::Template->new($self->endpoints->{$endpoint})->process(%args); | |||||||||||||||||||||||||||
| 1119 | } | ||||||||||||||||||||||||||||
| 1120 | |||||||||||||||||||||||||||||
| 1121 | sub base_uri { | ||||||||||||||||||||||||||||
| 1122 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
base_uri: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1123 | 1 | ▶ | return $self->{base_uri} if blessed($self->{base_uri}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 1124 | 1 | ▶ | $self->{base_uri} = URI->new($self->{base_uri} // 'https://api.eu.onfido.com'); | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"base_uri"} // "https://api.eu.onfido.com"
MC/DC0%0/1
$self->{"base_uri"} // "https://api.eu.onfido.com"
$self->{"base_uri"}
Truth table50%1/2
A
A= $self->{"base_uri"}
| |||||||||||||||||||||||||||||
| 1125 | 1 | return $self->{base_uri}; | |||||||||||||||||||||||||||
| 1126 | } | ||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||
| 1128 | 20 | ▶ | sub token { return shift->{token} } | ||||||||||||||||||||||||||
|
Subroutine
token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||
| 1130 | sub ua { | ||||||||||||||||||||||||||||
| 1131 | 20 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
ua: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1132 | 20 | ▶ | return $self->{ua} //= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"ua"} //= do {
MC/DC0%0/2
$self->{"ua"} //= do {
$self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "decode_content", 1, "pipeline", 0, "stall_timeout", 60, "max_connections_per_host", 2, "user_agent", "Mozilla/4.0 (WebService::Async::Onfido; DERIV\@cpan.org; https://metacpan.org/pod/WebService::Async::Onfido)"));
$ua
}
$self->{"ua"}
do {
$self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "decode_content", 1, "pipeline", 0, "stall_timeout", 60, "max_connections_per_host", 2, "user_agent", "Mozilla/4.0 (WebService::Async::Onfido; DERIV\@cpan.org; https://metacpan.org/pod/WebService::Async::Onfido)"));
$ua
}
Truth table66%2/3
A //= B
A= $self->{"ua"}B= do {
$self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "decode_content", 1, "pipeline", 0, "stall_timeout", 60, "max_connections_per_host", 2, "user_agent", "Mozilla/4.0 (WebService::Async::Onfido; DERIV\@cpan.org; https://metacpan.org/pod/WebService::Async::Onfido)"));
$ua
}
| |||||||||||||||||||||||||||||
| 1133 | 1 | $self->add_child( | |||||||||||||||||||||||||||
| 1134 | my $ua = Net::Async::HTTP->new( | ||||||||||||||||||||||||||||
| 1135 | fail_on_error => 1, | ||||||||||||||||||||||||||||
| 1136 | decode_content => 1, | ||||||||||||||||||||||||||||
| 1137 | pipeline => 0, | ||||||||||||||||||||||||||||
| 1138 | stall_timeout => 60, | ||||||||||||||||||||||||||||
| 1139 | max_connections_per_host => 2, | ||||||||||||||||||||||||||||
| 1140 | user_agent => 'Mozilla/4.0 (WebService::Async::Onfido; DERIV@cpan.org; https://metacpan.org/pod/WebService::Async::Onfido)', | ||||||||||||||||||||||||||||
| 1141 | )); | ||||||||||||||||||||||||||||
| 1142 | 1 | $ua; | |||||||||||||||||||||||||||
| 1143 | } | ||||||||||||||||||||||||||||
| 1144 | } | ||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||
| 1146 | sub auth_headers { | ||||||||||||||||||||||||||||
| 1147 | 20 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
auth_headers: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1148 | 20 | return headers => {'Authorization' => 'Token token=' . $self->token}; | |||||||||||||||||||||||||||
| 1149 | } | ||||||||||||||||||||||||||||
| 1150 | |||||||||||||||||||||||||||||
| 1151 | sub ryu { | ||||||||||||||||||||||||||||
| 1152 | 5 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
ryu: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1153 | 5 | ▶ | return $self->{ryu} //= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"ryu"} //= do {
MC/DC0%0/2
$self->{"ryu"} //= do {
$self->add_child(my $ryu = "Ryu::Async"->new);
$ryu
}
$self->{"ryu"}
do {
$self->add_child(my $ryu = "Ryu::Async"->new);
$ryu
}
Truth table66%2/3
A //= B
A= $self->{"ryu"}B= do {
$self->add_child(my $ryu = "Ryu::Async"->new);
$ryu
}
| |||||||||||||||||||||||||||||
| 1154 | 1 | $self->add_child(my $ryu = Ryu::Async->new); | |||||||||||||||||||||||||||
| 1155 | 1 | $ryu; | |||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||
| 1157 | } | ||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||
| 1159 | =head2 is_rate_limited | ||||||||||||||||||||||||||||
| 1160 | |||||||||||||||||||||||||||||
| 1161 | Returns true if we are currently rate limited, false otherwise. | ||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||
| 1163 | May eventually be updated to return number of seconds that you need to wait. | ||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||
| 1165 | =cut | ||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||
| 1167 | sub is_rate_limited { | ||||||||||||||||||||||||||||
| 1168 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
is_rate_limited: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 1169 | 0 | ▶ | return $self->{rate_limit} && $self->{request_count} >= $self->requests_per_minute; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'rate_limit'} && $self->{'request_count'} >= $self->requests_per_minute
MC/DC0%0/2
$self->{'rate_limit'} && $self->{'request_count'} >= $self->requests_per_minute
$self->{'rate_limit'}
$self->{'request_count'} >= $self->requests_per_minute
Truth table0%0/3
A && B
A= $self->{'rate_limit'}B= $self->{'request_count'} >= $self->requests_per_minute
| |||||||||||||||||||||||||||||
| 1170 | } | ||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||
| 1172 | =head2 rate_limiting | ||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||
| 1174 | Applies rate limiting check. | ||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||
| 1176 | Returns a L<Future> which will resolve once it's safe to send further requests. | ||||||||||||||||||||||||||||
| 1177 | |||||||||||||||||||||||||||||
| 1178 | =cut | ||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||
| 1180 | sub rate_limiting { | ||||||||||||||||||||||||||||
| 1181 | 20 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
rate_limiting: called CC=4 SCAR=17.3
Pod
documented
| |||||||||||||||||||||||||||||
| 1182 | 20 | ▶ | $self->{rate_limit} //= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"rate_limit"} //= do {
MC/DC0%0/2
$self->{"rate_limit"} //= do {
$self->loop->delay_future("after", 60)->on_ready(sub {
$self->{"request_count"} = 0;
delete $self->{"rate_limit"};
}
)
}
$self->{"rate_limit"}
do {
$self->loop->delay_future("after", 60)->on_ready(sub {
$self->{"request_count"} = 0;
delete $self->{"rate_limit"};
}
)
}
Truth table66%2/3
A //= B
A= $self->{"rate_limit"}B= do {
$self->loop->delay_future("after", 60)->on_ready(sub {
$self->{"request_count"} = 0;
delete $self->{"rate_limit"};
}
)
}
| |||||||||||||||||||||||||||||
| 1183 | $self->loop->delay_future(after => 60)->on_ready( | ||||||||||||||||||||||||||||
| 1184 | sub { | ||||||||||||||||||||||||||||
| 1185 | 0 | ▶ | $self->{request_count} = 0; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 1186 | 0 | delete $self->{rate_limit}; | |||||||||||||||||||||||||||
| 1187 | 1 | }); | |||||||||||||||||||||||||||
| 1188 | }; | ||||||||||||||||||||||||||||
| 1189 | 20 | ▶ | return Future->done unless $self->requests_per_minute and ++$self->{request_count} >= $self->requests_per_minute; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->requests_per_minute and ++$self->{"request_count"} >= $self->requests_per_minute
MC/DC0%0/2
$self->requests_per_minute and ++$self->{"request_count"} >= $self->requests_per_minute
$self->requests_per_minute
++$self->{"request_count"} >= $self->requests_per_minute
Truth table33%1/3
A and B
A= $self->requests_per_minuteB= ++$self->{"request_count"} >= $self->requests_per_minute
| |||||||||||||||||||||||||||||
| 1190 | 0 | return $self->{rate_limit}; | |||||||||||||||||||||||||||
| 1191 | } | ||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||
| 1193 | 40 | ▶ | sub requests_per_minute { return shift->{requests_per_minute} //= 300 } | ||||||||||||||||||||||||||
|
Subroutine
requests_per_minute: called CC=2 SCAR=6.9
Pod
undocumented
Condition100%2/2
+(shift())->{"requests_per_minute"} //= 300
MC/DC100%1/1
+(shift())->{"requests_per_minute"} //= 300
+(shift())->{"requests_per_minute"}
Truth table100%2/2
A
A= +(shift())->{"requests_per_minute"}
| |||||||||||||||||||||||||||||
| 1194 | |||||||||||||||||||||||||||||
| 1195 | sub source { | ||||||||||||||||||||||||||||
| 1196 | 5 | ▶ | my ($self) = shift; | ||||||||||||||||||||||||||
|
Subroutine
source: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 1197 | 5 | return $self->ryu->source(@_); | |||||||||||||||||||||||||||
| 1198 | } | ||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||
| 1200 | sub _get_mime_type { | ||||||||||||||||||||||||||||
| 1201 | 2 | ▶ | my $filename = shift; | ||||||||||||||||||||||||||
|
Subroutine
_get_mime_type: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||
| 1203 | 2 | my $ext = (fileparse($filename, "[^.]+"))[2]; | |||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||
| 1205 | 2 | ▶ | return $FILE_MIME_TYPE_MAPPING{lc($ext // '')} // 'application/octet-stream'; | ||||||||||||||||||||||||||
|
Condition50%2/4
$FILE_MIME_TYPE_MAPPING{lc($ext // "")} // "application/octet-stream"
$ext // ""
MC/DC0%0/1
$FILE_MIME_TYPE_MAPPING{lc($ext // "")} // "application/octet-stream"
$FILE_MIME_TYPE_MAPPING{lc($ext // "")}
MC/DC0%0/1
$ext // ""
$ext
Truth table50%1/2
A
A= $FILE_MIME_TYPE_MAPPING{lc($ext // "")}
Truth table50%1/2
A
A= $ext
| |||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||
| 1208 | 3 | 1; | |||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||
| 1210 | __END__ | ||||||||||||||||||||||||||||
| 1211 | |||||||||||||||||||||||||||||
| 1212 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||
| 1214 | deriv.com | ||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||
| 1216 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||
| 1218 | Copyright Deriv.com 2019. | ||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||
| 1220 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||
| 1222 | Licensed under the same terms as Perl5 itself. | ||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||