From e2fa569cfa89b77e0470d1e37c0f7cf48910da15 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). --- C4/SMS.pm | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/C4/SMS.pm b/C4/SMS.pm index 24580d6..6785e92 100644 --- a/C4/SMS.pm +++ b/C4/SMS.pm @@ -36,6 +36,7 @@ use strict; use warnings; use C4::Context; +use File::Spec; use vars qw( $VERSION ); @@ -74,14 +75,29 @@ 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 $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; + } + # Create a sender - my $sender = SMS::Send->new( $driver, - _login => C4::Context->preference('SMSSendUsername'), - _password => C4::Context->preference('SMSSendPassword'), - ); - + my $sender = SMS::Send->new( + $driver, + _login => C4::Context->preference('SMSSendUsername'), + _password => C4::Context->preference('SMSSendPassword'), + %args, + ); + # Send a message my $sent = $sender->send_sms( to => $params->{'destination'}, text => $params->{'message'}, -- 1.9.1