Bug 2176 (3/5): adding methods to manage message_queue, new advance_notices.pl, new...
[koha.git] / C4 / SMS.pm
1 package C4::SMS;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 =head1 NAME
19
20 C4::SMS - send SMS messages
21
22 =head1 SYNOPSIS
23
24 my $success = C4::SMS->send_sms( message     => 'This is my text message',
25                                  destination => '212-555-1212' );
26
27 =head1 DESCRIPTION
28
29
30
31 =cut
32
33 use strict;
34 use warnings;
35
36 use C4::Context;
37 use SMS::Send;
38
39 use vars qw( $VERSION );
40
41 BEGIN {
42     $VERSION = 0.03;
43 }
44
45 =head1 METHODS
46
47 =cut
48
49 # The previous implmentation used username and password.
50 # our $user = C4::Context->config('smsuser');
51 # our $pwd  = C4::Context->config('smspass');
52
53 =head2 send_sms
54
55 =over4
56
57 =back
58
59 =cut
60
61 sub send_sms {
62     my $self = shift;
63     my $params= shift;
64
65     foreach my $required_parameter ( qw( message destination ) ) {
66         # Should I warn in some way?
67         return unless defined $params->{ $required_parameter };
68     }
69
70     # This allows the user to override the driver. See SMS::Send::Test
71     my $driver = exists $params->{'driver'} ? $params->{'driver'} : $self->driver();
72     return unless $driver;
73
74     # warn "using driver: $driver to send message to $params->{'destination'}";
75     
76     # Create a sender
77     my $sender = SMS::Send->new( $driver,
78                                  _login    => C4::Context->preference('SMSSendUsername'),
79                                  _password => C4::Context->preference('SMSSendPassword'),
80                             );
81     
82     # Send a message
83     my $sent = $sender->send_sms( to   => $params->{'destination'},
84                                   text => $params->{'message'},
85                              );
86     # warn 'failure' unless $sent;
87     return $sent;
88 }
89
90 =head2 driver
91
92 =over 4
93
94 =back
95
96 =cut
97
98 sub driver {
99     my $self = shift;
100
101     # return 'US::SprintPCS';
102     return C4::Context->preference('SMSSendDriver');
103
104 }
105
106 1;
107
108 __END__
109