| 1 | package SMS::Send::BulkSMS; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | $SMS::Send::BulkSMS::VERSION = '0.02'; | |||||||||
| 7 | |||||||||||
| 8 | # ABSTRACT: SMS::Send driver for the International BulkSMS service | ||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use HTTP::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use base 'SMS::Send::Driver'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 16 | 0 | my ($class, %args) = @_; | |||||||||
| 17 | 0 | my $self = \%args; | |||||||||
| 18 | |||||||||||
| 19 | $self->{$_} | ||||||||||
| 20 | or croak "$_ missing" | ||||||||||
| 21 | 0 | ▶ | for qw( _login _password ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | |||||||||||
| 23 | 0 | $self->{_http} = HTTP::Tiny->new(); | |||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | $self->{_verbose} = 0 unless exists $self->{_verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | 0 | return bless $self, $class; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | sub send_sms { | ||||||||
|
Subroutine
send_sms: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 31 | 0 | my ($self, %args) = @_; | |||||||||
| 32 | |||||||||||
| 33 | # remove leading + | ||||||||||
| 34 | 0 | ( my $recipient = $args{to} ) =~ s/^\+//; | |||||||||
| 35 | |||||||||||
| 36 | 0 | my $message = $args{text}; | |||||||||
| 37 | |||||||||||
| 38 | my $response = $self->{_http}->post_form( | ||||||||||
| 39 | 'https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0', | ||||||||||
| 40 | { | ||||||||||
| 41 | username => $self->{_login}, | ||||||||||
| 42 | password => $self->{_password}, | ||||||||||
| 43 | 0 | msisdn => $recipient, | |||||||||
| 44 | message => $message, | ||||||||||
| 45 | }, | ||||||||||
| 46 | ); | ||||||||||
| 47 | |||||||||||
| 48 | # Fatal error | ||||||||||
| 49 | croak $response->{content} | ||||||||||
| 50 | 0 | ▶ | unless $response->{success}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 0 | my ($result_code, $result_string, $batch_id) = split(/\|/, $response->{content}); | |||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | if ($result_code eq '0') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | ▶ | warn "send_sms succeeded: $batch_id" if $args{_verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | return 1; | |||||||||
| 57 | } | ||||||||||
| 58 | else { | ||||||||||
| 59 | 0 | ▶ | warn "send_sms failed: $result_code, $result_string" if $args{_verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | return 0; | |||||||||
| 61 | } | ||||||||||
| 62 | 0 | print "\n"; | |||||||||
| 63 | |||||||||||
| 64 | 0 | croak "Can't parse response from BulkSMS API"; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 1 | 1; | |||||||||
| 68 | |||||||||||
| 69 | __END__ | ||||||||||