blib/lib/Finance/GDAX/API/Withdrawl.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 18 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 86 CC 4 SCAR 13.9
CC
4
Cov
0%
to_payment
6.0
to_coinbase
6.0
to_crypto
6.0
CRAP 4.0
1 package Finance::GDAX::API::Withdrawl;
2 our $VERSION = '0.02';
3 use 5.20.0;
4 use warnings;
5 use Moose;
6 use Finance::GDAX::API::TypeConstraints;
7 use Finance::GDAX::API;
8 use namespace::autoclean;
9  
10 extends 'Finance::GDAX::API';
11  
12 has 'payment_method_id' => (is => 'rw',
13 isa => 'Str',
14 );
15 has 'coinbase_account_id' => (is => 'rw',
16 isa => 'Str',
17 );
18 has 'crypto_address' => (is => 'rw',
19 isa => 'Str',
20 );
21 has 'amount' => (is => 'rw',
22 isa => 'PositiveNum',
23 );
24 has 'currency' => (is => 'rw',
25 isa => 'Str',
26 );
27  
28 sub to_payment {
29 my $self = shift;
30 unless ($self->payment_method_id &&
31 $self->amount &&
32 $self->currency) {
33 die 'payments need amount and currency set';
34 }
35 $self->path('/withdrawls/payment-method');
36 $self->method('POST');
37 $self->body({ amount => $self->amount,
38 currency => $self->currency,
39 payment_method_id => $self->payment_method_id,
40 });
41 return $self->send;
42 }
43  
44 sub to_coinbase {
45 my $self = shift;
46 unless ($self->coinbase_account_id &&
47 $self->amount &&
48 $self->currency) {
49 die 'coinbase needs an amount and currency set';
50 }
51 $self->path('/withdrawls/coinbase-account');
52 $self->method('POST');
53 $self->body({ amount => $self->amount,
54 currency => $self->currency,
55 coinbase_account_id => $self->coinbase_account_id,
56 });
57 return $self->send;
58 }
59  
60 sub to_crypto {
61 my $self = shift;
62 unless ($self->crypto_address &&
63 $self->amount &&
64 $self->currency) {
65 die 'crypto_address needs an amount and currency set';
66 }
67 $self->path('/withdrawls/crypto');
68 $self->method('POST');
69 $self->body({ amount => $self->amount,
70 currency => $self->currency,
71 crypto_address => $self->crypto_address,
72 });
73 return $self->send;
74 }
75  
76 __PACKAGE__->meta->make_immutable;
77 1;
78  
79 =head1 NAME
80  
81 Finance::GDAX::API::Withdrawl - Withdraw funds to a Payment Method or
82 Coinbase
83  
84 =head1 SYNOPSIS
85  
86 use Finance::GDAX::API::Withdraw;
87  
88 $withdraw = Finance::GDAX::API::Withdraw->new(
89 currency => 'USD',
90 amount => '250.00');
91  
92 $withdraw->payment_method_id('kwji-wefwe-ewrgeurg-wef');
93  
94 $response = $withdraw->to_payment;
95  
96 # Or, to a Coinbase account
97 $withdraw->coinbase_account_id('woifhe-i234h-fwikn-wfihwe');
98  
99 $response = $withdraw->to_coinbase;
100  
101 # Or, to a Crypto address
102 $withdraw->crypto_address('1PtbhinXWpKZjD7CXfFR7kG8RF8vJTMCxA');
103  
104 =head2 DESCRIPTION
105  
106 Used to transfer funds out of your GDAX account, either to a
107 predefined Payment Method or your Coinbase account.
108  
109 Both methods require the same two attributes: "amount" and "currency"
110 to be set, along with their corresponding payment or coinbase account
111 id's.
112  
113 =head1 ATTRIBUTES
114  
115 =head2 C<payment_method_id> $string
116  
117 ID of the payment method.
118  
119 =head2 C<coinbase_account_id> $string
120  
121 ID of the coinbase account.
122  
123 =head2 C<crypto_address> $string
124  
125 Withdraw funds to a crypto address.
126  
127 =head2 C<amount> $number
128  
129 The amount to be withdrawn.
130  
131 =head2 C<currency> $currency_string
132  
133 The currency of the amount -- for example "USD".
134  
135 =head1 METHODS
136  
137 =head2 C<to_payment>
138  
139 All attributes must be set before calling this method. The return
140 value is a hash that will describe the result of the payment.
141  
142 From the current GDAX API documentation, this is how that returned hash is
143 keyed:
144  
145 {
146 "id":"593533d2-ff31-46e0-b22e-ca754147a96a",
147 "amount": "10.00",
148 "currency": "USD",
149 "payout_at": "2016-08-20T00:31:09Z"
150 }
151  
152 =head2 C<to_coinbase>
153  
154 All attributes must be set before calling this method. The return
155 value is a hash that will describe the result of the funds move.
156  
157 From the current GDAX API documentation, this is how that returned hash is
158 keyed:
159  
160 {
161 "id":"593533d2-ff31-46e0-b22e-ca754147a96a",
162 "amount":"10.00",
163 "currency": "BTC",
164 }
165  
166 =head2 C<to_crypto>
167  
168 All attributes must be set before calling this method. The return
169 value is a hash that will describe the result of the funds move.
170  
171 From the current GDAX API documentation, this is how that returned hash is
172 keyed:
173  
174 {
175 "id":"593533d2-ff31-46e0-b22e-ca754147a96a",
176 "amount":"10.00",
177 "currency": "BTC",
178 }
179  
180 =cut
181  
182  
183 =head1 AUTHOR
184  
185 Mark Rushing <mark@orbislumen.net>
186  
187 =head1 COPYRIGHT AND LICENSE
188  
189 This software is copyright (c) 2017 by Home Grown Systems, SPC.
190  
191 This is free software; you can redistribute it and/or modify it under
192 the same terms as the Perl 5 programming language system itself.
193  
194 =cut
195