| 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
| |||||||||||||
| 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
MC/DC0%0/1
delete $config{'clientKey'} || undef
delete $config{'clientKey'}
Truth table0%0/2
A
A= delete $config{'clientKey'}
| |||||||||||||
| 28 | 0 | ▶ | Carp::croak("clientKey option is required") | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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'
MC/DC0%0/1
delete $config{'responce'} || 'hash'
delete $config{'responce'}
Truth table0%0/2
A
A= delete $config{'responce'}
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
MC/DC0%0/1
$request->{'queueId'} || 1
$request->{'queueId'}
Truth table0%0/2
A
A= $request->{'queueId'}
| |||||||||||||
| 83 | }); | ||||||||||||
| 84 | 0 | ▶ | if($self->{responce} eq 'json'){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||