From d6d16e90dab280188e9a1a3b1466a5e6a9139fae Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Mon, 6 Oct 2014 15:04:12 +0200 Subject: [PATCH] Bug 13029: Allow to pass additional parameters to SMS::Send drivers C4::SMS::send_sms now reads a YAML file and pass all parameters in the file to SMS::Send::new. The config file is read in /etc/sms/driver/.yaml. For instance, if the driver used is SMS::Send::UK::Kapow, the config file has to be in /etc/sms/driver/UK/Kapow.yaml A underscore character is prepended to all parameter names so they are treated as driver-specific options (leading underscore must not appear in config file). Signed-off-by: Magnus Enger Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- C4/SMS.pm | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/C4/SMS.pm b/C4/SMS.pm index 41407e3bc9..d011f5f52f 100644 --- a/C4/SMS.pm +++ b/C4/SMS.pm @@ -36,6 +36,7 @@ use strict; use warnings; use C4::Context; +use File::Spec; @@ -70,21 +71,39 @@ sub send_sms { my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver(); return unless $driver; - # warn "using driver: $driver to send message to $params->{'destination'}"; my ($sent, $sender); + + my $subpath = $driver; + $subpath =~ s|::|/|; + + my $conf_file = File::Spec->catfile( + C4::Context->config('installdir'), + 'etc', 'sms', 'driver', $subpath + ) . q{.yaml}; + my %args; + if ( -f $conf_file ) { + require YAML; + my $conf = YAML::LoadFile( $conf_file ); + %args = map { q{_} . $_ => $conf->{$_} } keys %$conf; + } + eval { # Create a sender - $sender = SMS::Send->new( $driver, - _login => C4::Context->preference('SMSSendUsername'), - _password => C4::Context->preference('SMSSendPassword'), - ); - + $sender = SMS::Send->new( + $driver, + _login => C4::Context->preference('SMSSendUsername'), + _password => C4::Context->preference('SMSSendPassword'), + %args, + ); + # Send a message - $sent = $sender->send_sms( to => $params->{'destination'}, - text => $params->{'message'}, - ); + $sent = $sender->send_sms( + to => $params->{destination}, + text => $params->{message}, + ); }; + #We might die because SMS::Send $driver is not defined or the sms-number has a bad format #Catch those errors and fail the sms-sending gracefully. if ($@) { -- 2.39.5