line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Diffbot Perl API |
2
|
|
|
|
|
|
|
package WebService::Diffbot; |
3
|
|
|
|
|
|
|
{ |
4
|
|
|
|
|
|
|
$WebService::Diffbot::VERSION = '0.003'; |
5
|
|
|
|
|
|
|
} |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
855273
|
use Moo; |
|
1
|
|
|
|
|
14276
|
|
|
1
|
|
|
|
|
5
|
|
8
|
1
|
|
|
1
|
|
2405
|
use namespace::clean; |
|
1
|
|
|
|
|
11770
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
1378
|
use JSON qw( decode_json encode_json ); |
|
1
|
|
|
|
|
14752
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
758240
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
48272
|
|
|
1
|
|
|
|
|
608
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has api_url => ( is => 'ro', default => sub { 'http://api.diffbot.com/v2/' } ); |
14
|
|
|
|
|
|
|
has automatic_api => ( is => 'rw', default => sub { 'article' } ); |
15
|
|
|
|
|
|
|
has $_ => ( is => 'rw', required => 1 ) for qw( token url ); |
16
|
|
|
|
|
|
|
has $_ => ( is => 'rw' ) for qw( fields timeout callback ); |
17
|
|
|
|
|
|
|
has verbose => ( is => 'rw', default => sub { 0 } ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub article { |
20
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
21
|
0
|
|
|
|
|
|
my %args = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$self->automatic_api('article'); |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
$self->url( $args{url} ) if $args{url}; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$self->_process; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub frontpage { |
31
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my %args = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$self->automatic_api('frontpage'); |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
$self->url( $args{url} ) if $args{url}; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$self->_process; |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub version { |
42
|
0
|
|
|
0
|
0
|
|
__PACKAGE__->VERSION; |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _process { |
46
|
0
|
|
|
0
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
0
|
|
|
|
return if not defined $self->token or not defined $self->url; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $uri = URI->new($self->api_url . $self->automatic_api); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$uri->query_form( |
53
|
|
|
|
|
|
|
token => $self->token, |
54
|
|
|
|
|
|
|
url => $self->url, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $response = LWP::UserAgent->new->get($uri); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
die $response if !$response->is_success; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $content = decode_json $response->decoded_content; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
die $content->{error} if $content->{error}; |
64
|
0
|
0
|
|
|
|
|
print STDERR $content->{warning} if $content->{warning}; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $content; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |