File Coverage

blib/lib/SMS/MessageBird/API/SMS.pm
Criterion Covered Total %
statement 9 22 40.9
branch 0 4 0.0
condition 0 3 0.0
subroutine 3 8 37.5
pod 5 5 100.0
total 17 42 40.4


line stmt bran cond sub pod time code
1             package SMS::MessageBird::API::SMS;
2              
3 2     2   7 use strict;
  2         2  
  2         66  
4 2     2   8 use warnings;
  2         2  
  2         85  
5              
6 2     2   726 use parent 'SMS::MessageBird::API';
  2         418  
  2         7  
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       $params{originator} //= $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
121             for more information.
122              
123             =cut
124              
125             sub receive {
126 0     0 1   my ($self, $message_id) = @_;
127              
128 0 0         my $route = ($message_id) ? "/messages/$message_id"
129             : '/messages';
130              
131 0           return $self->_api_request( get => $route );
132             }
133              
134              
135             =head2 get
136              
137             Synonym for the L method.
138              
139             =cut
140              
141             sub get {
142 0     0 1   my ($self, $message_id) = @_;
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
157             for more information.
158              
159             =cut
160              
161             sub remove {
162 0     0 1   my ($self, $message_id) = @_;
163              
164 0 0         return $self->_no_param_supplied('message ID') if !$message_id;
165              
166 0           return $self->_api_request( delete => "/messages/$message_id" );
167             }
168              
169              
170             =head2 del
171              
172             Synonym for the L method.
173              
174             =cut
175              
176             sub del {
177 0     0 1   my ($self, $message_id) = @_;
178              
179 0           return $self->remove($message_id);
180             }
181              
182              
183             =head1 AUTHOR
184              
185             James Ronan, C<< >>
186              
187             =head1 BUGS
188              
189             Please report any bugs or feature requests to C,
190             or through the web interface at L.
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.
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             1;
207