| 1 | package Nexmo::SMS::WAPPushMessage; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Nexmo::SMS::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use JSON::PP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | # ABSTRACT: Module that respresents a WAPPush message for the Nexmo SMS API! | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 9 | my %attrs = ( | |||||||||||||||||||||||||||
| 16 | title => 'required', | ||||||||||||||||||||||||||||
| 17 | url => 'required', | ||||||||||||||||||||||||||||
| 18 | type => 'required', | ||||||||||||||||||||||||||||
| 19 | from => 'required', | ||||||||||||||||||||||||||||
| 20 | to => 'required', | ||||||||||||||||||||||||||||
| 21 | server => 'required', | ||||||||||||||||||||||||||||
| 22 | username => 'required', | ||||||||||||||||||||||||||||
| 23 | password => 'required', | ||||||||||||||||||||||||||||
| 24 | status_report_req => 'optional', | ||||||||||||||||||||||||||||
| 25 | client_ref => 'optional', | ||||||||||||||||||||||||||||
| 26 | network_code => 'optional', | ||||||||||||||||||||||||||||
| 27 | validity => 'optional', | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 9 | for my $attr ( keys %attrs ) { | |||||||||||||||||||||||||||
| 31 | 9 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 108 | ▶ | *{ __PACKAGE__ . '::' . $attr } = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 33 | 20 | my ($self,$value) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 20 | my $key = '__' . $attr . '__'; | |||||||||||||||||||||||||||
| 36 | 20 | ▶ | $self->{$key} = $value if @_ == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 20 | return $self->{$key}; | |||||||||||||||||||||||||||
| 38 | 108 | }; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 1 | my ($class,%param) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | for my $attr ( keys %attrs ) { | |||||||||||||||||||||||||||
| 48 | 12 | ▶ | if ( exists $param{$attr} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 8 | $self->$attr( $param{$attr} ); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | $self->user_agent( | ||||||||||||||||||||||||||||
| 54 | 1 | LWP::UserAgent->new( | |||||||||||||||||||||||||||
| 55 | agent => 'Perl module ' . __PACKAGE__ . ' ' . $VERSION, | ||||||||||||||||||||||||||||
| 56 | ), | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | return $self; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | ▶ | sub user_agent { | ||||||||||||||||||||||||||
|
Subroutine
user_agent: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 2 | my ($self,$ua) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | ▶ | $self->{__ua__} = $ua if @_ == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 2 | return $self->{__ua__}; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub errstr { | ||||||||||||||||||||||||||
|
Subroutine
errstr: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | my ($self,$message) = @_; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $self->{__errstr__} = $message if @_ == 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | return $self->{__errstr__}; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub send { | ||||||||||||||||||||||||||
|
Subroutine
send: called CC=9 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 1 | my ($self) = shift; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | my %optional; | |||||||||||||||||||||||||||
| 83 | 1 | ▶ | $optional{'client-ref'} = $self->client_ref if $self->client_ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | $optional{'status-report-req'} = $self->status_report_req if $self->status_report_req; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 1 | ▶ | $optional{'network-code'} = $self->network_code if $self->network_code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | $optional{'validity'} = $self->validity if $self->validity; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | my $response = $self->user_agent->post( | |||||||||||||||||||||||||||
| 89 | $self->server, | ||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | %optional, | ||||||||||||||||||||||||||||
| 92 | username => $self->username, | ||||||||||||||||||||||||||||
| 93 | password => $self->password, | ||||||||||||||||||||||||||||
| 94 | from => $self->from, | ||||||||||||||||||||||||||||
| 95 | to => $self->to, | ||||||||||||||||||||||||||||
| 96 | title => $self->title, | ||||||||||||||||||||||||||||
| 97 | url => $self->url, | ||||||||||||||||||||||||||||
| 98 | type => $self->type, | ||||||||||||||||||||||||||||
| 99 | }, | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | ▶ | if ( !$response || !$response->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$response and $response->is_success
MC/DC0%0/2
$response and $response->is_success
$response
$response->is_success
Truth table33%1/3
A and B
A= $responseB= $response->is_success
| |||||||||||||||||||||||||||||
| 103 | 0 | $self->errstr("Request was not successful: " . $response->status_line); | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | warn $response->content if $response; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 0 | return; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | my $json = $response->content; | |||||||||||||||||||||||||||
| 109 | 1 | my $response_object = Nexmo::SMS::Response->new( json => $json ); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | if ( $response_object->is_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | $self->errstr( $response_object->errstr ); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 1 | return $response_object; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 2 | ▶ | sub check_needed_params { | ||||||||||||||||||||||||||
|
Subroutine
check_needed_params: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 2 | my ($class,%params) = @_; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 2 | my @params_not_ok; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 2 | for my $attr ( keys %attrs ) { | |||||||||||||||||||||||||||
| 125 | 24 | ▶ | if ( $attrs{$attr} eq 'required' and !$params{$attr} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$attrs{$attr} eq "required" and not $params{$attr}
MC/DC100%2/2
$attrs{$attr} eq "required" and not $params{$attr}
$attrs{$attr} eq "required"
not $params{$attr}
Truth table100%3/3
A and not(B)
A= $attrs{$attr} eq "required"B= not $params{$attr}
| |||||||||||||||||||||||||||||
| 126 | 2 | push @params_not_ok, $attr; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 2 | return join ", ", @params_not_ok; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 9 | 1; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||