| 1 | package SMS::MessageBird::API::SMS; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use parent 'SMS::MessageBird::API'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | SMS::MessageBird::API::SMS - Sub-module for the SMS::MessageBird distribution. | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | This is a sub-module which is part of the SMS::MessageBird distribution. | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | While this module can be used directly, it's designed to be used via | ||||||||||||||||||||
| 18 | L<SMS::MessageBird> | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =head1 DESCRIPTION | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | This module provides the interface to the SMS sending methods of the MessageBird | ||||||||||||||||||||
| 24 | JSON API. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | The methods implmented acceept the paramteres as named in the MessageBird API | ||||||||||||||||||||
| 27 | documentation which can be found at the L<MessageBird Developer Documentation|https://www.messagebird.com/en-gb/developers>. | ||||||||||||||||||||
| 28 | If you're using this distribution you should be familiar with the API | ||||||||||||||||||||
| 29 | documentation. | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | =head2 Response Data | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | Every method returns a standardised hashref containin the following keys: | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =over | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | =item ok | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | Value of 0 or 1. Indicates if the request was completed successfully or not. | ||||||||||||||||||||
| 40 | This value is based on LWP::UserAgent's is_success() method. | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =item code | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | This is the HTTP code returned by the API. In the event of ok => 0 - it's | ||||||||||||||||||||
| 45 | possible that the request was a 401 etc. So this is provided for sanity | ||||||||||||||||||||
| 46 | checking. | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | =item content | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | This is a Perl hashref data structure decoded from the API's response JSON | ||||||||||||||||||||
| 51 | as-is. | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | Please see the L<MessageBird Developer Documentation|https://www.messagebird.com/en-gb/developers> | ||||||||||||||||||||
| 54 | for more information on the expected structure. | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =back | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =head1 METHODS | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =head2 send | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | In: %params - Hash of params accepted by the MessageBird API. | ||||||||||||||||||||
| 65 | Out: $response - Hashref of response data. See "Response Data" above. | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | This method implements the POST /messages route of the API. | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | Accepted parameters are listed in the MessageBird API documentation. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | Require parameters are as follows: | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =over | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =item originator | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | The originator parameter is required but can be omitted if set when | ||||||||||||||||||||
| 78 | instantiating the SMS::MessageBird module. | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =item recipients | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | The recipients parameter is required and can be either a scalar containing a | ||||||||||||||||||||
| 83 | single MSISDN (mobile number) or an arrayref containing many recipients. | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =item body | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | The body parameter is required. Scalar containing the text of the message. | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =back | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | All other parameters are optional. | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | Please see the L<MessageBird API Documentation|https://www.messagebird.com/en-gb/developers> | ||||||||||||||||||||
| 94 | for more information. | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | sub send { | ||||||||||||||||||||
| 99 | 0 | ▶ | my ($self, %params) = @_; | ||||||||||||||||||
|
Subroutine
send: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | $params{originator} //= $self->{originator}; | ||||||||||||||||||
|
Condition0%0/3
$params{"originator"} //= $self->{"originator"}
MC/DC0%0/2
$params{"originator"} //= $self->{"originator"}
$params{"originator"}
$self->{"originator"}
Truth table0%0/3
A //= B
A= $params{"originator"}B= $self->{"originator"}
| |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | return $self->_api_request( | |||||||||||||||||||
| 104 | post => '/messages', | ||||||||||||||||||||
| 105 | \%params | ||||||||||||||||||||
| 106 | ); | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =head2 receive | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | In: $mesasge_id - Optional ID of the message to recieve. | ||||||||||||||||||||
| 113 | Out: $response - Hashref of response data. See "Response Data" above. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | This method implements the GET /messages/{message_id} route of the API. | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | If supplied with a $message_id, that one message will be returned. If omitted, | ||||||||||||||||||||
| 118 | a complete list of messages will be returned. | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | Please see the L<MessageBird API Documentation|https://www.messagebird.com/en-gb/developers> | ||||||||||||||||||||
| 121 | for more information. | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =cut | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | sub receive { | ||||||||||||||||||||
| 126 | 0 | ▶ | my ($self, $message_id) = @_; | ||||||||||||||||||
|
Subroutine
receive: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | ▶ | my $route = ($message_id) ? "/messages/$message_id" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 129 | : '/messages'; | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | 0 | return $self->_api_request( get => $route ); | |||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =head2 get | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | Synonym for the L<receive()|/"receive"> method. | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | sub get { | ||||||||||||||||||||
| 142 | 0 | ▶ | my ($self, $message_id) = @_; | ||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 143 | 0 | return $self->receive($message_id); | |||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =head2 remove | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | In: $message_id - The message_id to remove. | ||||||||||||||||||||
| 150 | Out: $response - Hashref of response data. See "Response Data" above. | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | This method implements the DELETE /messages/{message_id} route of the API. | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | Deletes the SMS with identifier $message_id. | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | Please see the L<MessageBird API Documentation|https://www.messagebird.com/en-gb/developers> | ||||||||||||||||||||
| 157 | for more information. | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | sub remove { | ||||||||||||||||||||
| 162 | 0 | ▶ | my ($self, $message_id) = @_; | ||||||||||||||||||
|
Subroutine
remove: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | 0 | ▶ | return $self->_no_param_supplied('message ID') if !$message_id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | 0 | return $self->_api_request( delete => "/messages/$message_id" ); | |||||||||||||||||||
| 167 | } | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | =head2 del | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | Synonym for the L<remove()|/"remove"> method. | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | sub del { | ||||||||||||||||||||
| 177 | 0 | ▶ | my ($self, $message_id) = @_; | ||||||||||||||||||
|
Subroutine
del: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | 0 | return $self->remove($message_id); | |||||||||||||||||||
| 180 | } | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | =head1 AUTHOR | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | James Ronan, C<< <james at ronanweb.co.uk> >> | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | =head1 BUGS | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | Please report any bugs or feature requests to C<bug-sms-messagebird at rt.cpan.org>, | ||||||||||||||||||||
| 190 | or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SMS-MessageBird>. | ||||||||||||||||||||
| 191 | I will be notified, and then you'll automatically be notified of progress on your | ||||||||||||||||||||
| 192 | bug as I make changes. | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | Alternatively you can raise an issue on the source code which is available on | ||||||||||||||||||||
| 195 | L<GitHub|https://github.com/jamesronan/SMS-MessageBird>. | ||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | Copyright 2016 James Ronan. | ||||||||||||||||||||
| 200 | |||||||||||||||||||||
| 201 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 202 | the same terms as Perl itself. | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | 2 | 1; | |||||||||||||||||||
| 207 | |||||||||||||||||||||