Enhance jasminsms (#2560)

* indent
This commit is contained in:
qgarnier 2021-02-01 13:36:57 +01:00 committed by GitHub
parent 2cd6d98aca
commit bbe4fd1c14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 8 deletions

View File

@ -37,7 +37,7 @@ sub new {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit();
}
if (!defined($options{noptions})) {
$options{options}->add_options(arguments => {
'hostname:s@' => { name => 'hostname' },
@ -108,7 +108,11 @@ sub send_sms {
'hex-content=' . $options{message}
];
if (defined($options{from}) && $options{from} ne '') {
push @$get_param, 'from=' . $options{from}
push @$get_param, 'from=' . $options{from};
}
if (defined($options{dlr}) && $options{dlr} eq 'yes') {
push @$get_param, 'dlr=yes', 'dlr-url=' . $options{dlr_url},
'dlr-level=' . $options{dlr_level}, 'dlr-method=' . $options{dlr_method};
}
my $rv = 'Error sending sms';

View File

@ -26,22 +26,28 @@ use strict;
use warnings;
use Encode;
my $map_dlr_level = {
'sms-c' => 1, terminal => 2, both => 3
};
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'from:s' => { name => 'from'},
'to:s' => { name => 'to' },
'message:s' => { name => 'message' },
'coding:s' => { name => 'coding', default => 8 }
'from:s' => { name => 'from'},
'to:s' => { name => 'to' },
'message:s' => { name => 'message' },
'coding:s' => { name => 'coding', default => 8 },
'dlr-url:s' => { name => 'dlr_url' },
'dlr-level:s' => { name => 'dlr_level' },
'dlr-method:s' => { name => 'dlr_method' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
@ -64,6 +70,26 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => 'Please set --message option');
$self->{output}->option_exit();
}
$self->{dlr_enabled} = 'no';
my $dlr_options = { dlr_url => 1, dlr_level => 1, dlr_method => 1 };
foreach (('dlr_url', 'dlr_level', 'dlr_method')) {
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') {
if (/level/ && !defined($map_dlr_level->{ $self->{option_results}->{$_} })) {
$self->{output}->add_option_msg(short_msg => 'Wrong --dlr-level option');
$self->{output}->option_exit();
} elsif (/method/ && $self->{option_results}->{$_} !~ /^GET|POST$/) {
$self->{output}->add_option_msg(short_msg => 'Wrong --dlr-method option');
$self->{output}->option_exit();
}
$self->{dlr_enabled} = 'yes';
delete $dlr_options->{$_};
}
}
if (scalar(keys %$dlr_options) =~ /1|2/) {
$self->{output}->add_option_msg(short_msg => 'Please set ' . join(' ', (map { s/_/-/g; $_ } keys(%$dlr_options))) . ' option(s)');
$self->{output}->option_exit();
}
}
sub encoding_message {
@ -84,7 +110,11 @@ sub run {
to => $self->{option_results}->{to},
from => $self->{option_results}->{from},
message => $self->{option_results}->{message},
coding => $self->{option_results}->{coding}
coding => $self->{option_results}->{coding},
dlr => $self->{dlr_enabled},
dlr_url => $self->{option_results}->{dlr_url},
dlr_level => $self->{dlr_enabled} eq 'yes' ? $map_dlr_level->{ $self->{option_results}->{dlr_level} } : undef,
dlr_method => $self->{option_results}->{dlr_method}
);
if ($response =~ /Error/) {
@ -124,6 +154,18 @@ Specify the message to send.
Sets the Data Coding Scheme bits (Default: 8 (UCS2)).
=item B<--dlr-url>
Sets DLR-URL.
=item B<--dlr-level>
Sets DLR level (can be: 'sms-c', 'terminal', 'both').
=item B<--dlr-method>
Sets DLR method (can be: 'GET', 'POST').
=back
=cut