Bug 16011: $VERSION - Remove the $VERSION init
[koha.git] / C4 / SMS.pm
blob684b2d676d14f8b5cf3da4614dce07e237c29d20
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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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( );
42 BEGIN {
45 =head1 METHODS
47 =cut
49 # The previous implmentation used username and password.
50 # our $user = C4::Context->config('smsuser');
51 # our $pwd = C4::Context->config('smspass');
53 =head2 send_sms
55 =cut
57 sub send_sms {
58 my $self = shift;
59 my $params= shift;
61 foreach my $required_parameter ( qw( message destination ) ) {
62 # Should I warn in some way?
63 return unless defined $params->{ $required_parameter };
66 eval { require SMS::Send; };
67 if ( $@ ) {
68 # we apparently don't have SMS::Send. Return a failure.
69 return;
72 # This allows the user to override the driver. See SMS::Send::Test
73 my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver();
74 return unless $driver;
76 # warn "using driver: $driver to send message to $params->{'destination'}";
78 my ($sent, $sender);
79 eval {
80 # Create a sender
81 $sender = SMS::Send->new( $driver,
82 _login => C4::Context->preference('SMSSendUsername'),
83 _password => C4::Context->preference('SMSSendPassword'),
86 # Send a message
87 $sent = $sender->send_sms( to => $params->{'destination'},
88 text => $params->{'message'},
91 #We might die because SMS::Send $driver is not defined or the sms-number has a bad format
92 #Catch those errors and fail the sms-sending gracefully.
93 if ($@) {
94 warn $@;
95 return;
97 # warn 'failure' unless $sent;
98 return $sent;
101 =head2 driver
103 =cut
105 sub driver {
106 my $self = shift;
108 # return 'US::SprintPCS';
109 return C4::Context->preference('SMSSendDriver');
115 __END__