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