File Coverage

blib/lib/WebService/DS/SOP/Auth/V1_1/Request/PUT_JSON.pm
Criterion Covered Total %
statement 27 27 100.0
branch 4 4 100.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1             package WebService::DS::SOP::Auth::V1_1::Request::PUT_JSON;
2 3     3   779 use strict;
  3         6  
  3         86  
3 3     3   20 use warnings;
  3         6  
  3         63  
4 3     3   14 use Carp ();
  3         11  
  3         78  
5 3     3   14 use JSON::XS qw(encode_json);
  3         7  
  3         142  
6 3     3   573 use HTTP::Request::Common qw(PUT);
  3         23885  
  3         194  
7 3     3   21 use WebService::DS::SOP::Auth::V1_1::Util qw(create_signature);
  3         13  
  3         519  
8              
9             sub create_request {
10 4     4 1 8531 my ($class, $uri, $params, $app_secret) = @_;
11              
12 4 100       30 Carp::croak('Missing required parameter: time') if not $params->{time};
13 3 100       20 Carp::croak('Missing app_secret') if not $app_secret;
14              
15 2         19 my $content = encode_json($params);
16 2         9 my $sig = create_signature($content, $app_secret);
17              
18 2         13 my $req = PUT $uri, Content => $content;
19 2         7823 $req->headers->header('content-type' => 'application/json');
20 2         97 $req->headers->header('x-sop-sig' => $sig);
21 2         120 $req;
22             }
23              
24             1;
25              
26             __END__
27              
28             =encoding utf-8
29              
30             =head1 NAME
31              
32             WebService::DS::SOP::Auth::V1_1::Request::PUT_JSON
33              
34             =head1 DESCRIPTION
35              
36             To create a valid L<HTTP::Request> object for C<PUT> request with content type C<application/json>.
37              
38             =head1 FUNCTIONS
39              
40             =head2 $class->create_request( URI $uri, Hash $params, Str $app_secret ) returns HTTP::Request
41              
42             Returns L<HTTP::Request> object for a PUT request with content-type C<application/json>,
43             with signature in header C<X-Sop-Sig>.
44              
45             =head1 LICENSE
46              
47             Copyright (C) dataSpring, Inc.
48             Copyright (C) Research Panel Asia, Inc.
49              
50             This library is free software; you can redistribute it and/or modify
51             it under the same terms as Perl itself.
52              
53             =head1 AUTHOR
54              
55             yowcow E<lt>yoko.oyama [ at ] d8aspring.comE<gt>
56              
57             =cut
58