|
Lines 36-41
use strict;
Link Here
|
| 36 |
use warnings; |
36 |
use warnings; |
| 37 |
|
37 |
|
| 38 |
use C4::Context; |
38 |
use C4::Context; |
|
|
39 |
use File::Spec; |
| 39 |
|
40 |
|
| 40 |
use vars qw( $VERSION ); |
41 |
use vars qw( $VERSION ); |
| 41 |
|
42 |
|
|
Lines 74-94
sub send_sms {
Link Here
|
| 74 |
my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver(); |
75 |
my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver(); |
| 75 |
return unless $driver; |
76 |
return unless $driver; |
| 76 |
|
77 |
|
| 77 |
# warn "using driver: $driver to send message to $params->{'destination'}"; |
|
|
| 78 |
|
78 |
|
| 79 |
my ($sent, $sender); |
79 |
my ($sent, $sender); |
|
|
80 |
|
| 81 |
my $subpath = $driver; |
| 82 |
$subpath =~ s|::|/|; |
| 83 |
|
| 84 |
my $conf_file = File::Spec->catfile( |
| 85 |
C4::Context->config('installdir'), |
| 86 |
'etc', 'sms', 'driver', $subpath |
| 87 |
) . q{.yaml}; |
| 88 |
my %args; |
| 89 |
if ( -f $conf_file ) { |
| 90 |
require YAML; |
| 91 |
my $conf = YAML::LoadFile( $conf_file ); |
| 92 |
%args = map { q{_} . $_ => $conf->{$_} } keys %$conf; |
| 93 |
} |
| 94 |
|
| 80 |
eval { |
95 |
eval { |
| 81 |
# Create a sender |
96 |
# Create a sender |
| 82 |
$sender = SMS::Send->new( $driver, |
97 |
$sender = SMS::Send->new( |
| 83 |
_login => C4::Context->preference('SMSSendUsername'), |
98 |
$driver, |
| 84 |
_password => C4::Context->preference('SMSSendPassword'), |
99 |
_login => C4::Context->preference('SMSSendUsername'), |
| 85 |
); |
100 |
_password => C4::Context->preference('SMSSendPassword'), |
| 86 |
|
101 |
%args, |
|
|
102 |
); |
| 103 |
|
| 87 |
# Send a message |
104 |
# Send a message |
| 88 |
$sent = $sender->send_sms( to => $params->{'destination'}, |
105 |
$sent = $sender->send_sms( |
| 89 |
text => $params->{'message'}, |
106 |
to => $params->{destination}, |
| 90 |
); |
107 |
text => $params->{message}, |
|
|
108 |
); |
| 91 |
}; |
109 |
}; |
|
|
110 |
|
| 92 |
#We might die because SMS::Send $driver is not defined or the sms-number has a bad format |
111 |
#We might die because SMS::Send $driver is not defined or the sms-number has a bad format |
| 93 |
#Catch those errors and fail the sms-sending gracefully. |
112 |
#Catch those errors and fail the sms-sending gracefully. |
| 94 |
if ($@) { |
113 |
if ($@) { |
| 95 |
- |
|
|