line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nexmo::SMS::GetBalance; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
45
|
use strict; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
249
|
|
4
|
8
|
|
|
8
|
|
41
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
186
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
41
|
use LWP::UserAgent; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
174
|
|
7
|
8
|
|
|
8
|
|
37
|
use JSON::PP; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
915
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Module to ask for the balance for the Nexmo SMS API! |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %attrs = ( |
15
|
|
|
|
|
|
|
server => 'required', |
16
|
|
|
|
|
|
|
username => 'required', |
17
|
|
|
|
|
|
|
password => 'required', |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
for my $attr ( keys %attrs ) { |
21
|
8
|
|
|
8
|
|
62
|
no strict 'refs'; |
|
8
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
2730
|
|
22
|
|
|
|
|
|
|
*{ __PACKAGE__ . '::' . $attr } = sub { |
23
|
6
|
|
|
6
|
|
11
|
my ($self,$value) = @_; |
24
|
|
|
|
|
|
|
|
25
|
6
|
|
|
|
|
15
|
my $key = '__' . $attr . '__'; |
26
|
6
|
100
|
|
|
|
23
|
$self->{$key} = $value if @_ == 2; |
27
|
6
|
|
|
|
|
30
|
return $self->{$key}; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
33
|
1
|
|
|
1
|
1
|
4
|
my ($class,%param) = @_; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
4
|
my $self = bless {}, $class; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
5
|
for my $attr ( keys %attrs ) { |
38
|
3
|
50
|
|
|
|
8
|
if ( exists $param{$attr} ) { |
39
|
3
|
|
|
|
|
18
|
$self->$attr( $param{$attr} ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$self->user_agent( |
44
|
1
|
|
|
|
|
13
|
LWP::UserAgent->new( |
45
|
|
|
|
|
|
|
agent => 'Perl module ' . __PACKAGE__ . ' ' . $VERSION, |
46
|
|
|
|
|
|
|
), |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
8
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub user_agent { |
54
|
2
|
|
|
2
|
1
|
3759
|
my ($self,$ua) = @_; |
55
|
|
|
|
|
|
|
|
56
|
2
|
100
|
|
|
|
10
|
$self->{__ua__} = $ua if @_ == 2; |
57
|
2
|
|
|
|
|
6
|
return $self->{__ua__}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_balance { |
62
|
1
|
|
|
1
|
1
|
4
|
my ($self) = shift; |
63
|
|
|
|
|
|
|
|
64
|
8
|
|
|
8
|
|
9696
|
use Data::Dumper; |
|
8
|
|
|
|
|
109204
|
|
|
8
|
|
|
|
|
2076
|
|
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
5
|
my $url = sprintf "%saccount/get-balance/%s/%s", |
67
|
|
|
|
|
|
|
$self->server, |
68
|
|
|
|
|
|
|
$self->username, |
69
|
|
|
|
|
|
|
$self->password; |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
4
|
my $ua = $self->user_agent; |
72
|
1
|
|
|
|
|
6
|
$ua->default_header( 'Accept' => 'application/json' ); |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
74
|
my $response = $ua->get( |
75
|
|
|
|
|
|
|
$url, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
1
|
50
|
33
|
|
|
12
|
if ( !$response || !$response->is_success ) { |
79
|
0
|
|
|
|
|
0
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
15
|
my $json = $response->content; |
83
|
1
|
|
|
|
|
17
|
my $coder = JSON::PP->new->utf8->pretty->allow_nonref; |
84
|
1
|
|
|
|
|
203
|
my $perl = $coder->decode( $json ); |
85
|
|
|
|
|
|
|
|
86
|
1
|
50
|
33
|
|
|
308
|
return if !$perl || ref $perl ne 'HASH'; |
87
|
1
|
|
|
|
|
93
|
return $perl->{'value'}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |