| 1 | package SMS::Send::MessageBird; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use 5.006; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 1 | ▶ | use parent 'SMS::Send::Driver'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use SMS::MessageBird; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 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.03 | ||||||||||||
| 18 | |||||||||||||
| 19 | =cut | ||||||||||||
| 20 | |||||||||||||
| 21 | 1 | our $VERSION = '0.03'; | |||||||||||
| 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<SMS::Send> | ||||||||||||
| 50 | for more information. | ||||||||||||
| 51 | |||||||||||||
| 52 | |||||||||||||
| 53 | =head1 METHODS | ||||||||||||
| 54 | |||||||||||||
| 55 | |||||||||||||
| 56 | =head2 new (constructor) | ||||||||||||
| 57 | |||||||||||||
| 58 | =cut | ||||||||||||
| 59 | |||||||||||||
| 60 | sub new { | ||||||||||||
| 61 | 0 | ▶ | my ($class, %params) = @_; | ||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||
| 62 | |||||||||||||
| 63 | my $self = bless { | ||||||||||||
| 64 | api_key => $params{_api_key}, | ||||||||||||
| 65 | 0 | ▶ | }, $class || 'SMS::Send::MessageBird'; | ||||||||||
|
Condition0%0/2
$class || 'SMS::Send::MessageBird'
MC/DC0%0/1
$class || 'SMS::Send::MessageBird'
$class
Truth table0%0/2
A
A= $class
| |||||||||||||
| 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 | ▶ | if (exists $params{ "_$messagebird_param" }) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | my ($self, %params) = @_; | ||||||||||
|
Subroutine
send_sms: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 120 | |||||||||||||
| 121 | my %messagebird_params = ( | ||||||||||||
| 122 | recipients => $params{to}, | ||||||||||||
| 123 | body => $params{text}, | ||||||||||||
| 124 | 0 | ); | |||||||||||
| 125 | |||||||||||||
| 126 | 0 | ▶ | if (exists $params{_parameters}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 127 | %messagebird_params = ( | ||||||||||||
| 128 | %messagebird_params, | ||||||||||||
| 129 | 0 | %{ $params{_parameters} }, | |||||||||||
| 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<< <james at ronanweb.co.uk> >> | ||||||||||||
| 142 | |||||||||||||
| 143 | =head1 BUGS | ||||||||||||
| 144 | |||||||||||||
| 145 | Please report any bugs or feature requests to C<bug-sms-send-messagebird at rt.cpan.org>, | ||||||||||||
| 146 | or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SMS-Send-MessageBird>. | ||||||||||||
| 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<GitHub|https://github.com/jamesronan/SMS-Send-MessageBird>. | ||||||||||||
| 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 | 1; # End of SMS::Send::MessageBird | |||||||||||
| 164 | |||||||||||||