File Coverage

blib/lib/Webservice/Purgomalum/API.pm
Criterion Covered Total %
statement 15 34 44.1
branch 0 6 0.0
condition n/a
subroutine 5 11 45.4
pod 2 6 33.3
total 22 57 38.6


line stmt bran cond sub pod time code
1 1     1   393498 use strict;
  1         3  
  1         46  
2 1     1   7 use warnings;
  1         2  
  1         120  
3              
4             package Webservice::Purgomalum::API;
5              
6             our $VERSION = 1.001;
7 1     1   943 use HTTP::Tiny;
  1         75433  
  1         50  
8 1     1   10 use Carp;
  1         3  
  1         79  
9 1     1   774 use Data::Dumper;
  1         10994  
  1         461  
10              
11             my $base_url = 'https://www.purgomalum.com/service/';
12              
13             sub new{
14 0     0 0   my ($package) = @_;
15 0           my $self = {
16             'ua' => HTTP::Tiny->new(),
17             'debug'=> 0,
18             };
19 0           bless $self, $package;
20 0           return $self;
21             }
22              
23             sub contains_profanity{
24 0     0 1   my ($self, %params) = @_;
25 0           return $self->fetch('containsprofanity?', %params);
26             }
27              
28             sub get{
29 0     0 1   my ($self, %params) = @_;
30 0           return $self->fetch('plain?', %params);
31             }
32              
33             sub fetch{
34 0     0 0   my ($self, $endpoint, %options) = @_;
35 0           my $params = $self->ua->www_form_urlencode( \%options );
36 0 0         my $response = $self->ua->get($base_url.$endpoint.$params) or croak "$!";
37              
38 0 0         print STDERR Dumper($response) if $self->{debug};
39              
40 0           return $response->{content};
41             }
42              
43             sub ua{
44 0     0 0   my $self = shift;
45 0           return $self->{ua};
46             }
47              
48             sub debug{
49 0     0 0   my ($self, $toggle) = @_;
50 0 0         if (defined $toggle){
51 0           $self->{debug} = $toggle;
52             }
53 0           return $self;
54             }
55             1;
56              
57              
58             __END__