line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::BitFlyer; |
2
|
3
|
|
|
3
|
|
193517
|
use strict; |
|
3
|
|
|
|
|
34
|
|
|
3
|
|
|
|
|
132
|
|
3
|
3
|
|
|
3
|
|
25
|
use warnings; |
|
3
|
|
|
|
|
16
|
|
|
3
|
|
|
|
|
164
|
|
4
|
3
|
|
|
3
|
|
29
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
245
|
|
5
|
3
|
|
|
3
|
|
2574
|
use HTTP::Tiny; |
|
3
|
|
|
|
|
136388
|
|
|
3
|
|
|
|
|
124
|
|
6
|
3
|
|
|
3
|
|
1521
|
use URI::Query; |
|
3
|
|
|
|
|
25818
|
|
|
3
|
|
|
|
|
168
|
|
7
|
3
|
|
|
3
|
|
1505
|
use Digest::SHA qw/hmac_sha256_hex/; |
|
3
|
|
|
|
|
8962
|
|
|
3
|
|
|
|
|
230
|
|
8
|
3
|
|
|
3
|
|
2030
|
use JSON qw//; |
|
3
|
|
|
|
|
28044
|
|
|
3
|
|
|
|
|
136
|
|
9
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
10
|
3
|
|
|
|
|
27
|
ro => [qw/ |
11
|
|
|
|
|
|
|
api_base |
12
|
|
|
|
|
|
|
access_key |
13
|
|
|
|
|
|
|
secret_key |
14
|
|
|
|
|
|
|
/], |
15
|
|
|
|
|
|
|
rw => [qw/ |
16
|
|
|
|
|
|
|
client |
17
|
|
|
|
|
|
|
sign |
18
|
|
|
|
|
|
|
timestamp |
19
|
|
|
|
|
|
|
decode_json |
20
|
|
|
|
|
|
|
api |
21
|
|
|
|
|
|
|
/], |
22
|
3
|
|
|
3
|
|
1286
|
); |
|
3
|
|
|
|
|
2754
|
|
23
|
|
|
|
|
|
|
|
24
|
3
|
|
|
3
|
|
1701
|
use WebService::BitFlyer::API; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
1650
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
1
|
|
|
1
|
1
|
131
|
my $class = shift; |
30
|
1
|
|
|
|
|
6
|
my %args = @_; |
31
|
|
|
|
|
|
|
|
32
|
1
|
50
|
33
|
|
|
9
|
if (!$args{access_key} || !$args{secret_key}) { |
33
|
0
|
|
|
|
|
0
|
croak "require 'access_key' and 'secret_key'."; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
8
|
my $self = bless { |
37
|
|
|
|
|
|
|
decode_json => 0, |
38
|
|
|
|
|
|
|
api_base => 'https://api.bitflyer.jp', |
39
|
|
|
|
|
|
|
%args, |
40
|
|
|
|
|
|
|
}, $class; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
7
|
$self->_initialize($args{client_opt}); |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
9
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _initialize { |
48
|
1
|
|
|
1
|
|
6
|
my ($self, $client_opt) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$self->client( |
51
|
|
|
|
|
|
|
HTTP::Tiny->new( |
52
|
|
|
|
|
|
|
agent => __PACKAGE__ . "/$VERSION", |
53
|
|
|
|
|
|
|
default_headers => { |
54
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
55
|
|
|
|
|
|
|
'ACCESS-KEY' => $self->access_key, |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
timeout => 15, |
58
|
|
|
|
|
|
|
verify_SSL => 1, |
59
|
1
|
50
|
|
|
|
8
|
%{$client_opt || {}}, |
|
1
|
|
|
|
|
30
|
|
60
|
|
|
|
|
|
|
) |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
106
|
$self->api(WebService::BitFlyer::API->new($self)); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub set_sign { |
67
|
0
|
|
|
0
|
1
|
|
my ($self, $method, $req_path, $body) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->timestamp(time); |
70
|
0
|
|
0
|
|
|
|
$self->sign(hmac_sha256_hex($self->timestamp . $method . $req_path . ($body || ''), $self->secret_key)); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub request { |
74
|
0
|
|
|
0
|
1
|
|
my ($self, $method, $req_path, $query) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$method = uc $method; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $res; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if ($method eq 'GET') { |
|
|
0
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $query_string = URI::Query->new($query)->stringify; |
82
|
0
|
0
|
|
|
|
|
$query_string = $query_string ? "?$query_string" : ''; |
83
|
0
|
|
|
|
|
|
$self->set_sign($method, $req_path . $query_string); |
84
|
0
|
|
|
|
|
|
my $req_url = join '', $self->api_base, $req_path, $query_string; |
85
|
0
|
|
|
|
|
|
$res = $self->client->get( |
86
|
|
|
|
|
|
|
$req_url, |
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
headers => { |
89
|
|
|
|
|
|
|
'ACCESS-TIMESTAMP' => $self->timestamp, |
90
|
|
|
|
|
|
|
'ACCESS-SIGN' => $self->sign, |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
}, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
elsif ($method =~ m!^(?:POST|DELETE)$!) { |
96
|
0
|
0
|
|
|
|
|
my $content = $query ? JSON::encode_json($query) : ''; |
97
|
0
|
|
|
|
|
|
$self->set_sign($method, $req_path, $content); |
98
|
0
|
|
|
|
|
|
my $req_url = join '', $self->api_base, $req_path; |
99
|
0
|
|
|
|
|
|
$res = $self->client->request( |
100
|
|
|
|
|
|
|
$method, |
101
|
|
|
|
|
|
|
$req_url, |
102
|
|
|
|
|
|
|
{ |
103
|
|
|
|
|
|
|
content => $content, |
104
|
|
|
|
|
|
|
headers => { |
105
|
|
|
|
|
|
|
'ACCESS-TIMESTAMP' => $self->timestamp, |
106
|
|
|
|
|
|
|
'ACCESS-SIGN' => $self->sign, |
107
|
|
|
|
|
|
|
}, |
108
|
|
|
|
|
|
|
}, |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
unless ($res->{success}) { |
113
|
0
|
|
|
|
|
|
croak "Error:" . join "\t", map { $res->{$_} } (qw/url status reason content/); |
|
0
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
if ($self->decode_json) { |
117
|
0
|
|
|
|
|
|
return JSON::decode_json($res->{content}); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
else { |
120
|
0
|
|
|
|
|
|
return $res->{content}; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |