File Coverage

lib/WebService/Readwise.pm
Criterion Covered Total %
statement 20 38 52.6
branch 0 6 0.0
condition 0 3 0.0
subroutine 7 10 70.0
pod 3 3 100.0
total 30 60 50.0


line stmt bran cond sub pod time code
1 2     2   526554 use strict;
  2         7  
  2         82  
2 2     2   15 use warnings;
  2         4  
  2         211  
3              
4 2     2   37 use v5.010;
  2         9  
5              
6             package WebService::Readwise;
7              
8             # ABSTRACT: Perl module to interact with Readwise.io API
9 2     2   1756 use HTTP::Tiny;
  2         131635  
  2         156  
10 2     2   1021 use JSON::MaybeXS;
  2         24547  
  2         161  
11              
12 2     2   1206 use Moo;
  2         19217  
  2         13  
13 2     2   5319 use namespace::clean;
  2         43720  
  2         17  
14              
15              
16             has token => (
17             is => 'ro',
18             required => 0,
19             default => sub { return $ENV{WEBSERVICE_READWISE_TOKEN} },
20             );
21              
22              
23             has base_url => (
24             is => 'ro',
25             default => sub {'https://readwise.io/api/v2/'},
26             );
27              
28              
29             has http => (
30             is => 'ro',
31             default => sub {
32             return HTTP::Tiny->new;
33             },
34             );
35              
36              
37             sub auth {
38 0     0 1   my $self = shift;
39              
40 0           my $response = $self->http->request(
41             'GET',
42             $self->base_url . 'auth/',
43             { headers => { Authorization => "Token $self->{token}", }, }
44             );
45              
46 0           return $response->{status};
47             }
48              
49              
50             sub export {
51 0     0 1   my ( $self, %params ) = @_;
52              
53 0           my $path = 'export/';
54 0 0 0       if ( %params && $params{'pageCursor'} ) {
55 0           $path .= '?pageCursor=' . $params{pageCursor};
56             }
57              
58 0           my $response = $self->http->request(
59             'GET',
60             $self->base_url . $path,
61             { headers => { Authorization => "Token $self->{token}", }, }
62             );
63              
64 0 0         if ( !$response->{success} ) {
65 0           return 'Response error';
66             }
67              
68 0           my $json = decode_json $response->{content};
69              
70 0           return $json;
71             }
72              
73              
74             sub highlights {
75 0     0 1   my $self = shift;
76              
77 0           my $response = $self->http->request(
78             'GET',
79             $self->base_url . 'highlights/',
80             { headers => { Authorization => "Token $self->{token}", }, }
81             );
82              
83 0 0         if ( !$response->{success} ) {
84 0           return 'Response error';
85             }
86              
87 0           my $json = decode_json $response->{content};
88              
89 0           return $json;
90             }
91              
92             1;
93              
94             __END__