TT#68300 Fix coding style, indentation and spacing

Change-Id: I380ca0cffc1b163ff7af914dcd069b79891cf634
changes/50/34750/2
Guillem Jover 6 years ago
parent 82af7f6424
commit f69d3e8bc2

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use NGCP::API::Client; use NGCP::API::Client;
@ -13,26 +15,31 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'verbose', 'verbose',
) or usage(); ) or usage();
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 1, pod2usage(
-message => $missing ? "Missing parameters: $missing" : '', -exitval => $missing ? 1 : 0,
); -verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -15,7 +17,7 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'billing_profile_id=i', 'billing_profile_id=i',
'contact_id=i', 'contact_id=i',
@ -25,20 +27,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99, pod2usage(
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -exitval => $missing ? 1 : 0,
-message => $missing ? "Missing parameters: $missing" : '', -verbose => 99,
); -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -48,10 +55,11 @@ sub main {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
my $uri = '/api/customers/'; my $uri = '/api/customers/';
my %data = map { $_ => $opts->{$_} } my %data = map {
qw(billing_profile_id contact_id type status); $_ => $opts->{$_}
} qw(billing_profile_id contact_id type status);
my $res = $client->request('POST', $uri, \%data); my $res = $client->request('POST', $uri, \%data);
print $res->result."\n"; print $res->result . "\n";
return !$res->is_success; return !$res->is_success;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -16,7 +18,7 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'domain=s', 'domain=s',
'reseller_id=i', 'reseller_id=i',
@ -27,6 +29,7 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $arg (@ARGV) { foreach my $arg (@ARGV) {
if ($arg =~ /^[^-]/) { if ($arg =~ /^[^-]/) {
$opts->{domain} = $arg; $opts->{domain} = $arg;
@ -37,16 +40,20 @@ sub check_params {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99, pod2usage(
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -exitval => $missing ? 1 : 0,
-message => $missing ? "Missing parameters: $missing" : '', -verbose => 99,
); -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -61,7 +68,7 @@ sub main {
$data{'_' . $elem . '_reload'} = $opts->{$elem}; $data{'_' . $elem . '_reload'} = $opts->{$elem};
} }
my $res = $client->request('POST', $uri, \%data); my $res = $client->request('POST', $uri, \%data);
print $res->result."\n"; print $res->result . "\n";
return !$res->is_success; return !$res->is_success;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -14,7 +16,7 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'customer_id=i', 'customer_id=i',
'username|u=s', 'username|u=s',
@ -30,20 +32,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99, pod2usage(
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -exitval => $missing ? 1 : 0,
-message => $missing ? "Missing parameters: $missing" : '', -verbose => 99,
); -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -59,8 +66,9 @@ sub main {
} }
my $uri = '/api/subscribers/'; my $uri = '/api/subscribers/';
my %data = map { $_ => $opts->{$_} } my %data = map {
qw(customer_id username password webpassword); $_ => $opts->{$_}
} qw(customer_id username password webpassword);
$data{primary_number} = { map { $_ => $opts->{$_} } qw(cc ac sn) }; $data{primary_number} = { map { $_ => $opts->{$_} } qw(cc ac sn) };
$data{administrative} = $opts->{admin}; $data{administrative} = $opts->{admin};
my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'}; my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'};
@ -70,7 +78,7 @@ sub main {
$data{domain_id} = $tmp->{id}; $data{domain_id} = $tmp->{id};
} }
my $res = $client->request('POST', $uri, \%data); my $res = $client->request('POST', $uri, \%data);
print $res->result."\n"; print $res->result . "\n";
return !$res->is_success; return !$res->is_success;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -24,32 +26,40 @@ my $opts = {
my $config; my $config;
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'verbose', 'verbose',
) or usage(); ) or usage();
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 1, pod2usage(
-message => $missing ? "Missing parameters: $missing" : '', -exitval => $missing ? 1 : 0,
); -verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
sub load_config { sub load_config {
$config = XML::Simple->new()->XMLin($config_file, ForceArray => [ 'credit_warnings' ]) $config = XML::Simple->new()->XMLin(
or die "Cannot load config: $config_file: $ERRNO\n"; $config_file,
ForceArray => [ 'credit_warnings' ],
) or die "Cannot load config: $config_file: $ERRNO\n";
return; return;
} }
@ -58,9 +68,11 @@ sub send_email {
my $template = get_email_template() || return; my $template = get_email_template() || return;
my $vars = { domain => $cwarning->{domain}, my $vars = {
threshold => $cwarning->{threshold}, domain => $cwarning->{domain},
adminmail => $config->{adminmail} }; threshold => $cwarning->{threshold},
adminmail => $config->{adminmail},
};
foreach my $data (@{$contracts}) { foreach my $data (@{$contracts}) {
if (exists $data->{threshold}) { if (exists $data->{threshold}) {
@ -85,8 +97,8 @@ EOF
my $email = Email::Simple->create( my $email = Email::Simple->create(
header => [ header => [
To => ref $cwarning->{recipients} eq 'ARRAY' To => ref $cwarning->{recipients} eq 'ARRAY'
? join(', ', @{$cwarning->{recipients}}) ? join(', ', @{$cwarning->{recipients}})
: $cwarning->{recipients}, : $cwarning->{recipients},
From => $template->{from_email}, From => $template->{from_email},
Subject => $template->{subject}, Subject => $template->{subject},
], ],
@ -108,18 +120,19 @@ sub get_data {
verbose => $opts->{verbose}, verbose => $opts->{verbose},
page_rows => $page_size, page_rows => $page_size,
); );
my @result = (); my @result = ();
while (my $res = $client->next_page($uri)) { while (my $res = $client->next_page($uri)) {
die "$res->result\n" unless $res->is_success; die "$res->result\n" unless $res->is_success;
my $res_hash = $res->as_hash; my $res_hash = $res->as_hash;
my $data = $res_hash->{_embedded}{'ngcp:'.$link}; my $data = $res_hash->{_embedded}{'ngcp:' . $link};
if ('ARRAY' eq ref $data) { if ('ARRAY' eq ref $data) {
unless ($process_code->($data)) { unless ($process_code->($data)) {
push(@result,@$data); push @result, @{$data};
} }
} elsif ($data) { } elsif ($data) {
unless ($process_code->([ $data ])) { unless ($process_code->([ $data ])) {
push(@result,$data); push @result, $data;
} }
} }
} }
@ -138,6 +151,7 @@ sub get_email_template {
sub main { sub main {
check_params(); check_params();
load_config(); load_config();
my $cwarnings = ref $config->{credit_warnings} eq 'ARRAY' my $cwarnings = ref $config->{credit_warnings} eq 'ARRAY'
? $config->{credit_warnings} ? $config->{credit_warnings}
: [ $config->{credit_warnings} ]; : [ $config->{credit_warnings} ];
@ -158,9 +172,11 @@ sub main {
my $ratio = $balance->{ratio} // 1.0; my $ratio = $balance->{ratio} // 1.0;
my $threshold = $cwarning->{threshold} * $ratio; my $threshold = $cwarning->{threshold} * $ratio;
next if $balance->{cash_balance} >= $threshold; next if $balance->{cash_balance} >= $threshold;
my $data = { map { $_ => $balance->{$_} } qw(id cash_balance) }; my $data = {
map { $_ => $balance->{$_} } qw(id cash_balance)
};
$data->{threshold} = $threshold if $ratio < 1.0; $data->{threshold} = $threshold if $ratio < 1.0;
push @contracts,$data; push @contracts, $data;
} }
return 1; return 1;
} }
@ -172,6 +188,7 @@ sub main {
print $EVAL_ERROR if $EVAL_ERROR; print $EVAL_ERROR if $EVAL_ERROR;
} }
} }
return 0; return 0;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -16,7 +18,7 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'domain=s', 'domain=s',
'skip_xmpp', 'skip_xmpp',
@ -26,20 +28,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99, pod2usage(
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -exitval => $missing ? 1 : 0,
-message => $missing ? "Missing parameters: $missing" : '', -verbose => 99,
); -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -49,13 +56,15 @@ sub main {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
# domain_id # domain_id
my $dom = $client->request('GET', '/api/domains/?domain='.$opts->{domain}); my $dom = $client->request('GET', '/api/domains/?domain=' . $opts->{domain});
if ($dom->as_hash->{total_count} != 1) { if ($dom->as_hash->{total_count} != 1) {
die "Domain $opts->{domain} not found\n"; die "Domain $opts->{domain} not found\n";
} }
my $uri = '/api/domains/'; my $uri = '/api/domains/';
my %data = map { '_'.$_.'_reload' => $opts->{$_} } qw(skip_xmpp skip_sip); my %data = map {
'_' . $_ . '_reload' => $opts->{$_}
} qw(skip_xmpp skip_sip);
my $dom_id; my $dom_id;
my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'}; my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'};
if (ref $tmp eq 'ARRAY') { if (ref $tmp eq 'ARRAY') {
@ -66,7 +75,7 @@ sub main {
die "Domain $opts->{domain} not found\n" unless $dom_id; die "Domain $opts->{domain} not found\n" unless $dom_id;
$uri .= $dom_id; $uri .= $dom_id;
my $res = $client->request('DELETE', $uri, \%data); my $res = $client->request('DELETE', $uri, \%data);
print $res->result."\n"; print $res->result . "\n";
return !$res->is_success; return !$res->is_success;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -22,7 +24,7 @@ my $PROGRAM_BASE = 'ngcp-fraud-notifier';
my $retcode = 0; my $retcode = 0;
my $piddir = '/run/ngcp-fraud-notifier'; my $piddir = '/run/ngcp-fraud-notifier';
my $pidfile = "$piddir/ngcp-fraud-notifier.pid"; my $pidfile = "$piddir/ngcp-fraud-notifier.pid";
my $pf = File::Pid->new({ file => $pidfile }); my $pf = File::Pid->new({ file => $pidfile });
local $PROGRAM_NAME = $PROGRAM_BASE; local $PROGRAM_NAME = $PROGRAM_BASE;
local $OUTPUT_AUTOFLUSH = 1; local $OUTPUT_AUTOFLUSH = 1;
@ -37,7 +39,7 @@ my $opts = {
my $config; my $config;
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'verbose', 'verbose',
) or usage(); ) or usage();
@ -48,19 +50,24 @@ sub DESTROY {
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 1, pod2usage(
-message => $missing ? "Missing parameters: $missing" : '', -exitval => $missing ? 1 : 0,
); -verbose => 1,
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -83,11 +90,11 @@ sub get_data {
while (my $res = $client->next_page($uri)) { while (my $res = $client->next_page($uri)) {
die "$res->result\n" unless $res->is_success; die "$res->result\n" unless $res->is_success;
my $res_hash = $res->as_hash; my $res_hash = $res->as_hash;
my $data = $res_hash->{_embedded}{'ngcp:'.$link}; my $data = $res_hash->{_embedded}{'ngcp:' . $link};
if ('ARRAY' eq ref $data) { if ('ARRAY' eq ref $data) {
push(@result,@$data); push @result, @{$data};
} elsif ($data) { } elsif ($data) {
push(@result,$data); push @result, $data;
} }
if (defined $code and 'CODE' eq ref $code) { if (defined $code and 'CODE' eq ref $code) {
$code->(\@result); $code->(\@result);
@ -99,6 +106,7 @@ sub get_data {
sub get_email_template { sub get_email_template {
my $event = shift; my $event = shift;
my $lock_type = $event->{interval_lock} ? 'lock' : 'warning'; my $lock_type = $event->{interval_lock} ? 'lock' : 'warning';
my $reseller_id = $event->{reseller_id}; my $reseller_id = $event->{reseller_id};
my @templates_data = (); my @templates_data = ();
@ -110,8 +118,8 @@ sub get_email_template {
} }
my $selected_template; my $selected_template;
foreach my $template (@templates_data) { foreach my $template (@templates_data) {
next if $template->{name} ne 'customer_fraud_'.$lock_type.'_default_email' next if $template->{name} ne 'customer_fraud_' . $lock_type . '_default_email'
&& $template->{name} ne 'customer_fraud_'.$lock_type.'_email'; && $template->{name} ne 'customer_fraud_' . $lock_type . '_email';
next if $template->{reseller_id} && $template->{reseller_id} != $reseller_id; next if $template->{reseller_id} && $template->{reseller_id} != $reseller_id;
$selected_template = $template; $selected_template = $template;
last if $template->{reseller_id}; last if $template->{reseller_id};
@ -130,20 +138,22 @@ sub send_email {
my $template = get_email_template($event); my $template = get_email_template($event);
my $vars = { adminmail => $config->{adminmail}, my $vars = {
customer_id => $event->{contract_id}, adminmail => $config->{adminmail},
interval => $event->{interval}, customer_id => $event->{contract_id},
interval_cost => sprintf('%.2f', $event->{interval_cost}/100), interval => $event->{interval},
interval_limit => sprintf('%.2f', $event->{interval_limit}/100), interval_cost => sprintf('%.2f', $event->{interval_cost} / 100),
type => $event->{type} eq 'profile_limit' interval_limit => sprintf('%.2f', $event->{interval_limit} / 100),
? 'billing profile' : 'customer', type => $event->{type} eq 'profile_limit'
}; ? 'billing profile' : 'customer',
};
foreach my $subscriber (@{$subscribers}) { foreach my $subscriber (@{$subscribers}) {
$vars->{subscribers} .= sprintf "%s\@%s %s\n", $vars->{subscribers} .= sprintf "%s\@%s %s\n",
@{$subscriber}{qw(username domain)}, @{$subscriber}{qw(username domain)},
$subscriber->{external_id} $subscriber->{external_id}
? '('.$subscriber->{external_id}.')' : ''; ? '(' . $subscriber->{external_id} . ')'
: '';
} }
my $tt = Template->new(); my $tt = Template->new();
@ -183,20 +193,26 @@ sub update_notify_status {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
my $now = strftime('%Y-%m-%d %H:%M:%S', localtime); my $now = strftime('%Y-%m-%d %H:%M:%S', localtime);
my $uri = '/api/customerfraudevents/'.$event->{id}; my $uri = '/api/customerfraudevents/' . $event->{id};
my $data = [ { op => 'replace', my $data = [
path => '/notify_status', {
value => 'notified' }, op => 'replace',
{ op => 'replace', path => '/notify_status',
path => '/notified_at', value => 'notified',
value => $now } ]; },
{
op => 'replace',
path => '/notified_at',
value => $now,
},
];
my $res = $client->request('PATCH', $uri, $data); my $res = $client->request('PATCH', $uri, $data);
return; return;
} }
sub main { sub main {
if (my $num = $pf->running) { if (my $num = $pf->running) {
print "$PROGRAM_BASE is already running.\n"; print "$PROGRAM_BASE is already running.\n";
$retcode = 1; $retcode = 1;
@ -207,22 +223,26 @@ sub main {
check_params(); check_params();
load_config(); load_config();
get_data( get_data(
sprintf('/api/customerfraudevents/?no_count=true&notify_status=%s','new'),'customerfraudevents', sub { sprintf('/api/customerfraudevents/?no_count=true&notify_status=%s', 'new'),
my $events = shift; 'customerfraudevents',
foreach my $event (@{$events}) { sub {
if ($event->{interval_notify}) { my $events = shift;
my $subscribers = get_data(sprintf('/api/subscribers/?customer_id=%d', foreach my $event (@{$events}) {
$event->{contract_id}), if ($event->{interval_notify}) {
'subscribers'); my $subscribers = get_data(sprintf('/api/subscribers/?customer_id=%d',
next unless scalar @$subscribers; $event->{contract_id}),
eval { 'subscribers');
send_email($event, $subscribers); next unless scalar @$subscribers;
}; eval {
print $EVAL_ERROR if $EVAL_ERROR; send_email($event, $subscribers);
};
print $EVAL_ERROR if $EVAL_ERROR;
}
} }
} }
}); );
return; return;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -13,7 +15,7 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'customer_id=i', 'customer_id=i',
'verbose', 'verbose',
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99, pod2usage(
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -exitval => $missing ? 1 : 0,
-message => $missing ? "Missing parameters: $missing" : '', -verbose => 99,
); -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -46,8 +53,8 @@ sub main {
my $uri = '/api/customers/'; my $uri = '/api/customers/';
$uri .= $opts->{customer_id} ? $opts->{customer_id} : ''; $uri .= $opts->{customer_id} ? $opts->{customer_id} : '';
my $res = $client->request('GET', $uri); my $res = $client->request('GET', $uri);
$res->is_success ? print $res->decoded_content."\n" $res->is_success ? print $res->decoded_content . "\n"
: print $res->result."\n"; : print $res->result . "\n";
return !$res->is_success; return !$res->is_success;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -13,7 +15,7 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'id=i', 'id=i',
'verbose', 'verbose',
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99, pod2usage(
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -exitval => $missing ? 1 : 0,
-message => $missing ? "Missing parameters: $missing" : '', -verbose => 99,
); -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -46,8 +53,8 @@ sub main {
my $uri = '/api/soundsets/'; my $uri = '/api/soundsets/';
$uri .= $opts->{id} ? $opts->{id} : ''; $uri .= $opts->{id} ? $opts->{id} : '';
my $res = $client->request('GET', $uri); my $res = $client->request('GET', $uri);
$res->is_success ? print $res->content."\n" $res->is_success ? print $res->content . "\n"
: print $res->result."\n"; : print $res->result . "\n";
return !$res->is_success; return !$res->is_success;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -13,7 +15,7 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'customer_id=i', 'customer_id=i',
'verbose', 'verbose',
@ -21,20 +23,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99, pod2usage(
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -exitval => $missing ? 1 : 0,
-message => $missing ? "Missing parameters: $missing" : '', -verbose => 99,
); -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -43,12 +50,16 @@ sub main {
my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); my $client = NGCP::API::Client->new(verbose => $opts->{verbose});
my $uri = '/api/customers/'.$opts->{customer_id}; my $uri = '/api/customers/' . $opts->{customer_id};
my $data = [ { op => 'replace', my $data = [
path => '/status', {
value => 'terminated' } ]; op => 'replace',
path => '/status',
value => 'terminated',
},
];
my $res = $client->request('PATCH', $uri, $data); my $res = $client->request('PATCH', $uri, $data);
print $res->result."\n"; print $res->result . "\n";
return !$res->is_success; return !$res->is_success;
} }

@ -1,6 +1,8 @@
#!/usr/bin/perl #!/usr/bin/perl
use strict; use strict;
use warnings; use warnings;
use English; use English;
use Getopt::Long; use Getopt::Long;
use Pod::Usage; use Pod::Usage;
@ -13,7 +15,7 @@ my $opts = {
verbose => 0, verbose => 0,
}; };
GetOptions( $opts, GetOptions($opts,
'help|h' => sub { usage() }, 'help|h' => sub { usage() },
'username=s', 'username=s',
'domain=s', 'domain=s',
@ -22,20 +24,25 @@ GetOptions( $opts,
sub check_params { sub check_params {
my @missing; my @missing;
foreach my $param (@required) { foreach my $param (@required) {
push @missing, $param unless $opts->{$param}; push @missing, $param unless $opts->{$param};
} }
usage(join(' ', @missing)) if scalar @missing; usage(join(' ', @missing)) if scalar @missing;
return; return;
} }
sub usage { sub usage {
my $missing = shift; my $missing = shift;
pod2usage(-exitval => $missing ? 1 : 0,
-verbose => 99, pod2usage(
-sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', -exitval => $missing ? 1 : 0,
-message => $missing ? "Missing parameters: $missing" : '', -verbose => 99,
); -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS',
-message => $missing ? "Missing parameters: $missing" : '',
);
return; return;
} }
@ -51,6 +58,7 @@ sub main {
my $sub_id; my $sub_id;
if ($sub->as_hash->{total_count} == 1) { if ($sub->as_hash->{total_count} == 1) {
my $tmp = $sub->as_hash->{_embedded}->{'ngcp:subscribers'}; my $tmp = $sub->as_hash->{_embedded}->{'ngcp:subscribers'};
if (ref $tmp eq 'ARRAY') { if (ref $tmp eq 'ARRAY') {
$sub_id = @{$tmp}[0]->{id}; $sub_id = @{$tmp}[0]->{id};
} else { } else {
@ -60,12 +68,16 @@ sub main {
} else { } else {
die "Subscriber $opts->{username}\@$opts->{domain} not found\n"; die "Subscriber $opts->{username}\@$opts->{domain} not found\n";
} }
$uri = '/api/subscribers/'.$sub_id; $uri = '/api/subscribers/' . $sub_id;
my $data = [ { op => 'replace', my $data = [
path => '/status', {
value => 'terminated' } ]; op => 'replace',
path => '/status',
value => 'terminated',
},
];
my $res = $client->request('PATCH', $uri, $data); my $res = $client->request('PATCH', $uri, $data);
print $res->result."\n"; print $res->result . "\n";
return !$res->is_success; return !$res->is_success;
} }

Loading…
Cancel
Save