Coincheck.pm

filter: Statementstmt 69.7% 46 / 66 Branchbran 0.0% 0 / 12 Conditioncond 25.0% 1 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 86.6% 13 / 15 Podpod 100% 3 / 3 totaltotal 61.7% 63 / 102 CC 10 SCAR 28.7
CC
10
Cov
57%
request
56.0
set_signature
6.0
_initialize
3.0
CRAP 17.7
↑ Summary Coincheck/Withdraw.pm »
1 package WebService::Coincheck;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Time::HiRes qw/time/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use URI::Query;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Digest::SHA qw/hmac_sha256_hex/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use String::CamelCase qw/camelize/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Class::Load qw/load_class/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use JSON qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Class::Accessor::Lite (
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ro => [qw/
14 api_base
15 access_key
16 secret_key
17 ticker
18 trade
19 order_book
20 order
21 leverage
22 account
23 send
24 deposit
25 bank_account
26 withdraw
27 borrow
28 transfer
29 /],
30 rw => [qw/
31 client
32 signature
33 nonce
34 decode_json
35 /],
36 3 );
37  
38 3 our $VERSION = '0.04';
39  
40 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
41 1 my $class = shift;
42 1 my %args = @_;
43  
44 1 my $self = bless {
45 decode_json => 0,
46 api_base => 'https://coincheck.jp/',
47 %args,
48 }, $class;
49  
50 1 $self->_initialize($args{client_opt});
51  
52 1 return $self;
53 }
54  
55 1 ▶sub _initialize {
Subroutine _initialize: called CC=3 SCAR=11.0
56 1 my ($self, $client_opt) = @_;
57  
58 $self->client(
59 HTTP::Tiny->new(
60 agent => __PACKAGE__ . "/$VERSION",
61 default_headers => {
62 'Content-Type' => 'application/json',
63 'ACCESS-KEY' => $self->access_key,
64 },
65 timeout => 15,
66 verify_SSL => 1,
67 1 ▶ %{$client_opt || {}},
Condition50%1/2
$client_opt || {}
l!l
01
MC/DC0%0/1
$client_opt || {}
$client_opt
Truth table50%1/2
A
A= $client_opt
Aresult
11
00
68 )
69 );
70  
71 1 for my $api (qw/
72 ticker
73 trade
74 order_book
75 order
76 leverage
77 account
78 send
79 deposit
80 bank_account
81 withdraw
82 borrow
83 transfer
84 /) {
85 12 my $klass = 'WebService::Coincheck::' . camelize($api);
86 12 $self->{$api} = load_class($klass)->new($self);
87 }
88 }
89  
90 0 ▶sub set_signature {
Subroutine set_signature: not called CC=2 SCAR=17.9
Pod documented
91 0 my ($self, $req_url, $body) = @_;
92  
93 0 $self->nonce(int(time * 10000));
94 0 ▶ $self->signature(hmac_sha256_hex($self->nonce . $req_url . ($body || ''), $self->secret_key));
Condition0%0/2
$body || ''
l!l
00
MC/DC0%0/1
$body || ''
$body
Truth table0%0/2
A
A= $body
Aresult
11
00
95 }
96  
97 0 ▶sub request {
Subroutine request: not called CC=7 SCAR=40.3
Pod documented
98 0 my ($self, $method, $req_path, $query) = @_;
99  
100 0 my $res;
101  
102 0 ▶ if ($method =~ m!^get$!i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($method =~ /^get$/i) { } 0 0 0
elsif ($method =~ /^(?:post|delete)$/i) { } 0 0 0
103 0 my $query_string = URI::Query->new($query)->stringify;
104 0 ▶ my $req_url = join '', $self->api_base, $req_path, $query_string ? "?$query_string" : '';
Branch: 1 branch
BranchTrueFalseTotal
$query_string ? : 0 0 0
105 0 $self->set_signature($req_url);
106 0 $res = $self->client->get(
107 $req_url,
108 {
109 headers => {
110 'ACCESS-NONCE' => $self->nonce,
111 'ACCESS-SIGNATURE' => $self->signature,
112 },
113 },
114 );
115 }
116 elsif ($method =~ m!^(?:post|delete)$!i) {
117 0 my $req_url = join '', $self->api_base, $req_path;
118 0 ▶ my $content = $query ? JSON::encode_json($query) : '';
Branch: 1 branch
BranchTrueFalseTotal
$query ? : 0 0 0
119 0 $self->set_signature($req_url, $content);
120 0 $res = $self->client->request(
121 uc $method,
122 $req_url,
123 {
124 content => $content,
125 headers => {
126 'ACCESS-NONCE' => $self->nonce,
127 'ACCESS-SIGNATURE' => $self->signature,
128 },
129 },
130 );
131 }
132  
133 0 ▶ unless ($res->{success}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"success"}) 0 0 0
134 0 croak "Error:" . join "\t", map { $res->{$_} } (qw/url status reason content/);
135 }
136  
137 0 ▶ if ($self->decode_json) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->decode_json) { } 0 0 0
138 0 return JSON::decode_json($res->{content});
139 }
140 else {
141 0 return $res->{content};
142 }
143 }
144  
145 3 1;
146  
147 __END__
↑ Summary Coincheck/Withdraw.pm »