File Coverage

blib/lib/WebService/DS/SOP/Auth/V1_1/Request/POST_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::POST_JSON;
2 3     3   108695 use strict;
  3         14  
  3         85  
3 3     3   14 use warnings;
  3         7  
  3         71  
4 3     3   15 use Carp ();
  3         8  
  3         64  
5 3     3   12 use JSON::XS qw(encode_json);
  3         7  
  3         170  
6 3     3   542 use HTTP::Request::Common qw(POST);
  3         18446  
  3         139  
7 3     3   451 use WebService::DS::SOP::Auth::V1_1::Util qw(create_signature);
  3         18  
  3         524  
8              
9             sub create_request {
10 6     6 1 13437 my ($class, $uri, $params, $app_secret) = @_;
11              
12 6 100       47 Carp::croak('Missing required parameter: time') if not $params->{time};
13 4 100       21 Carp::croak('Missing app_secret') if not $app_secret;
14              
15 3         33 my $content = encode_json($params);
16 3         12 my $sig = create_signature($content, $app_secret);
17              
18 3         1350 my $req = POST $uri, Content => $content;
19 3         1002 $req->headers->header('content-type' => 'application/json');
20 3         135 $req->headers->header('x-sop-sig' => $sig);
21 3         187 $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::POST_JSON
33              
34             =head1 DESCRIPTION
35              
36             To create a valid L<HTTP::Request> object for given C<POST> request parameters to send JSON data.
37              
38             =head1 METHODS
39              
40             =head2 $class->create_request( $uri, $params, $app_secret )
41              
42             Returns L<HTTP::Request> object for a POST request.
43             Request parameters are gathered as a JSON data in request body, while signature is added as request header C<X-Sop-Sig>.
44              
45             =head1 SEE ALSO
46              
47             L<HTTP::Request>
48             L<WebService::DS::SOP::Auth::V1_1>
49              
50             =head1 LICENSE
51              
52             Copyright (C) dataSpring, Inc.
53             Copyright (C) Research Panel Asia, Inc.
54              
55             This library is free software; you can redistribute it and/or modify
56             it under the same terms as Perl itself.
57              
58             =head1 AUTHOR
59              
60             yowcow E<lt>yoko.oyama [ at ] d8aspring.comE<gt>
61              
62             =cut
63