File Coverage

blib/lib/SMS/Send/MessageBird.pm
Criterion Covered Total %
statement 14 28 50.0
branch 0 4 0.0
condition 0 2 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 21 43 48.8


line stmt bran cond sub pod time code
1             package SMS::Send::MessageBird;
2              
3 1     1   12601 use 5.006;
  1         2  
4 1     1   3 use strict;
  1         1  
  1         19  
5 1     1   3 use warnings;
  1         3  
  1         22  
6              
7 1     1   385 use parent 'SMS::Send::Driver';
  1         210  
  1         4  
8              
9 1     1   981 use SMS::MessageBird;
  1         43716  
  1         180  
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.04
18              
19             =cut
20              
21             our $VERSION = '0.04';
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 0     0 1   my ($class, %params) = @_;
62              
63             my $self = bless {
64             api_key => $params{_api_key},
65 0   0       }, $class || 'SMS::Send::MessageBird';
66              
67             $self->{messagebird} = SMS::MessageBird->new(
68             api_key => $self->{api_key},
69 0           );
70              
71             # For the optional accepted constructor params for SMS::MessageBird - if
72             # we've been passed them, give them to SMS::MessageBird.
73 0           for my $messagebird_param (qw( originator api_url )) {
74 0 0         if (exists $params{ "_$messagebird_param" }) {
75             $self->{messagebird}->$messagebird_param(
76 0           $params{ "_$messagebird_param" }
77             );
78             }
79             }
80              
81 0           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 0     0 1   my ($self, %params) = @_;
120              
121             my %messagebird_params = (
122             recipients => $params{to},
123             body => $params{text},
124 0           );
125              
126 0 0         if (exists $params{_parameters}) {
127             %messagebird_params = (
128             %messagebird_params,
129 0           %{ $params{_parameters} },
  0            
130             );
131             }
132              
133 0           my $response = $self->{messagebird}->sms->send(%messagebird_params);
134              
135 0           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