line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Dogecoin::API; |
2
|
|
|
|
|
|
|
$Finance::Dogecoin::API::VERSION = '1.20140201.1608'; |
3
|
3
|
|
|
3
|
|
232006
|
use 5.010; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
120
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
4723
|
use Moo; |
|
3
|
|
|
|
|
73964
|
|
|
3
|
|
|
|
|
30
|
|
6
|
|
|
|
|
|
|
# limit the damage from Moo's use of strictures |
7
|
|
|
|
|
|
|
# see: http://www.modernperlbooks.com/mt/2014/01/fatal-warnings-are-a-ticking-time-bomb.html |
8
|
3
|
|
|
3
|
|
5878
|
use warnings NONFATAL => 'all'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
92
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
17
|
use Carp (); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
41
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
2593
|
use URI; |
|
3
|
|
|
|
|
29927
|
|
|
3
|
|
|
|
|
116
|
|
13
|
3
|
|
|
3
|
|
2863
|
use JSON; |
|
3
|
|
|
|
|
27097
|
|
|
3
|
|
|
|
|
23
|
|
14
|
3
|
|
|
3
|
|
3844
|
use HTTP::Headers; |
|
3
|
|
|
|
|
29415
|
|
|
3
|
|
|
|
|
122
|
|
15
|
3
|
|
|
3
|
|
1066
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
32516
|
|
|
3
|
|
|
|
|
86
|
|
16
|
3
|
|
|
3
|
|
2770
|
use LWP::Protocol::https; |
|
3
|
|
|
|
|
426697
|
|
|
3
|
|
|
|
|
129
|
|
17
|
3
|
|
|
3
|
|
2850
|
use URI::QueryParam; |
|
3
|
|
|
|
|
2960
|
|
|
3
|
|
|
|
|
1458
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has 'api_key', is => 'ro', required => 1; |
20
|
|
|
|
|
|
|
has 'endpoint', is => 'ro', default => sub { 'https://www.dogeapi.com/wow/' }; |
21
|
|
|
|
|
|
|
has 'json', is => 'ro', default => sub { |
22
|
|
|
|
|
|
|
my $j = JSON->new; $j->allow_nonref; $j |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'ua', is => 'ro', default => sub { |
26
|
|
|
|
|
|
|
my $headers = HTTP::Headers->new; |
27
|
|
|
|
|
|
|
$headers->header( 'Content-Type' => 'application/json' ); |
28
|
|
|
|
|
|
|
LWP::UserAgent->new( |
29
|
|
|
|
|
|
|
ssl_opts => { verify_hostname => 1 }, |
30
|
|
|
|
|
|
|
default_headers => $headers, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub request { |
35
|
13
|
|
|
13
|
0
|
59
|
my ($self, $method, %params) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# manually setting the 'a' parameter avoids a weird behavior in LWP::UA |
38
|
|
|
|
|
|
|
# which uppercases 'a'--not what the API expects or wants |
39
|
13
|
|
|
|
|
74
|
my $uri = URI->new( $self->endpoint ); |
40
|
13
|
|
|
|
|
26586
|
$uri->query_param( a => $method ); |
41
|
|
|
|
|
|
|
|
42
|
13
|
|
|
|
|
1646
|
while (my ($key, $value) = each %params) { |
43
|
16
|
|
|
|
|
1114
|
$uri->query_param( $key => $value ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
13
|
|
|
|
|
1703
|
my $response = $self->ua->get( $uri ); |
47
|
13
|
|
|
|
|
897
|
my $result = $self->json->decode( $response->decoded_content ); |
48
|
|
|
|
|
|
|
|
49
|
13
|
100
|
|
|
|
872
|
Carp::croak( "Bad API call from $method() call" ) if $result eq 'Bad Query'; |
50
|
13
|
100
|
|
|
|
52
|
Carp::croak( "Invalid API key '" . $self->api_key . "'" ) |
51
|
|
|
|
|
|
|
if $result eq 'Invalid API Key'; |
52
|
|
|
|
|
|
|
|
53
|
13
|
|
|
|
|
90
|
return $result; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
BEGIN { |
57
|
3
|
|
|
3
|
|
8
|
for my $non_api (qw( get_difficulty get_current_block get_current_price )) { |
58
|
9
|
|
|
3
|
|
36
|
my $method = sub { $_[0]->request( $non_api ) }; |
|
3
|
|
|
|
|
1524
|
|
59
|
9
|
|
|
|
|
12
|
do { |
60
|
3
|
|
|
3
|
|
33
|
no strict 'refs'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
267
|
|
61
|
9
|
|
|
|
|
11
|
*{ $non_api } = $method; |
|
9
|
|
|
|
|
45
|
|
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
3
|
|
|
|
|
7
|
for my $api (qw( get_balance get_my_addresses )) { |
66
|
6
|
|
|
4
|
|
16
|
my $method = sub { $_[0]->request( $api, api_key => $_[0]->api_key ) }; |
|
4
|
|
|
|
|
7496
|
|
67
|
6
|
|
|
|
|
8
|
do { |
68
|
3
|
|
|
3
|
|
14
|
no strict 'refs'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
110
|
|
69
|
6
|
|
|
|
|
8
|
*{ $api } = $method; |
|
6
|
|
|
|
|
1191
|
|
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub withdraw { |
75
|
7
|
|
|
7
|
1
|
4466
|
my ($self, %params) = @_; |
76
|
|
|
|
|
|
|
|
77
|
7
|
|
|
|
|
8
|
my @errors; |
78
|
|
|
|
|
|
|
|
79
|
7
|
|
|
|
|
14
|
for my $param (qw( payment_address amount )) { |
80
|
14
|
100
|
|
|
|
46
|
push @errors, $param unless $params{$param}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
7
|
100
|
|
|
|
20
|
if (@errors) { |
84
|
4
|
|
|
|
|
8
|
my $error = join ', ', @errors; |
85
|
4
|
|
|
|
|
52
|
Carp::croak( "Must call withdraw() with $error params" ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
3
|
100
|
|
|
|
30
|
Carp::croak( 'Must call withdraw() with amount of at least 5 Doge' ) |
89
|
|
|
|
|
|
|
if $params{amount} < 5; |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
8
|
$self->request( 'withdraw', api_key => $self->api_key, %params ); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub get_new_address { |
95
|
1
|
|
|
1
|
1
|
582
|
my ($self, %params) = @_; |
96
|
1
|
|
|
|
|
7
|
$self->request( 'get_new_address', api_key => $self->api_key, %params ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub get_address_received { |
100
|
3
|
|
|
3
|
1
|
617
|
my ($self, %params) = @_; |
101
|
3
|
|
100
|
|
|
18
|
$params{payment_address} //= $params{address_label}; |
102
|
|
|
|
|
|
|
|
103
|
3
|
100
|
|
|
|
36
|
Carp::croak( 'Must call get_address_received() with payment_address param' ) |
104
|
|
|
|
|
|
|
unless $params{payment_address}; |
105
|
|
|
|
|
|
|
|
106
|
2
|
|
|
|
|
12
|
$self->request( 'get_address_received', |
107
|
|
|
|
|
|
|
api_key => $self->api_key, %params |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub get_address_by_label { |
112
|
3
|
|
|
3
|
1
|
747
|
my ($self, %params) = @_; |
113
|
|
|
|
|
|
|
|
114
|
3
|
100
|
|
|
|
23
|
Carp::croak( 'Must call get_address_by_label() with address_label param' ) |
115
|
|
|
|
|
|
|
unless $params{address_label}; |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
|
|
|
20
|
$self->request( 'get_address_by_label', |
118
|
|
|
|
|
|
|
api_key => $self->api_key, %params |
119
|
|
|
|
|
|
|
); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
'to the moon'; |
123
|
|
|
|
|
|
|
__END__ |