File Coverage

blib/lib/SMS/MessageBird/API/SMS.pm
Criterion Covered Total %
statement 9 23 39.1
branch 0 6 0.0
condition n/a
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   9 use strict;
  2         2  
  2         46  
4 2     2   7 use warnings;
  2         2  
  2         54  
5              
6 2     2   749 use parent 'SMS::MessageBird::API';
  2         439  
  2         8  
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 remove
150              
151             In: $message_id - The message_id to remove.
152             Out: $response - Hashref of response data. See "Response Data" above.
153              
154             This method implements the DELETE /messages/{message_id} route of the API.
155              
156             Deletes the SMS with identifier $message_id.
157              
158             Please see the L
159             for more information.
160              
161             =cut
162              
163             sub remove {
164 0     0 1   my ($self, $message_id) = @_;
165              
166 0 0         return $self->_no_param_supplied('message ID') if !$message_id;
167              
168 0           return $self->_api_request( delete => "/messages/$message_id" );
169             }
170              
171              
172             =head2 del
173              
174             Synonym for the L method.
175              
176             =cut
177              
178             sub del {
179 0     0 1   my ($self, $message_id) = @_;
180              
181 0           return $self->remove($message_id);
182             }
183              
184              
185             =head1 AUTHOR
186              
187             James Ronan, C<< >>
188              
189             =head1 BUGS
190              
191             Please report any bugs or feature requests to C,
192             or through the web interface at L.
193             I will be notified, and then you'll automatically be notified of progress on your
194             bug as I make changes.
195              
196             Alternatively you can raise an issue on the source code which is available on
197             L.
198              
199             =head1 LICENSE AND COPYRIGHT
200              
201             Copyright 2016 James Ronan.
202              
203             This library is free software; you can redistribute it and/or modify it under
204             the same terms as Perl itself.
205              
206             =cut
207              
208             1;
209