| 1 | package SMS::Send::Fr::OVH; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use LWP::Simple qw(get); | ||
| 6 | use JSON qw(from_json); | ||
| 7 | use Carp; | ||
| 8 | |||
| 9 | our $VERSION = '0.01'; | ||
| 10 | use base 'SMS::Send::Driver'; | ||
| 11 | |||
| 12 | use constant URL => 'https://www.ovh.com/cgi-bin/sms/http2sms.cgi?&account=%s&login=%s&password=%s&from=%s&to=%s&message="%s"&contentType=application/json'; | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | SMS::Send::Fr::OVH - Perl driver for SMS::Send library. | ||
| 17 | |||
| 18 | =head1 SYNOPSIS | ||
| 19 | |||
| 20 | use SMS::Send::Fr::OVH; | ||
| 21 | |||
| 22 | # Create a sender | ||
| 23 | my $sender = SMS::Send->new('Fr::OVH', | ||
| 24 | _account => 'sms-ab1234-1', | ||
| 25 | _login => 'sms_user_name', | ||
| 26 | _password => 'pass', | ||
| 27 | _from => 'ovh_sender_name' | ||
| 28 | _transform_number => [ | ||
| 29 | { match_re => '^+33', replace_re => '0033' }, | ||
| 30 | ] | ||
| 31 | ); | ||
| 32 | |||
| 33 | # Send a message | ||
| 34 | my $sent = $sender->send_sms( | ||
| 35 | text => 'This is a test message', | ||
| 36 | to => '003361*****20' | ||
| 37 | ); | ||
| 38 | |||
| 39 | =head1 DESCRIPTION | ||
| 40 | |||
| 41 | SMS::Send::Fr::OVH - SMS::Send driver to send messages via OVH SMS API. | ||
| 42 | |||
| 43 | =head1 METHODS | ||
| 44 | |||
| 45 | =over 4 | ||
| 46 | |||
| 47 | =item new | ||
| 48 | |||
| 49 | Constructor. | ||
| 50 | |||
| 51 | =cut | ||
| 52 | |||
| 53 | sub new { | ||
| 54 | my ($class, %args) = @_; | ||
| 55 | |||
| 56 | my $self = bless { %args }, $class; | ||
| 57 | |||
| 58 | return $self; | ||
| 59 | } | ||
| 60 | |||
| 61 | =item send_sms | ||
| 62 | |||
| 63 | Send the message - see SMS::Send for details. | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | sub send_sms { | ||
| 68 | my ($self, %args) = @_; | ||
| 69 | |||
| 70 | $self->{text} = "$args{text}"; | ||
| 71 | $self->{to} = $self->transform_number($args{to}); | ||
| 72 | |||
| 73 | my @arguments; | ||
| 74 | foreach my $arg (qw(_account _login _password _from to text)) { | ||
| 75 | push @arguments, $self->{ $arg }; | ||
| 76 | } | ||
| 77 | |||
| 78 | #my $url = sprintf(URL, @arguments); | ||
| 79 | #my $response = from_json(get($url)); | ||
| 80 | |||
| 81 | #unless ($response->{status} == 100) { | ||
| 82 | # Carp::croak($response->{message}); | ||
| 83 | # return 0; | ||
| 84 | #} | ||
| 85 | |||
| 86 | return 1; | ||
| 87 | } | ||
| 88 | |||
| 89 | =item transform_number | ||
| 90 | |||
| 91 | Transform a phone number according to the regular expressions | ||
| 92 | provided to the constructor. | ||
| 93 | |||
| 94 | =cut | ||
| 95 | |||
| 96 | sub transform_number { | ||
| 97 | my ($self, $number) = @_; | ||
| 98 | |||
| 99 | foreach my $rule (@{ $self->{_transform_number} }) { | ||
| 100 | my $match = $rule->{match_re}; | ||
| 101 | my $replace = $rule->{replace_re}; | ||
| 102 | if ($number =~ /$match/) { | ||
| 103 | $number =~ s/$match/\Q$replace/g; | ||
| 104 | return $number; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | return $number; | ||
| 109 | } | ||
| 110 | |||
| 111 | =back | ||
| 112 | |||
| 113 | =head1 AUTHOR | ||
| 114 | |||
| 115 | Alex Arnaud, E<lt>gg.alexarnaud@gmail.comE<gt> |