File Coverage

blib/lib/Nexmo/SMS/Response/Message.pm
Criterion Covered Total %
statement 24 24 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 33 34 97.0


line stmt bran cond sub pod time code
1             package Nexmo::SMS::Response::Message;
2              
3 8     8   47 use strict;
  8         15  
  8         269  
4 8     8   46 use warnings;
  8         14  
  8         627  
5              
6             # ABSTRACT: Module that represents a single message in the response from Nexmo SMS API!
7              
8              
9             our $VERSION = '0.02';
10              
11             # create getter/setter
12             my @attrs = qw(
13             error_text status message_id client_ref remaining_balance
14             message_price status_text status_desc
15             );
16              
17             for my $attr ( @attrs ) {
18 8     8   45 no strict 'refs';
  8         17  
  8         3384  
19             *{ __PACKAGE__ . '::' . $attr } = sub {
20 92     92   4383 my ($self,$value) = @_;
21            
22 92         206 my $key = '__' . $attr . '__';
23 92 100       353 $self->{$key} = $value if @_ == 2;
24 92         436 return $self->{$key};
25             };
26             }
27              
28             my %status_map = (
29             0 => [ 'Success', 'The message was successfully accepted for delivery by nexmo' ],
30             1 => [ 'Throttled', 'You have exceeded the submission capacity allowed on this account, please back-off and retry' ],
31             2 => [ 'Missing params', 'Your request is incomplete and missing some mandatory parameters' ],
32             3 => [ 'Invalid params', 'Thevalue of one or more parameters is invalid' ],
33             4 => [ 'Invalid credentials', 'The username / password you supplied is either invalid or disabled' ],
34             5 => [ 'Internal error', 'An error has occurred in the nexmo platform whilst processing this message' ],
35             6 => [ 'Invalid message', 'The Nexmo platform was unable to process this message, for example, an un-recognized number prefix' ],
36             7 => [ 'Number barred', 'The number you are trying to submit to is blacklisted and may not receive messages' ],
37             8 => [ 'Partner account barred', 'The username you supplied is for an account that has been barred from submitting messages' ],
38             9 => [ 'Partner quota exceeded', 'Your pre-pay account does not have sufficient credit to process this message' ],
39             10 => [ 'Too many existing binds', 'The number of simultaneous connections to the platform exceeds the capabilities of your account' ],
40             11 => [ 'Account not enabled for REST', 'This account is not provisioned for REST submission, you should use SMPP instead' ],
41             12 => [ 'Message too long', 'Applies to Binary submissions, where the length of the UDF and the message body combined exceed 140 octets' ],
42             );
43              
44              
45             sub new {
46 6     6 1 39 my ($class,%param) = @_;
47            
48 6         26 my $self = bless {}, $class;
49            
50 6         20 for my $attr ( @attrs ) {
51 48         96 (my $key = $attr) =~ tr/_/-/;
52 48         196 $self->$attr( $param{$key} );
53             }
54            
55 6         22 my $status = $param{status};
56            
57 6 50       180 if ( exists $status_map{$status} ) {
58 6         18 my $info = $status_map{$status};
59 6         33 $self->status_text( $info->[0] );
60 6         32 $self->status_desc( $info->[1] );
61             }
62            
63 6         58 return $self;
64             }
65              
66             1;
67              
68              
69             __END__