File Coverage

blib/lib/SMS/Send/MessageBird.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1             package SMS::Send::MessageBird;
2              
3 1     1   12758 use 5.006;
  1         3  
4 1     1   3 use strict;
  1         1  
  1         18  
5 1     1   4 use warnings;
  1         3  
  1         21  
6              
7 1     1   445 use parent 'SMS::Send::Driver';
  1         214  
  1         4  
8              
9             use SMS::MessageBird;
10              
11             =head1 NAME
12              
13             SMS::Send::MessageBird - SMS::Send driver for the SMS::MessageBird distribution.
14              
15             =head1 VERSION
16              
17             Version 0.02
18              
19             =cut
20              
21             our $VERSION = '0.02';
22              
23              
24             =head1 SYNOPSIS
25              
26             Enables sending of SMS messages with the SMS::Send distribution using
27             MessageBird's API as the providing gateway via the SMS::MessageBird
28             distribution.
29              
30             use SMS::Send;
31             use SMS::Send::MessageBird;
32              
33             my $messagebird = SMS::Send->new(
34             'SMS::Send::MessageBird',
35             _api_key => 'test_ABCDEF123456',
36             _originator => 'James Ronan',
37             );
38             $messagebird->send_sms(
39             text => 'Hi, How are you?',
40             to => '+441234567890',
41             );
42              
43              
44             =head1 DESCRIPTION
45              
46             SMS::Send Driver for the SMS::MessageBird distribution - provides a simple
47             interface for SMS sending via MessageBird.
48              
49             This module isn't designed to be used on its own. Please see L
50             for more information.
51              
52              
53             =head1 METHODS
54              
55              
56             =head2 new (constructor)
57              
58             =cut
59              
60             sub new {
61             my ($class, %params) = @_;
62              
63             my $self = bless {
64             api_key => $params{_api_key},
65             }, $class || 'SMS::Send::MessageBird';
66              
67             $self->{messagebird} = SMS::MessageBird->new(
68             api_key => $self->{api_key},
69             );
70              
71             # For the optional accepted constructor params for SMS::MessageBird - if
72             # we've been passed them, give them to SMS::MessageBird.
73             for my $messagebird_param (qw( originator api_url )) {
74             if (exists $params{ "_$messagebird_param" }) {
75             $self->{messagebird}->$messagebird_param(
76             $params{ "_$messagebird_param" }
77             );
78             }
79             }
80              
81             return $self;
82             }
83              
84              
85             =head2 send_sms
86              
87             Sends an SMS via MessageBird.
88              
89             As there are a whole host of optional parameters that can be passed to the
90             MessageBird API, along with the required parameters, an additional '_parameters'
91             key can be passed containing a hash of those options.
92              
93             =over
94              
95             =item to
96              
97             Required. This is mapped to SMS::MessageBird's recipients parameter. Due to the
98             way SMS::Send works, it will accept only a single recipient.
99              
100             =item text
101              
102             Required. This is mapped to SMS::MessageBird's body parameter. It should contain
103             the content of the message you wish to send.
104              
105             =item _parameters
106              
107             Optional. This should be a hashref of the extra parameters you wish to pass to
108             SMS::MessageBird.
109              
110             The one exception to the "optional" status is be the originator parameter, If
111             you don't pass _originator to the SMS::Send constructor then you must provide
112             it via the _parameters hashref.
113              
114             =back
115              
116             =cut
117              
118             sub send_sms {
119             my ($self, %params) = @_;
120              
121             my %messagebird_params = (
122             recipients => $params{to},
123             body => $params{text},
124             );
125              
126             if (exists $params{_parameters}) {
127             %messagebird_params = (
128             %messagebird_params,
129             %{ $params{_parameters} },
130             );
131             }
132              
133             my $response = $self->{messagebird}->sms->send(%messagebird_params);
134              
135             return $response->{ok};
136             }
137              
138              
139             =head1 AUTHOR
140              
141             James Ronan, C<< >>
142              
143             =head1 BUGS
144              
145             Please report any bugs or feature requests to C,
146             or through the web interface at L.
147             I will be notified, and then you'll automatically be notified of progress on
148             your bug as I make changes.
149              
150             Alternatively you can raise an issue on the source code which is available on
151             L.
152              
153              
154             =head1 LICENSE AND COPYRIGHT
155              
156             Copyright 2016 James Ronan.
157              
158             This library is free software; you can redistribute it and/or modify it under
159             the same terms as Perl itself.
160              
161             =cut
162              
163             1; # End of SMS::Send::MessageBird
164