| 1 | package SMS::SMS77; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use LWP::UserAgent; | ||
| 7 | use Carp; | ||
| 8 | use Data::Dumper; | ||
| 9 | |||
| 10 | our $VERSION = 0.01; | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | SMS::SMS77 - inferface for sms77.de SMS Service | ||
| 15 | |||
| 16 | =head1 VERSION | ||
| 17 | |||
| 18 | Version 0.01 | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | sub new { | ||
| 23 | my $invocant = shift(); | ||
| 24 | my $class = ref($invocant) || $invocant; | ||
| 25 | my $self = { | ||
| 26 | '_lwp' => LWP::UserAgent->new(), | ||
| 27 | 'url' => 'https://gateway.sms77.de/', | ||
| 28 | 'user' => undef, | ||
| 29 | 'password' => undef, | ||
| 30 | 'debug' => 0, | ||
| 31 | 'default_type' => 'standard', | ||
| 32 | 'timeout' => 30, | ||
| 33 | 'proxy' => undef, | ||
| 34 | @_ | ||
| 35 | }; | ||
| 36 | |||
| 37 | $self->{'_lwp'}->agent('SMS::SMS77-perlmodule/'.$VERSION." with libwww-perl"); | ||
| 38 | $self->{'_lwp'}->timeout($self->{'timeout'}); | ||
| 39 | if(defined($self->{'proxy'})) { | ||
| 40 | $self->{'_lwp'}->proxy(@{$self->{'proxy'}}); | ||
| 41 | } | ||
| 42 | |||
| 43 | bless( $self, $class ); | ||
| 44 | |||
| 45 | return ($self); | ||
| 46 | } | ||
| 47 | |||
| 48 | sub timeout { | ||
| 49 | my $self = shift(); | ||
| 50 | |||
| 51 | $self->{'timeout'} = shift; | ||
| 52 | return($self->{'_lwp'}->timeout($self->{'timeout'})); | ||
| 53 | } | ||
| 54 | |||
| 55 | sub proxy { | ||
| 56 | my $self = shift(); | ||
| 57 | |||
| 58 | $self->{'proxy'} = [ @_ ]; | ||
| 59 | return($self->{'_lwp'}->proxy(@{$self->{'proxy'}})); | ||
| 60 | } | ||
| 61 | |||
| 62 | sub send { | ||
| 63 | my $self = shift; | ||
| 64 | my $msg = shift; | ||
| 65 | my %form; | ||
| 66 | my $uri = URI->new($self->{'url'}); | ||
| 67 | my $ret; | ||
| 68 | my $i; | ||
| 69 | |||
| 70 | $form{'u'} = $self->{'user'}; | ||
| 71 | $form{'p'} = $self->{'password'}; | ||
| 72 | |||
| 73 | if(defined($msg->{'type'})) { | ||
| 74 | $form{'type'} = $msg->{'type'}; | ||
| 75 | } else { | ||
| 76 | $form{'type'} = $self->{'default_type'}; | ||
| 77 | } | ||
| 78 | |||
| 79 | foreach $i ('from', 'text', 'status') { | ||
| 80 | if(defined($msg->{$i})) { | ||
| 81 | $form{$i} = $msg->{$i}; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | if($self->{'debug'}) { | ||
| 86 | $form{'debug'} = 1; | ||
| 87 | } | ||
| 88 | if(defined($msg->{'delay'})) { | ||
| 89 | $form{'delay'} = $msg->{'delay'}->epoch(); | ||
| 90 | } | ||
| 91 | $form{'to'} = join("\n", @{$msg->{'to'}}); | ||
| 92 | |||
| 93 | $uri->query_form(\%form); | ||
| 94 | $ret = $self->{'_lwp'}->get($uri); | ||
| 95 | |||
| 96 | if($self->{'debug'}) { | ||
| 97 | print Dumper($ret); | ||
| 98 | } | ||
| 99 | return($ret->content); | ||
| 100 | } | ||
| 101 | |||
| 102 | =head1 see also | ||
| 103 | |||
| 104 | SMS::SMS77::Message | ||
| 105 | |||
| 106 | =head1 AUTHOR | ||
| 107 | |||
| 108 | Markus Benning, C<< <me at w3r3wolf.de> >> | ||
| 109 | |||
| 110 | =head1 COPYRIGHT & LICENSE | ||
| 111 | |||
| 112 | Copyright 2007 Markus Benning, all rights reserved. | ||
| 113 | |||
| 114 | This program is free software; you can redistribute it and/or modify it | ||
| 115 | under the same terms as Perl itself. | ||
| 116 | |||
| 117 | =cut | ||
| 118 | |||
| 119 | 1; # End of SMS::SMS77 | ||
| 120 | |||
| 121 | # vim:ts=2:syntax=perl: | ||
| 122 | # vim600:foldmethod=marker: | ||
| 123 |