| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::ValidSign::API::Constructor; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $VERSION = '0.003'; | 
| 4 | 6 |  |  | 6 |  | 56016 | use Moo::Role; | 
|  | 6 |  |  |  |  | 19 |  | 
|  | 6 |  |  |  |  | 35 |  | 
| 5 | 6 |  |  | 6 |  | 2545 | use namespace::autoclean; | 
|  | 6 |  |  |  |  | 16 |  | 
|  | 6 |  |  |  |  | 54 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | # ABSTRACT: A REST API client for ValidSign | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 6 |  |  | 6 |  | 543 | use Carp qw(croak); | 
|  | 6 |  |  |  |  | 15 |  | 
|  | 6 |  |  |  |  | 384 |  | 
| 10 | 6 |  |  | 6 |  | 2706 | use HTTP::Request; | 
|  | 6 |  |  |  |  | 119892 |  | 
|  | 6 |  |  |  |  | 238 |  | 
| 11 | 6 |  |  | 6 |  | 3652 | use JSON qw(decode_json); | 
|  | 6 |  |  |  |  | 58705 |  | 
|  | 6 |  |  |  |  | 38 |  | 
| 12 | 6 |  |  | 6 |  | 916 | use URI; | 
|  | 6 |  |  |  |  | 17 |  | 
|  | 6 |  |  |  |  | 167 |  | 
| 13 | 6 |  |  | 6 |  | 3046 | use Types::Standard qw(Str); | 
|  | 6 |  |  |  |  | 481002 |  | 
|  | 6 |  |  |  |  | 87 |  | 
| 14 | 6 |  |  |  |  | 67 | use WebService::ValidSign::Types qw( | 
| 15 |  |  |  |  |  |  | WebServiceValidSignURI | 
| 16 | 6 |  |  | 6 |  | 7476 | ); | 
|  | 6 |  |  |  |  | 70 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | has lwp => ( | 
| 19 |  |  |  |  |  |  | is      => 'ro', | 
| 20 |  |  |  |  |  |  | lazy    => 1, | 
| 21 |  |  |  |  |  |  | builder => 1, | 
| 22 |  |  |  |  |  |  | ); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | has endpoint => ( | 
| 25 |  |  |  |  |  |  | is       => 'ro', | 
| 26 |  |  |  |  |  |  | isa      => WebServiceValidSignURI, | 
| 27 |  |  |  |  |  |  | default  => sub { 'https://try.validsign.nl/api' }, | 
| 28 |  |  |  |  |  |  | coerce   => 1 | 
| 29 |  |  |  |  |  |  | ); | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | has secret => ( | 
| 32 |  |  |  |  |  |  | is       => 'ro', | 
| 33 |  |  |  |  |  |  | isa      => Str, | 
| 34 |  |  |  |  |  |  | required => 1, | 
| 35 |  |  |  |  |  |  | ); | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | sub args_builder { | 
| 38 | 5 |  |  | 5 | 0 | 14 | my $self = shift; | 
| 39 | 5 |  |  |  |  | 14 | return map { $_ => $self->$_ } qw(secret endpoint lwp); | 
|  | 15 |  |  |  |  | 176 |  | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | sub _build_lwp { | 
| 43 | 4 |  |  | 4 |  | 1892 | require LWP::UserAgent; | 
| 44 | 4 |  |  |  |  | 48741 | return LWP::UserAgent->new( | 
| 45 |  |  |  |  |  |  | agent                 => "WebService::ValidSign/$VERSION", | 
| 46 |  |  |  |  |  |  | protocols_allowed     => [qw(https)], | 
| 47 |  |  |  |  |  |  | ssl_opts              => { verify_hostname => 1 }, | 
| 48 |  |  |  |  |  |  | requests_redirectable => [qw(HEAD GET)], | 
| 49 |  |  |  |  |  |  | ); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | around '_build_lwp' => sub { | 
| 53 |  |  |  |  |  |  | my ($orig, $self, @args) = @_; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | my $lwp = $orig->($self, @args); | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | $lwp->default_header("Authorization", join(" ", "Basic", $self->secret)); | 
| 58 |  |  |  |  |  |  | return $lwp; | 
| 59 |  |  |  |  |  |  | }; | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | 1; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | __END__ | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =pod | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =encoding UTF-8 | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head1 NAME | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | WebService::ValidSign::API::Constructor - A REST API client for ValidSign | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 VERSION | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | version 0.003 | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | use WebService::ValidSign; | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | my $client = WebService::ValidSign->new( | 
| 83 |  |  |  |  |  |  | secret   => "Your API key", | 
| 84 |  |  |  |  |  |  | endpoint => 'https://hostname.validsign.nl/api' | 
| 85 |  |  |  |  |  |  | ); | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | $client-> | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =over | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | =item api_uri | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | The API URI endpoint as described in the Acceplication Integrator's Guide | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =item lwp | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | An LWP::UserAgent object. If you extend this module you can use your own | 
| 100 |  |  |  |  |  |  | builder or just inject something that respects the LWP::UserAgent API. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =back | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =head1 METHODS | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head1 AUTHOR | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | Wesley Schwengle <waterkip@cpan.org> | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | This software is Copyright (c) 2019 by Wesley Schwengle. | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | This is free software, licensed under: | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | The (three-clause) BSD License | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | =cut |