File Coverage

blib/lib/WebService/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::SOP::Auth::V1_1::Request::POST_JSON;
2 3     3   77474 use strict;
  3         4  
  3         84  
3 3     3   11 use warnings;
  3         3  
  3         50  
4 3     3   10 use Carp ();
  3         3  
  3         36  
5 3     3   9 use JSON::XS qw(encode_json);
  3         5  
  3         128  
6 3     3   499 use HTTP::Request::Common qw(POST);
  3         14082  
  3         141  
7 3     3   391 use WebService::SOP::Auth::V1_1::Util qw(create_signature);
  3         17  
  3         420  
8              
9             sub create_request {
10 6     6 1 9077 my ($class, $uri, $params, $app_secret) = @_;
11              
12 6 100       41 Carp::croak('Missing required parameter: time') if not $params->{time};
13 4 100       16 Carp::croak('Missing app_secret') if not $app_secret;
14              
15 3         47 my $content = encode_json($params);
16 3         10 my $sig = create_signature($content, $app_secret);
17              
18 3         1279 my $req = POST $uri, Content => $content;
19 3         650 $req->headers->header('content-type' => 'application/json');
20 3         83 $req->headers->header('x-sop-sig' => $sig);
21 3         120 $req;
22             }
23              
24             1;
25              
26             __END__
27              
28             =encoding utf-8
29              
30             =head1 NAME
31              
32             WebService::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::SOP::Auth::V1_1>
49              
50             =head1 LICENSE
51              
52             Copyright (C) Research Panel Asia, Inc.
53              
54             This library is free software; you can redistribute it and/or modify
55             it under the same terms as Perl itself.
56              
57             =head1 AUTHOR
58              
59             yowcowvg E<lt>yoko_ohyama [ at ] voyagegroup.comE<gt>
60              
61             =cut
62