| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::ValidSign; | 
| 2 |  |  |  |  |  |  | our $VERSION = '0.002'; | 
| 3 | 3 |  |  | 3 |  | 351612 | use Moo; | 
|  | 3 |  |  |  |  | 24657 |  | 
|  | 3 |  |  |  |  | 15 |  | 
| 4 | 3 |  |  | 3 |  | 4576 | use namespace::autoclean; | 
|  | 3 |  |  |  |  | 13105 |  | 
|  | 3 |  |  |  |  | 17 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | # ABSTRACT: A REST API client for ValidSign | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 3 |  |  | 3 |  | 1478 | use Module::Pluggable::Object; | 
|  | 3 |  |  |  |  | 21535 |  | 
|  | 3 |  |  |  |  | 112 |  | 
| 9 | 3 |  |  | 3 |  | 24 | use List::Util qw(first); | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 1054 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | has auth => ( | 
| 12 |  |  |  |  |  |  | is      => 'ro', | 
| 13 |  |  |  |  |  |  | builder => 1, | 
| 14 |  |  |  |  |  |  | lazy    => 1, | 
| 15 |  |  |  |  |  |  | handles => [qw(token)], | 
| 16 |  |  |  |  |  |  | ); | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | has package => ( | 
| 19 |  |  |  |  |  |  | is      => 'ro', | 
| 20 |  |  |  |  |  |  | lazy    => 1, | 
| 21 |  |  |  |  |  |  | builder => 1, | 
| 22 |  |  |  |  |  |  | ); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | has account => ( | 
| 25 |  |  |  |  |  |  | is      => 'ro', | 
| 26 |  |  |  |  |  |  | lazy    => 1, | 
| 27 |  |  |  |  |  |  | builder => 1, | 
| 28 |  |  |  |  |  |  | ); | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | { | 
| 31 |  |  |  |  |  |  | my @API_PLUGINS; | 
| 32 |  |  |  |  |  |  | my $search_path = 'WebService::ValidSign::API'; | 
| 33 |  |  |  |  |  |  | sub __build_api_package { | 
| 34 | 3 |  |  | 3 |  | 11 | my ($self, $pkg) = @_; | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 3 | 100 |  |  |  | 12 | if (!@API_PLUGINS) { | 
| 37 | 2 |  |  |  |  | 18 | my $finder = Module::Pluggable::Object->new( | 
| 38 |  |  |  |  |  |  | search_path => $search_path, | 
| 39 |  |  |  |  |  |  | require     => 1, | 
| 40 |  |  |  |  |  |  | ); | 
| 41 | 2 |  |  |  |  | 28 | @API_PLUGINS = $finder->plugins; | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 3 | 50 |  | 5 |  | 7521 | if (my $plugin = first { $pkg eq $_ } @API_PLUGINS) { | 
|  | 5 |  |  |  |  | 22 |  | 
| 45 | 3 | 100 |  |  |  | 15 | return $pkg->new( | 
| 46 |  |  |  |  |  |  | $self->args_builder, | 
| 47 |  |  |  |  |  |  | $pkg eq 'WebService::ValidSign::API::Auth' ? () : ( | 
| 48 |  |  |  |  |  |  | auth => $self->auth, | 
| 49 |  |  |  |  |  |  | ) | 
| 50 |  |  |  |  |  |  | ); | 
| 51 |  |  |  |  |  |  | } | 
| 52 | 0 |  |  |  |  | 0 | die sprintf("Unable to load '%s', not found in search path: '%s'!\n", | 
| 53 |  |  |  |  |  |  | $pkg, $search_path); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub _build_auth { | 
| 58 | 2 |  |  | 2 |  | 10700 | my $self = shift; | 
| 59 | 2 |  |  |  |  | 10 | return $self->__build_api_package('WebService::ValidSign::API::Auth'); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub _build_package { | 
| 63 | 0 |  |  | 0 |  | 0 | my $self = shift; | 
| 64 | 0 |  |  |  |  | 0 | return $self->__build_api_package('WebService::ValidSign::API::DocumentPackage'); | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub _build_account { | 
| 68 | 1 |  |  | 1 |  | 8489 | my $self = shift; | 
| 69 | 1 |  |  |  |  | 4 | return $self->__build_api_package('WebService::ValidSign::API::Account'); | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | with "WebService::ValidSign::API::Constructor"; | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | __END__ | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =pod | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | =encoding UTF-8 | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =head1 NAME | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | WebService::ValidSign - A REST API client for ValidSign | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =head1 VERSION | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | version 0.002 | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | use WebService::ValidSign; | 
| 93 |  |  |  |  |  |  | use WebService::ValidSign::Object::DocumentPackage; | 
| 94 |  |  |  |  |  |  | use WebService::ValidSign::Object::Document; | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | my $client = WebService::ValidSign->new( | 
| 97 |  |  |  |  |  |  | secret   => 'my very secret API key', | 
| 98 |  |  |  |  |  |  | endpoint => 'https://my.validsign.nl/api' | 
| 99 |  |  |  |  |  |  | lwp      => LWP::UserAgent->new(), # optional | 
| 100 |  |  |  |  |  |  | ); | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | my $documentpackage = WebService::ValidSign::Object::DocumentPackage->new( | 
| 103 |  |  |  |  |  |  | name => "Document package name" | 
| 104 |  |  |  |  |  |  | ); | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | my $senders = $client->account->senders(search => $sender); | 
| 107 |  |  |  |  |  |  | if (!@$senders) { | 
| 108 |  |  |  |  |  |  | die "Unable to find sender $opts{senders}\n"; | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  | elsif (@$senders > 1) { | 
| 111 |  |  |  |  |  |  | die "Multiple senders found for $opts{senders}\n"; | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  | $documentpackage->sender($senders->[0]); | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | my $signers = $client->account->senders(search => $signer); | 
| 116 |  |  |  |  |  |  | if (!@$signers) { | 
| 117 |  |  |  |  |  |  | die "Unable to find sender $signer\n"; | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  | # at this moment only one signer is supported | 
| 120 |  |  |  |  |  |  | elsif (@$signers > 1) { | 
| 121 |  |  |  |  |  |  | die "Multiple senders found for $signer}\n"; | 
| 122 |  |  |  |  |  |  | } | 
| 123 |  |  |  |  |  |  | $documentpackage->add_signer('rolename' => signers->[0]); | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | my @documents = qw( | 
| 126 |  |  |  |  |  |  | /path/to/documents/foo.bar | 
| 127 |  |  |  |  |  |  | /path/to/documents/foo.txt | 
| 128 |  |  |  |  |  |  | ); | 
| 129 |  |  |  |  |  |  | foreach (@documents) { | 
| 130 |  |  |  |  |  |  | my $document = WebService::ValidSign::Object::Document->new( | 
| 131 |  |  |  |  |  |  | name => "$_", | 
| 132 |  |  |  |  |  |  | path => $_, | 
| 133 |  |  |  |  |  |  | ); | 
| 134 |  |  |  |  |  |  | $documentpackage->add_document($document); | 
| 135 |  |  |  |  |  |  | } | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | my $id = $client->package->create($documentpackage); | 
| 138 |  |  |  |  |  |  | print "Created package with ID $id", $/; | 
| 139 |  |  |  |  |  |  | my $details = $client->package->details($documentpackage); | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | A module that uses the ValidSign API to create/upload and sign documents. | 
| 144 |  |  |  |  |  |  | This module is in ALPHA state and is subject to change at any given moment | 
| 145 |  |  |  |  |  |  | without notice. | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | This module extends L<WebService::ValidSign::API::Constructor> and all of its | 
| 150 |  |  |  |  |  |  | attributes. | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =over | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | =item secret | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | Your API key | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =item endpoint | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | The API URI endpoint as described in the Application Integrator's Guide | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | =item lwp | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | An L<LWP::UserAgent> object. | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | =item auth | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | An L<WebService::ValidSign::API::Auth> object. Build for you. | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | =item package | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | An L<WebService::ValidSign::API::DocumentPackage> object. Build for you. | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | =item account | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | An L<WebService::ValidSign::API::Account> object. Build for you. | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | =back | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | This module has been made possible by my employer L<Mintlab | 
| 183 |  |  |  |  |  |  | B.V.|https://mintlab.nl> who uses this module in their open source product | 
| 184 |  |  |  |  |  |  | L<Zaaksysteem|https://zaaksysteem.nl>. | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | =head1 AUTHOR | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  | Wesley Schwengle <waterkip@cpan.org> | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | This software is Copyright (c) 2019 by Wesley Schwengle. | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | This is free software, licensed under: | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | The (three-clause) BSD License | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | =cut |