diff --git a/bin/ngcp-api-ping b/bin/ngcp-api-ping index 0fb5d1a..d6f9c1d 100755 --- a/bin/ngcp-api-ping +++ b/bin/ngcp-api-ping @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use NGCP::API::Client; @@ -13,26 +15,31 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'verbose', ) or usage(); sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 1, - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 1, + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } diff --git a/bin/ngcp-create-customer b/bin/ngcp-create-customer index d1f73c9..4d9631d 100755 --- a/bin/ngcp-create-customer +++ b/bin/ngcp-create-customer @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -15,7 +17,7 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'billing_profile_id=i', 'contact_id=i', @@ -25,20 +27,25 @@ GetOptions( $opts, sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 99, - -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 99, + -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -48,10 +55,11 @@ sub main { my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); my $uri = '/api/customers/'; - my %data = map { $_ => $opts->{$_} } - qw(billing_profile_id contact_id type status); + my %data = map { + $_ => $opts->{$_} + } qw(billing_profile_id contact_id type status); my $res = $client->request('POST', $uri, \%data); - print $res->result."\n"; + print $res->result . "\n"; return !$res->is_success; } diff --git a/bin/ngcp-create-domain b/bin/ngcp-create-domain index 2bbf381..7d5dcee 100755 --- a/bin/ngcp-create-domain +++ b/bin/ngcp-create-domain @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -16,7 +18,7 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'domain=s', 'reseller_id=i', @@ -27,6 +29,7 @@ GetOptions( $opts, sub check_params { my @missing; + foreach my $arg (@ARGV) { if ($arg =~ /^[^-]/) { $opts->{domain} = $arg; @@ -37,16 +40,20 @@ sub check_params { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 99, - -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 99, + -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -61,7 +68,7 @@ sub main { $data{'_' . $elem . '_reload'} = $opts->{$elem}; } my $res = $client->request('POST', $uri, \%data); - print $res->result."\n"; + print $res->result . "\n"; return !$res->is_success; } diff --git a/bin/ngcp-create-subscriber b/bin/ngcp-create-subscriber index cc9a8c9..1fb99a9 100755 --- a/bin/ngcp-create-subscriber +++ b/bin/ngcp-create-subscriber @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -14,7 +16,7 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'customer_id=i', 'username|u=s', @@ -30,20 +32,25 @@ GetOptions( $opts, sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 99, - -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 99, + -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -59,8 +66,9 @@ sub main { } my $uri = '/api/subscribers/'; - my %data = map { $_ => $opts->{$_} } - qw(customer_id username password webpassword); + my %data = map { + $_ => $opts->{$_} + } qw(customer_id username password webpassword); $data{primary_number} = { map { $_ => $opts->{$_} } qw(cc ac sn) }; $data{administrative} = $opts->{admin}; my $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'}; @@ -70,7 +78,7 @@ sub main { $data{domain_id} = $tmp->{id}; } my $res = $client->request('POST', $uri, \%data); - print $res->result."\n"; + print $res->result . "\n"; return !$res->is_success; } diff --git a/bin/ngcp-credit-warning b/bin/ngcp-credit-warning index 1fe99e1..9925a81 100755 --- a/bin/ngcp-credit-warning +++ b/bin/ngcp-credit-warning @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -24,32 +26,40 @@ my $opts = { my $config; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'verbose', ) or usage(); sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 1, - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 1, + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } sub load_config { - $config = XML::Simple->new()->XMLin($config_file, ForceArray => [ 'credit_warnings' ]) - or die "Cannot load config: $config_file: $ERRNO\n"; + $config = XML::Simple->new()->XMLin( + $config_file, + ForceArray => [ 'credit_warnings' ], + ) or die "Cannot load config: $config_file: $ERRNO\n"; + return; } @@ -58,9 +68,11 @@ sub send_email { my $template = get_email_template() || return; - my $vars = { domain => $cwarning->{domain}, - threshold => $cwarning->{threshold}, - adminmail => $config->{adminmail} }; + my $vars = { + domain => $cwarning->{domain}, + threshold => $cwarning->{threshold}, + adminmail => $config->{adminmail}, + }; foreach my $data (@{$contracts}) { if (exists $data->{threshold}) { @@ -85,8 +97,8 @@ EOF my $email = Email::Simple->create( header => [ To => ref $cwarning->{recipients} eq 'ARRAY' - ? join(', ', @{$cwarning->{recipients}}) - : $cwarning->{recipients}, + ? join(', ', @{$cwarning->{recipients}}) + : $cwarning->{recipients}, From => $template->{from_email}, Subject => $template->{subject}, ], @@ -108,18 +120,19 @@ sub get_data { verbose => $opts->{verbose}, page_rows => $page_size, ); + my @result = (); while (my $res = $client->next_page($uri)) { die "$res->result\n" unless $res->is_success; 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) { unless ($process_code->($data)) { - push(@result,@$data); + push @result, @{$data}; } } elsif ($data) { unless ($process_code->([ $data ])) { - push(@result,$data); + push @result, $data; } } } @@ -138,6 +151,7 @@ sub get_email_template { sub main { check_params(); load_config(); + my $cwarnings = ref $config->{credit_warnings} eq 'ARRAY' ? $config->{credit_warnings} : [ $config->{credit_warnings} ]; @@ -158,9 +172,11 @@ sub main { my $ratio = $balance->{ratio} // 1.0; my $threshold = $cwarning->{threshold} * $ratio; 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; - push @contracts,$data; + push @contracts, $data; } return 1; } @@ -172,6 +188,7 @@ sub main { print $EVAL_ERROR if $EVAL_ERROR; } } + return 0; } diff --git a/bin/ngcp-delete-domain b/bin/ngcp-delete-domain index 5af67fc..9f2cc91 100755 --- a/bin/ngcp-delete-domain +++ b/bin/ngcp-delete-domain @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -16,7 +18,7 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'domain=s', 'skip_xmpp', @@ -26,20 +28,25 @@ GetOptions( $opts, sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 99, - -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 99, + -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -49,13 +56,15 @@ sub main { my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); # 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) { die "Domain $opts->{domain} not found\n"; } 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 $tmp = $dom->as_hash->{_embedded}->{'ngcp:domains'}; if (ref $tmp eq 'ARRAY') { @@ -66,7 +75,7 @@ sub main { die "Domain $opts->{domain} not found\n" unless $dom_id; $uri .= $dom_id; my $res = $client->request('DELETE', $uri, \%data); - print $res->result."\n"; + print $res->result . "\n"; return !$res->is_success; } diff --git a/bin/ngcp-fraud-notifier b/bin/ngcp-fraud-notifier index f0e417a..7ef96d1 100755 --- a/bin/ngcp-fraud-notifier +++ b/bin/ngcp-fraud-notifier @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -22,7 +24,7 @@ my $PROGRAM_BASE = 'ngcp-fraud-notifier'; my $retcode = 0; my $piddir = '/run/ngcp-fraud-notifier'; 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 $OUTPUT_AUTOFLUSH = 1; @@ -37,7 +39,7 @@ my $opts = { my $config; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'verbose', ) or usage(); @@ -48,19 +50,24 @@ sub DESTROY { sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 1, - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 1, + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -83,11 +90,11 @@ sub get_data { while (my $res = $client->next_page($uri)) { die "$res->result\n" unless $res->is_success; 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) { - push(@result,@$data); + push @result, @{$data}; } elsif ($data) { - push(@result,$data); + push @result, $data; } if (defined $code and 'CODE' eq ref $code) { $code->(\@result); @@ -99,6 +106,7 @@ sub get_data { sub get_email_template { my $event = shift; + my $lock_type = $event->{interval_lock} ? 'lock' : 'warning'; my $reseller_id = $event->{reseller_id}; my @templates_data = (); @@ -110,8 +118,8 @@ sub get_email_template { } my $selected_template; foreach my $template (@templates_data) { - next if $template->{name} ne 'customer_fraud_'.$lock_type.'_default_email' - && $template->{name} ne 'customer_fraud_'.$lock_type.'_email'; + next if $template->{name} ne 'customer_fraud_' . $lock_type . '_default_email' + && $template->{name} ne 'customer_fraud_' . $lock_type . '_email'; next if $template->{reseller_id} && $template->{reseller_id} != $reseller_id; $selected_template = $template; last if $template->{reseller_id}; @@ -130,20 +138,22 @@ sub send_email { my $template = get_email_template($event); - my $vars = { adminmail => $config->{adminmail}, - customer_id => $event->{contract_id}, - interval => $event->{interval}, - interval_cost => sprintf('%.2f', $event->{interval_cost}/100), - interval_limit => sprintf('%.2f', $event->{interval_limit}/100), - type => $event->{type} eq 'profile_limit' - ? 'billing profile' : 'customer', - }; + my $vars = { + adminmail => $config->{adminmail}, + customer_id => $event->{contract_id}, + interval => $event->{interval}, + interval_cost => sprintf('%.2f', $event->{interval_cost} / 100), + interval_limit => sprintf('%.2f', $event->{interval_limit} / 100), + type => $event->{type} eq 'profile_limit' + ? 'billing profile' : 'customer', + }; foreach my $subscriber (@{$subscribers}) { $vars->{subscribers} .= sprintf "%s\@%s %s\n", @{$subscriber}{qw(username domain)}, $subscriber->{external_id} - ? '('.$subscriber->{external_id}.')' : ''; + ? '(' . $subscriber->{external_id} . ')' + : ''; } my $tt = Template->new(); @@ -183,20 +193,26 @@ sub update_notify_status { my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); my $now = strftime('%Y-%m-%d %H:%M:%S', localtime); - my $uri = '/api/customerfraudevents/'.$event->{id}; - my $data = [ { op => 'replace', - path => '/notify_status', - value => 'notified' }, - { op => 'replace', - path => '/notified_at', - value => $now } ]; + my $uri = '/api/customerfraudevents/' . $event->{id}; + my $data = [ + { + op => 'replace', + path => '/notify_status', + value => 'notified', + }, + { + op => 'replace', + path => '/notified_at', + value => $now, + }, + ]; + my $res = $client->request('PATCH', $uri, $data); return; } sub main { - if (my $num = $pf->running) { print "$PROGRAM_BASE is already running.\n"; $retcode = 1; @@ -207,22 +223,26 @@ sub main { check_params(); load_config(); + get_data( - sprintf('/api/customerfraudevents/?no_count=true¬ify_status=%s','new'),'customerfraudevents', sub { - my $events = shift; - foreach my $event (@{$events}) { - if ($event->{interval_notify}) { - my $subscribers = get_data(sprintf('/api/subscribers/?customer_id=%d', - $event->{contract_id}), - 'subscribers'); - next unless scalar @$subscribers; - eval { - send_email($event, $subscribers); - }; - print $EVAL_ERROR if $EVAL_ERROR; + sprintf('/api/customerfraudevents/?no_count=true¬ify_status=%s', 'new'), + 'customerfraudevents', + sub { + my $events = shift; + foreach my $event (@{$events}) { + if ($event->{interval_notify}) { + my $subscribers = get_data(sprintf('/api/subscribers/?customer_id=%d', + $event->{contract_id}), + 'subscribers'); + next unless scalar @$subscribers; + eval { + send_email($event, $subscribers); + }; + print $EVAL_ERROR if $EVAL_ERROR; + } } } - }); + ); return; } diff --git a/bin/ngcp-get-customer b/bin/ngcp-get-customer index 6f6f546..b49a334 100755 --- a/bin/ngcp-get-customer +++ b/bin/ngcp-get-customer @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -13,7 +15,7 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'customer_id=i', 'verbose', @@ -21,20 +23,25 @@ GetOptions( $opts, sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 99, - -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 99, + -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -46,8 +53,8 @@ sub main { my $uri = '/api/customers/'; $uri .= $opts->{customer_id} ? $opts->{customer_id} : ''; my $res = $client->request('GET', $uri); - $res->is_success ? print $res->decoded_content."\n" - : print $res->result."\n"; + $res->is_success ? print $res->decoded_content . "\n" + : print $res->result . "\n"; return !$res->is_success; } diff --git a/bin/ngcp-sound-set b/bin/ngcp-sound-set index 9b0b643..c54eed3 100755 --- a/bin/ngcp-sound-set +++ b/bin/ngcp-sound-set @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -13,7 +15,7 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'id=i', 'verbose', @@ -21,20 +23,25 @@ GetOptions( $opts, sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 99, - -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 99, + -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -46,8 +53,8 @@ sub main { my $uri = '/api/soundsets/'; $uri .= $opts->{id} ? $opts->{id} : ''; my $res = $client->request('GET', $uri); - $res->is_success ? print $res->content."\n" - : print $res->result."\n"; + $res->is_success ? print $res->content . "\n" + : print $res->result . "\n"; return !$res->is_success; } diff --git a/bin/ngcp-terminate-customer b/bin/ngcp-terminate-customer index fc1d1c5..9de5521 100755 --- a/bin/ngcp-terminate-customer +++ b/bin/ngcp-terminate-customer @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -13,7 +15,7 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'customer_id=i', 'verbose', @@ -21,20 +23,25 @@ GetOptions( $opts, sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 99, - -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 99, + -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -43,12 +50,16 @@ sub main { my $client = NGCP::API::Client->new(verbose => $opts->{verbose}); - my $uri = '/api/customers/'.$opts->{customer_id}; - my $data = [ { op => 'replace', - path => '/status', - value => 'terminated' } ]; + my $uri = '/api/customers/' . $opts->{customer_id}; + my $data = [ + { + op => 'replace', + path => '/status', + value => 'terminated', + }, + ]; my $res = $client->request('PATCH', $uri, $data); - print $res->result."\n"; + print $res->result . "\n"; return !$res->is_success; } diff --git a/bin/ngcp-terminate-subscriber b/bin/ngcp-terminate-subscriber index e0d59d1..d8f6ddc 100755 --- a/bin/ngcp-terminate-subscriber +++ b/bin/ngcp-terminate-subscriber @@ -1,6 +1,8 @@ #!/usr/bin/perl + use strict; use warnings; + use English; use Getopt::Long; use Pod::Usage; @@ -13,7 +15,7 @@ my $opts = { verbose => 0, }; -GetOptions( $opts, +GetOptions($opts, 'help|h' => sub { usage() }, 'username=s', 'domain=s', @@ -22,20 +24,25 @@ GetOptions( $opts, sub check_params { my @missing; + foreach my $param (@required) { push @missing, $param unless $opts->{$param}; } usage(join(' ', @missing)) if scalar @missing; + return; } sub usage { my $missing = shift; - pod2usage(-exitval => $missing ? 1 : 0, - -verbose => 99, - -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', - -message => $missing ? "Missing parameters: $missing" : '', - ); + + pod2usage( + -exitval => $missing ? 1 : 0, + -verbose => 99, + -sections => 'SYNOPSIS|REQUIRED ARGUMENTS|OPTIONS', + -message => $missing ? "Missing parameters: $missing" : '', + ); + return; } @@ -51,6 +58,7 @@ sub main { my $sub_id; if ($sub->as_hash->{total_count} == 1) { my $tmp = $sub->as_hash->{_embedded}->{'ngcp:subscribers'}; + if (ref $tmp eq 'ARRAY') { $sub_id = @{$tmp}[0]->{id}; } else { @@ -60,12 +68,16 @@ sub main { } else { die "Subscriber $opts->{username}\@$opts->{domain} not found\n"; } - $uri = '/api/subscribers/'.$sub_id; - my $data = [ { op => 'replace', - path => '/status', - value => 'terminated' } ]; + $uri = '/api/subscribers/' . $sub_id; + my $data = [ + { + op => 'replace', + path => '/status', + value => 'terminated', + }, + ]; my $res = $client->request('PATCH', $uri, $data); - print $res->result."\n"; + print $res->result . "\n"; return !$res->is_success; }