| 1 | 7 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | 7 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | package WebService::SendGrid::Newsletter; | ||||||||||||
| 4 | |||||||||||||
| 5 | # ABSTRACT: Perl interface to SendGrid Newsletter API | ||||||||||||
| 6 | 7 | our $VERSION = '0.02'; # VERSION | |||||||||||
| 7 | |||||||||||||
| 8 | 7 | ▶ | use HTTP::Request::Common; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 7 | ▶ | use JSON; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 7 | ▶ | use HTTP::Tiny; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 7 | ▶ | use WebService::SendGrid::Newsletter::Lists; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 7 | ▶ | use WebService::SendGrid::Newsletter::Recipients; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 7 | ▶ | use WebService::SendGrid::Newsletter::Schedule; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 7 | ▶ | use WebService::SendGrid::Newsletter::Identity; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 7 | ▶ | use WebService::SendGrid::Newsletter::Categories; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 7 | ▶ | use parent 'WebService::SendGrid::Newsletter::Base'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | |||||||||||||
| 19 | |||||||||||||
| 20 | 7 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||
| 21 | 7 | my ($class, %args) = @_; | |||||||||||
| 22 | |||||||||||||
| 23 | 7 | my $self = {}; | |||||||||||
| 24 | 7 | bless($self, $class); | |||||||||||
| 25 | |||||||||||||
| 26 | 7 | $self->_check_required_args([ qw( api_user api_key ) ], %args); | |||||||||||
| 27 | |||||||||||||
| 28 | 6 | $self->{api_user} = $args{api_user}; | |||||||||||
| 29 | 6 | $self->{api_key} = $args{api_key}; | |||||||||||
| 30 | |||||||||||||
| 31 | 6 | $self->{ua} = HTTP::Tiny->new; | |||||||||||
| 32 | 6 | ▶ | $self->{ua}->agent(__PACKAGE__ . '/' . | ||||||||||
|
Condition50%1/2
$__PACKAGE__::VERSION || 0
MC/DC0%0/1
$__PACKAGE__::VERSION || 0
$__PACKAGE__::VERSION
Truth table50%1/2
A
A= $__PACKAGE__::VERSION
| |||||||||||||
| 33 | ($__PACKAGE__::VERSION || 0) . ' (Perl)'); | ||||||||||||
| 34 | |||||||||||||
| 35 | 6 | $self->{json_options} = $args{json_options}; | |||||||||||
| 36 | |||||||||||||
| 37 | 6 | $self->{last_response} = undef; | |||||||||||
| 38 | 6 | $self->{last_response_code} = undef; | |||||||||||
| 39 | |||||||||||||
| 40 | 6 | ▶ | if (exists $args{identity}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | $self->{identity} = $args{identity}; | |||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 6 | return $self; | |||||||||||
| 45 | } | ||||||||||||
| 46 | |||||||||||||
| 47 | # Sends a request to SendGrid Newsletter API | ||||||||||||
| 48 | 34 | ▶ | sub _send_request { | ||||||||||
|
Subroutine
_send_request: called CC=1 SCAR=0.0
| |||||||||||||
| 49 | 34 | my ($self, $path, %args) = @_; | |||||||||||
| 50 | |||||||||||||
| 51 | 34 | my $params = { api_user => $self->{api_user}, api_key => $self->{api_key}, %args }; | |||||||||||
| 52 | |||||||||||||
| 53 | 34 | my $url = 'https://api.sendgrid.com/api/newsletter/' . $path . '.json'; | |||||||||||
| 54 | |||||||||||||
| 55 | 34 | my $response = $self->{ua}->post_form($url, $params); | |||||||||||
| 56 | |||||||||||||
| 57 | 34 | $self->{last_response_code} = $response->{status}; | |||||||||||
| 58 | 34 | $self->{last_response} = decode_json $response->{content}; | |||||||||||
| 59 | |||||||||||||
| 60 | 32 | return $response->{success}; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | |||||||||||||
| 64 | 0 | ▶ | sub get { | ||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 65 | 0 | my ($self, %args) = @_; | |||||||||||
| 66 | |||||||||||||
| 67 | 0 | $self->_check_required_args([ qw( name ) ], %args); | |||||||||||
| 68 | |||||||||||||
| 69 | 0 | ▶ | if ($self->_send_request('get', %args)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | 0 | return $self->{last_response}; | |||||||||||
| 71 | } | ||||||||||||
| 72 | else { | ||||||||||||
| 73 | 0 | return; | |||||||||||
| 74 | } | ||||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | |||||||||||||
| 78 | 3 | ▶ | sub add { | ||||||||||
|
Subroutine
add: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||
| 79 | 3 | my ($self, %args) = @_; | |||||||||||
| 80 | |||||||||||||
| 81 | 3 | ▶ | if (!exists $args{identity}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 0 | $args{identity} = $self->{identity}; | |||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 3 | $self->_check_required_args([ qw( identity name subject text html ) ], | |||||||||||
| 86 | %args); | ||||||||||||
| 87 | |||||||||||||
| 88 | 3 | return $self->_send_request('add', %args); | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | |||||||||||||
| 92 | 0 | ▶ | sub edit { | ||||||||||
|
Subroutine
edit: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 93 | 0 | my ($self, %args) = @_; | |||||||||||
| 94 | |||||||||||||
| 95 | 0 | $self->_check_required_args([ qw( name newname identity subject text | |||||||||||
| 96 | html ) ], %args); | ||||||||||||
| 97 | |||||||||||||
| 98 | 0 | return $self->_send_request('edit', %args); | |||||||||||
| 99 | } | ||||||||||||
| 100 | |||||||||||||
| 101 | |||||||||||||
| 102 | 0 | ▶ | sub list { | ||||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 103 | 0 | my ($self, %args) = @_; | |||||||||||
| 104 | |||||||||||||
| 105 | 0 | ▶ | if ($self->_send_request('list', %args)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | 0 | return $self->{last_response}; | |||||||||||
| 107 | } | ||||||||||||
| 108 | else { | ||||||||||||
| 109 | 0 | return; | |||||||||||
| 110 | } | ||||||||||||
| 111 | } | ||||||||||||
| 112 | |||||||||||||
| 113 | |||||||||||||
| 114 | 1 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 115 | 1 | my ($self, %args) = @_; | |||||||||||
| 116 | |||||||||||||
| 117 | 1 | $self->_check_required_args([ qw( name ) ], %args); | |||||||||||
| 118 | |||||||||||||
| 119 | 1 | return $self->_send_request('delete', %args); | |||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | |||||||||||||
| 123 | 15 | ▶ | sub lists { | ||||||||||
|
Subroutine
lists: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 124 | 15 | my ($self) = @_; | |||||||||||
| 125 | |||||||||||||
| 126 | 15 | ▶ | if (!defined $self->{lists}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 127 | 3 | $self->{lists} = WebService::SendGrid::Newsletter::Lists->new( | |||||||||||
| 128 | sgn => $self | ||||||||||||
| 129 | ); | ||||||||||||
| 130 | } | ||||||||||||
| 131 | |||||||||||||
| 132 | 15 | return $self->{lists}; | |||||||||||
| 133 | } | ||||||||||||
| 134 | |||||||||||||
| 135 | |||||||||||||
| 136 | 7 | ▶ | sub recipients { | ||||||||||
|
Subroutine
recipients: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 137 | 7 | my ($self) = @_; | |||||||||||
| 138 | |||||||||||||
| 139 | 7 | ▶ | if (!defined $self->{recipients}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 140 | $self->{recipients} = | ||||||||||||
| 141 | 2 | WebService::SendGrid::Newsletter::Recipients->new(sgn => $self); | |||||||||||
| 142 | } | ||||||||||||
| 143 | |||||||||||||
| 144 | 7 | return $self->{recipients}; | |||||||||||
| 145 | } | ||||||||||||
| 146 | |||||||||||||
| 147 | |||||||||||||
| 148 | 7 | ▶ | sub schedule { | ||||||||||
|
Subroutine
schedule: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 149 | 7 | my ($self) = @_; | |||||||||||
| 150 | |||||||||||||
| 151 | 7 | ▶ | if (!defined $self->{schedule}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 152 | $self->{schedule} = | ||||||||||||
| 153 | 1 | WebService::SendGrid::Newsletter::Schedule->new(sgn => $self); | |||||||||||
| 154 | } | ||||||||||||
| 155 | |||||||||||||
| 156 | 7 | return $self->{schedule}; | |||||||||||
| 157 | } | ||||||||||||
| 158 | |||||||||||||
| 159 | |||||||||||||
| 160 | 9 | ▶ | sub identity { | ||||||||||
|
Subroutine
identity: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 161 | 9 | my ($self) = @_; | |||||||||||
| 162 | |||||||||||||
| 163 | 9 | ▶ | if (!defined $self->{identity}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 164 | $self->{identity} = | ||||||||||||
| 165 | 1 | WebService::SendGrid::Newsletter::Identity->new(sgn => $self); | |||||||||||
| 166 | } | ||||||||||||
| 167 | |||||||||||||
| 168 | 9 | return $self->{identity}; | |||||||||||
| 169 | } | ||||||||||||
| 170 | |||||||||||||
| 171 | |||||||||||||
| 172 | 7 | ▶ | sub categories { | ||||||||||
|
Subroutine
categories: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 173 | 7 | my ($self) = @_; | |||||||||||
| 174 | |||||||||||||
| 175 | 7 | ▶ | if (!defined $self->{categories}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 176 | $self->{categories} = | ||||||||||||
| 177 | 1 | WebService::SendGrid::Newsletter::Categories->new(sgn => $self); | |||||||||||
| 178 | } | ||||||||||||
| 179 | |||||||||||||
| 180 | 7 | return $self->{categories}; | |||||||||||
| 181 | } | ||||||||||||
| 182 | |||||||||||||
| 183 | |||||||||||||
| 184 | 0 | ▶ | sub last_response_code { | ||||||||||
|
Subroutine
last_response_code: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 185 | 0 | my ($self) = @_; | |||||||||||
| 186 | |||||||||||||
| 187 | 0 | return $self->{last_response_code}; | |||||||||||
| 188 | } | ||||||||||||
| 189 | |||||||||||||
| 190 | |||||||||||||
| 191 | 0 | ▶ | sub last_response { | ||||||||||
|
Subroutine
last_response: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 192 | 0 | my ($self) = @_; | |||||||||||
| 193 | |||||||||||||
| 194 | 0 | return $self->{last_response}; | |||||||||||
| 195 | } | ||||||||||||
| 196 | |||||||||||||
| 197 | 7 | 1; | |||||||||||
| 198 | |||||||||||||
| 199 | __END__ | ||||||||||||