Bug 12858 [QA Followup] - Don't call webservice if we have no data
[koha.git] / C4 / SMS.pm
blob34cce27f61ca4e676663cac8bb1ddfffc8c4deaf
1 package C4::SMS;
3 # Copyright 2007 Liblime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 =head1 NAME
22 C4::SMS - send SMS messages
24 =head1 SYNOPSIS
26 my $success = C4::SMS->send_sms( message => 'This is my text message',
27 destination => '212-555-1212' );
29 =head1 DESCRIPTION
33 =cut
35 use strict;
36 use warnings;
38 use C4::Context;
40 use vars qw( $VERSION );
42 BEGIN {
43 $VERSION = 3.07.00.049;
46 =head1 METHODS
48 =cut
50 # The previous implmentation used username and password.
51 # our $user = C4::Context->config('smsuser');
52 # our $pwd = C4::Context->config('smspass');
54 =head2 send_sms
56 =cut
58 sub send_sms {
59 my $self = shift;
60 my $params= shift;
62 foreach my $required_parameter ( qw( message destination ) ) {
63 # Should I warn in some way?
64 return unless defined $params->{ $required_parameter };
67 eval { require SMS::Send; };
68 if ( $@ ) {
69 # we apparently don't have SMS::Send. Return a failure.
70 return;
73 # This allows the user to override the driver. See SMS::Send::Test
74 my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver();
75 return unless $driver;
77 # warn "using driver: $driver to send message to $params->{'destination'}";
79 my ($sent, $sender);
80 eval {
81 # Create a sender
82 $sender = SMS::Send->new( $driver,
83 _login => C4::Context->preference('SMSSendUsername'),
84 _password => C4::Context->preference('SMSSendPassword'),
87 # Send a message
88 $sent = $sender->send_sms( to => $params->{'destination'},
89 text => $params->{'message'},
92 #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.
94 if ($@) {
95 warn $@;
96 return;
98 # warn 'failure' unless $sent;
99 return $sent;
102 =head2 driver
104 =cut
106 sub driver {
107 my $self = shift;
109 # return 'US::SprintPCS';
110 return C4::Context->preference('SMSSendDriver');
116 __END__