File Coverage

blib/lib/WebService/ValidSign.pm
Criterion Covered Total %
statement 25 26 96.1
branch 5 6 83.3
condition n/a
subroutine 9 9 100.0
pod n/a
total 39 41 95.1


line stmt bran cond sub pod time code
1             package WebService::ValidSign;
2             our $VERSION = '0.003';
3 6     6   1000257 use Moo;
  6         39273  
  6         29  
4 6     6   8222 use namespace::autoclean;
  6         14  
  6         37  
5              
6             # ABSTRACT: A REST API client for ValidSign
7              
8 6     6   3067 use Module::Pluggable::Object;
  6         42107  
  6         218  
9 6     6   45 use List::Util qw(first);
  6         13  
  6         2284  
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 5     5   19 my ($self, $pkg) = @_;
35              
36 5 100       26 if (!@API_PLUGINS) {
37 3         31 my $finder = Module::Pluggable::Object->new(
38             search_path => $search_path,
39             require => 1,
40             );
41 3         43 @API_PLUGINS = $finder->plugins;
42             }
43              
44 5 50   11   8892 if (my $plugin = first { $pkg eq $_ } @API_PLUGINS) {
  11         40  
45 5 100       29 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 3     3   7721 my $self = shift;
59 3         19 return $self->__build_api_package('WebService::ValidSign::API::Auth');
60             }
61              
62             sub _build_package {
63 1     1   7715 my $self = shift;
64 1         3 return $self->__build_api_package('WebService::ValidSign::API::DocumentPackage');
65             }
66              
67             sub _build_account {
68 1     1   8539 my $self = shift;
69 1         5 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.003
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 BUGS
181              
182             L<JSON::XS> 4.01 has a bug that causes JSON serialization errors. Please
183             upgrade or downgrade JSON::XS where needed.
184              
185             =head1 ACKNOWLEDGEMENTS
186              
187             This module has been made possible by my employer L<Mintlab
188             B.V.|https://mintlab.nl> who uses this module in their open source product
189             L<Zaaksysteem|https://zaaksysteem.nl>.
190              
191             =head1 AUTHOR
192              
193             Wesley Schwengle <waterkip@cpan.org>
194              
195             =head1 COPYRIGHT AND LICENSE
196              
197             This software is Copyright (c) 2019 by Wesley Schwengle.
198              
199             This is free software, licensed under:
200              
201             The (three-clause) BSD License
202              
203             =cut