StatsMix/UserAgent.pm

filter: Statementstmt 54.9% 28 / 51 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 64.2% 9 / 14 Podpod 100% 4 / 4 totaltotal 56.1% 41 / 73 SCAR 14.0
CC
3
Cov
51%
_response
12.0
get
2.0
put
2.0
CRAP 4.1
« StatsMix/Params.pm ↑ Summary StatsMix/UserAgent/Exception.pm »
1 package WWW::StatsMix::UserAgent;
2  
3 12 $WWW::StatsMix::UserAgent::VERSION = '0.05';
4  
5 =head1 NAME
6  
7 WWW::StatsMix::UserAgent - StatsMix API user agent library.
8  
9 =head1 VERSION
10  
11 Version 0.05
12  
13 =cut
14  
15 12 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 12 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 12 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 12 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶use HTTP::Request::Common qw(POST PUT GET DELETE);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶use WWW::StatsMix::UserAgent::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 12 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 12 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 12 has 'api_key' => ( is => 'ro', required => 1 );
27 11 ▶has 'ua' => ( is => 'rw', default => sub { LWP::UserAgent->new(agent => "WWW-StatsMix-API/0.01"); } );
Subroutine __ANON__: called CC=1 SCAR=0.0
28  
29 =head1 DESCRIPTION
30  
31 The L<WWW::StatsMix::UserAgent> module is part of the core library for StatsMix
32 API services.
33  
34 =head1 METHODS
35  
36 =head2 get(<url>)
37  
38 The method get() expects one parameter i.e. URL and returns the standard response.
39 On error throws exception of type L<WWW::StatsMix::UserAgent::Exception>.
40  
41 =cut
42  
43 sub get {
44 0 ▶ my ($self, $url) = @_;
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
45  
46 0 my $request = GET($url);
47 0 $request->header("X-StatsMix-Token", $self->api_key);
48  
49 0 return _response($self->ua->request($request));
50 }
51  
52 =head2 put(<url>, <content>)
53  
54 The method put() expects three parameters i.e. URL, Headers, Content in the same
55 order and returns the standard response. On error throws exception of type L<WWW::StatsMix::UserAgent::Exception>.
56  
57 =cut
58  
59 sub put {
60 0 ▶ my ($self, $url, $content) = @_;
Subroutine put: not called CC=1 SCAR=6.9
Pod documented
61  
62 0 my $request = POST($url, $content);
63 0 $request->method('PUT');
64 0 $request->header("X-StatsMix-Token", $self->api_key);
65  
66 0 return _response($self->ua->request($request));
67 }
68  
69 =head2 post(<url>, <content>)
70  
71 The method post() expects three parameters i.e. URL, Headers, Content in the same
72 order and returns the standard response. On error throws exception of type L<WWW::StatsMix::UserAgent::Exception>.
73  
74 =cut
75  
76 sub post {
77 0 ▶ my ($self, $url, $content) = @_;
Subroutine post: not called CC=1 SCAR=6.9
Pod documented
78  
79 0 my $request = POST($url, $content);
80 0 $request->header("X-StatsMix-Token", $self->api_key);
81  
82 0 return _response($self->ua->request($request));
83 }
84  
85 =head2 delete(<url>)
86  
87 The method delete() expects one parameter URL and returns the standard response.
88 On error throws exception of type L<WWW::StatsMix::UserAgent::Exception>.
89  
90 =cut
91  
92 sub delete {
93 0 ▶ my ($self, $url) = @_;
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
94  
95 0 my $request = DELETE($url);
96 0 $request->header("X-StatsMix-Token", $self->api_key);
97  
98 0 return _response($self->ua->request($request));
99 }
100  
101 sub _response {
102 0 ▶ my ($response) = @_;
Subroutine _response: not called CC=3 SCAR=24.8
103  
104 0 my @caller = caller(1);
105 0 ▶ @caller = caller(2) if $caller[3] eq '(eval)';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[3] eq "(eval)" 0 0 0
106  
107 0 ▶ unless ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
108 0 WWW::StatsMix::UserAgent::Exception->throw({
109 method => $caller[3],
110 message => $response->message,
111 code => $response->code,
112 filename => $caller[1],
113 line_number => $caller[2] });
114 }
115  
116 0 return $response;
117 }
118  
119 =head1 AUTHOR
120  
121 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
122  
123 =head1 REPOSITORY
124  
125 L<https://github.com/Manwar/WWW-StatsMix>
126  
127 =head1 BUGS
128  
129 Please report any bugs or feature requests to C<bug-www-statsmix at rt.cpan.org>,
130 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-StatsMix>.
131 I will be notified, and then you'll automatically be notified of progress on your
132 bug as I make changes.
133  
134 =head1 SUPPORT
135  
136 You can find documentation for this module with the perldoc command.
137  
138 perldoc WWW::StatsMix::UserAgent
139  
140 You can also look for information at:
141  
142 =over 4
143  
144 =item * RT: CPAN's request tracker (report bugs here)
145  
146 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-StatsMix>
147  
148 =item * AnnoCPAN: Annotated CPAN documentation
149  
150 L<http://annocpan.org/dist/WWW-StatsMix>
151  
152 =item * CPAN Ratings
153  
154 L<http://cpanratings.perl.org/d/WWW-StatsMix>
155  
156 =item * Search CPAN
157  
158 L<http://search.cpan.org/dist/WWW-StatsMix/>
159  
160 =back
161  
162 Copyright (C) 2014 - 2015 Mohammad S Anwar.
163  
164 This program is free software; you can redistribute it and/or modify it under
165 the terms of the the Artistic License (2.0). You may obtain a copy of the full
166 license at:
167  
168 L<http://www.perlfoundation.org/artistic_license_2_0>
169  
170 Any use, modification, and distribution of the Standard or Modified Versions is
171 governed by this Artistic License.By using, modifying or distributing the Package,
172 you accept this license. Do not use, modify, or distribute the Package, if you do
173 not accept this license.
174  
175 If your Modified Version has been derived from a Modified Version made by someone
176 other than you,you are nevertheless required to ensure that your Modified Version
177 complies with the requirements of this license.
178  
179 This license does not grant you the right to use any trademark, service mark,
180 tradename, or logo of the Copyright Holder.
181  
182 This license includes the non-exclusive, worldwide, free-of-charge patent license
183 to make, have made, use, offer to sell, sell, import and otherwise transfer the
184 Package with respect to any patent claims licensable by the Copyright Holder that
185 are necessarily infringed by the Package. If you institute patent litigation
186 (including a cross-claim or counterclaim) against any party alleging that the
187 Package constitutes direct or contributory patent infringement,then this Artistic
188 License to you shall terminate on the date that such litigation is filed.
189  
190 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
191 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
192 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
193 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
194 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
195 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
196 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
197  
198 =cut
199  
200 12 1; # End of WWW::StatsMix::UserAgent
« StatsMix/Params.pm ↑ Summary StatsMix/UserAgent/Exception.pm »