File Coverage

blib/lib/SMS/MessageBird/API/SMS.pm
Criterion Covered Total %
statement 9 25 36.0
branch 0 6 0.0
condition n/a
subroutine 3 9 33.3
pod 6 6 100.0
total 18 46 39.1


line stmt bran cond sub pod time code
1             package SMS::MessageBird::API::SMS;
2              
3 2     2   14 use strict;
  2         8  
  2         61  
4 2     2   14 use warnings;
  2         4  
  2         64  
5              
6 2     2   10 use parent 'SMS::MessageBird::API';
  2         5  
  2         11  
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
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.
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
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
94             for more information.
95              
96             =cut
97              
98             sub send {
99 0     0 1   my ($self, %params) = @_;
100              
101 0 0         if (!exists $params{originator}) {
102 0           $params{originator} = $self->{originator};
103             }
104              
105 0           return $self->_api_request(
106             post => '/messages',
107             \%params
108             );
109             }
110              
111              
112             =head2 receive
113              
114             In: $mesasge_id - Optional ID of the message to recieve.
115             Out: $response - Hashref of response data. See "Response Data" above.
116              
117             This method implements the GET /messages/{message_id} route of the API.
118              
119             If supplied with a $message_id, that one message will be returned. If omitted,
120             a complete list of messages will be returned.
121              
122             Please see the L
123             for more information.
124              
125             =cut
126              
127             sub receive {
128 0     0 1   my ($self, $message_id) = @_;
129              
130 0 0         my $route = ($message_id) ? "/messages/$message_id"
131             : '/messages';
132              
133 0           return $self->_api_request( get => $route );
134             }
135              
136              
137             =head2 get
138              
139             Synonym for the L method.
140              
141             =cut
142              
143             sub get {
144 0     0 1   my ($self, $message_id) = @_;
145 0           return $self->receive($message_id);
146             }
147              
148              
149             =head2 search
150              
151             In: %filters - Hashref of filter key / data pairs
152             Out: $response - Hashref of reponse data. See "Response Data" above.
153              
154             Search sent messages by criterion rather than getting a specifc message by id.
155              
156             Please see the L
157             for a complete list of filters.
158              
159             B: MessageBird's API seems to ignore the documented "searchterm"
160             paramter - which isn't an option via their portal, so perhaps doesn't work. It
161             will, however, allow you to filter by status, recipient and originator. So it's
162             of some use. Limit has a minimum of 10.
163              
164             =cut
165              
166             sub search {
167 0     0 1   my ($self, %filters) = @_;
168              
169 0           return $self->_api_request( get => '/messages', \%filters );
170             }
171              
172              
173             =head2 remove
174              
175             In: $message_id - The message_id to remove.
176             Out: $response - Hashref of response data. See "Response Data" above.
177              
178             This method implements the DELETE /messages/{message_id} route of the API.
179              
180             Deletes the SMS with identifier $message_id.
181              
182             Please see the L
183             for more information.
184              
185             =cut
186              
187             sub remove {
188 0     0 1   my ($self, $message_id) = @_;
189              
190 0 0         return $self->_no_param_supplied('message ID') if !$message_id;
191              
192 0           return $self->_api_request( delete => "/messages/$message_id" );
193             }
194              
195              
196             =head2 del
197              
198             Synonym for the L method.
199              
200             =cut
201              
202             sub del {
203 0     0 1   my ($self, $message_id) = @_;
204              
205 0           return $self->remove($message_id);
206             }
207              
208              
209             =head1 AUTHOR
210              
211             James Ronan, C<< >>
212              
213             =head1 BUGS
214              
215             Please report any bugs or feature requests to C,
216             or through the web interface at L.
217             I will be notified, and then you'll automatically be notified of progress on your
218             bug as I make changes.
219              
220             Alternatively you can raise an issue on the source code which is available on
221             L.
222              
223             =head1 LICENSE AND COPYRIGHT
224              
225             Copyright 2016 James Ronan.
226              
227             This library is free software; you can redistribute it and/or modify it under
228             the same terms as Perl itself.
229              
230             =cut
231              
232             1;
233