| 1 | package Finance::Robinhood::Utils::Credentials; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | with 'MooX::Singleton'; | |||||||||||||||||||||||||||
| 4 | 3 | has 'old_skool' => ( is => 'rw', clearer => 1, predicate => 1 ); | |||||||||||||||||||||||||||
| 5 | 3 | has 'oauth' => ( is => 'rw', clearer => 1, predicate => 1 ); | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | sub migrate { | ||||||||||||||||||||||||||||
| 8 | 0 | ▶ | my $s = shift; | ||||||||||||||||||||||||||
|
Subroutine
migrate: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 0 | ▶ | return 1 if $s->has_oauth; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 10 | 0 | ▶ | return 0 if !$s->has_old_skool; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 11 | my ( $status, $token ) | ||||||||||||||||||||||||||||
| 12 | = Finance::Robinhood::Utils::Client->instance->post( | ||||||||||||||||||||||||||||
| 13 | 0 | $Finance::Robinhood::Endpoints{'oauth2/migrate_token'} ); | |||||||||||||||||||||||||||
| 14 | 0 | ▶ | $status == 200 ? !!$s->oauth( $token, _birth => time ) && $s->clear_old_skool() : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not !$s->oauth($token, "_birth", time) and $s->clear_old_skool
MC/DC0%0/2
not !$s->oauth($token, "_birth", time) and $s->clear_old_skool
not !$s->oauth($token, "_birth", time)
$s->clear_old_skool
Truth table0%0/3
A and B
A= not !$s->oauth($token, "_birth", time)B= $s->clear_old_skool
| |||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub headers { | ||||||||||||||||||||||||||||
| 18 | 6 | ▶ | my $s = shift; | ||||||||||||||||||||||||||
|
Subroutine
headers: called CC=3 SCAR=13.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | if ( $s->has_oauth ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 20 | #use Data::Dump; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # TODO: If expired, use refresh token to get new access token | ||||||||||||||||||||||||||||
| 23 | #ddx $s->oauth; | ||||||||||||||||||||||||||||
| 24 | 0 | return { Authorization => 'Bearer ' . $s->oauth->{access_token} }; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | elsif ( $s->has_old_skool ) { | ||||||||||||||||||||||||||||
| 27 | 0 | return { Authorization => 'Token ' . $s->old_skool }; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 6 | {}; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | 3 | 1; | |||||||||||||||||||||||||||