Anticaptcha/Request.pm

filter: Statementstmt 37.6% 26 / 69 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 53.8% 7 / 13 Podpod 83.3% 5 / 6 totaltotal 34.2% 38 / 111 CC 11 SCAR 23.5
CC
11
Cov
29%
new
30.0
getQueueStats
12.0
createTask
6.0
CRAP 10.5
↑ Summary Anticaptcha.pm »
1 package Anticaptcha::Request;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 require Exporter;
6 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 @ISA = ('Exporter');
8  
9 1 $VERSION = "1.02";
10 1 require 5.010;
11  
12 1 ▶use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use LWP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Anticaptcha ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 sub new
20 0 ▶{
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
21 # Check for common user mistake
22 0 ▶ Carp::croak("Options to Anticaptcha::Request should be key/value pairs, not hash reference")
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[1] eq "HASH" 0 0 0
23 if ref($_[1]) eq 'HASH';
24  
25 0 my($class, %config) = @_;
26  
27 0 ▶ my $clientKey = delete $config{clientKey} || undef;
Condition0%0/2
delete $config{'clientKey'} || undef
l!l
00
MC/DC0%0/1
delete $config{'clientKey'} || undef
delete $config{'clientKey'}
Truth table0%0/2
A
A= delete $config{'clientKey'}
Aresult
11
00
28 0 ▶ Carp::croak("clientKey option is required")
Branch: 1 branch
BranchTrueFalseTotal
unless $clientKey 0 0 0
29 if !$clientKey;
30  
31 my $self = bless {
32 clientKey => $clientKey,
33 0 ▶ responce => delete $config{responce} || 'hash'
Condition0%0/2
delete $config{'responce'} || 'hash'
l!l
00
MC/DC0%0/1
delete $config{'responce'} || 'hash'
delete $config{'responce'}
Truth table0%0/2
A
A= delete $config{'responce'}
Aresult
11
00
34 }, $class;
35 0 $self->{BROWSER} = LWP::UserAgent->new(
36 ssl_opts => {
37 SSL_verify_mode => 0,
38 verify_hostname => 0
39 }
40 );
41  
42 0 return $self;
43 }
44  
45 0 ▶sub createTask{
Subroutine createTask: not called CC=2 SCAR=17.9
Pod documented
46 0 my($self, $request) = @_;
47 0 my $req = $request;
48 0 $req->{clientKey} = $self->{clientKey};
49 0 my $json = JSON::encode_json($req);
50  
51 0 my $res = $self->request({
52 task => 'createTask',
53 data => $json
54 });
55 0 ▶ if($self->{responce} eq 'json'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'responce'} eq 'json') { } 0 0 0
56 0 return $res;
57 }else{
58 0 return JSON::decode_json($res);
59 }
60 }
61  
62 0 ▶sub getBalance{
Subroutine getBalance: not called CC=2 SCAR=17.9
Pod documented
63 0 my($self) = @_;
64 0 my $json = JSON::encode_json({clientKey => $self->{clientKey}});
65  
66 0 my $res = $self->request({
67 task => 'getBalance',
68 data => $json
69 });
70 0 ▶ if($self->{responce} eq 'json'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'responce'} eq 'json') { } 0 0 0
71 0 return $res;
72 }else{
73 0 return JSON::decode_json($res);
74 }
75 }
76  
77 0 ▶sub getQueueStats{
Subroutine getQueueStats: not called CC=3 SCAR=24.8
Pod documented
78 0 my($self, $request) = @_;
79  
80 my $res = $self->request({
81 task => 'getQueueStats',
82 0 ▶ data => JSON::encode_json({queueId => ($request->{queueId} || 1)})
Condition0%0/2
$request->{'queueId'} || 1
l!l
00
MC/DC0%0/1
$request->{'queueId'} || 1
$request->{'queueId'}
Truth table0%0/2
A
A= $request->{'queueId'}
Aresult
11
00
83 });
84 0 ▶ if($self->{responce} eq 'json'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'responce'} eq 'json') { } 0 0 0
85 0 return $res;
86 }else{
87 0 return JSON::decode_json($res);
88 }
89 }
90  
91 0 ▶sub getTaskResult{
Subroutine getTaskResult: not called CC=2 SCAR=17.9
Pod documented
92 0 my($self, $request) = @_;
93 0 my $req;
94 0 $req->{clientKey} = $self->{clientKey};
95 0 $req->{taskId} = $request->{taskId};
96 0 my $json = JSON::encode_json($req);
97  
98 0 my $res = $self->request({
99 task => 'getTaskResult',
100 data => $json
101 });
102 0 ▶ if($self->{responce} eq 'json'){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'responce'} eq 'json') { } 0 0 0
103 0 return $res;
104 }else{
105 0 return JSON::decode_json($res);
106 }
107 }
108  
109 0 ▶sub request{
Subroutine request: not called CC=2 SCAR=17.9
Pod undocumented
110 0 my($self, $request) = @_;
111  
112 0 my $req = HTTP::Request->new(POST => 'https://api.anti-captcha.com/'.$request->{task});
113 0 $req->content_type('application/json');
114 0 $req->content($request->{data});
115 0 my $res = $self->{BROWSER}->request($req);
116 0 ▶ if($res->is_success){
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
117 0 return $res->content;
118 }else{
119 0 return '{"errorId":999,"status":"HTTP ERROR '.$res->status_line.'"}';
120 }
121 }
122  
123 1 1;
124  
125 __END__
↑ Summary Anticaptcha.pm »