| 1 | package Finance::Robinhood::User; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | =for stopwords watchlist watchlists untradable urls | ||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | Finance::Robinhood::User - Represents a Single Authorized User | ||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | use Finance::Robinhood; | ||||||||||||||||||
| 14 | my $rh = Finance::Robinhood->new; | ||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | my $user = $rh->user(); | ||||||||||||||||||
| 17 | CORE::say $user->first_name . ' ' . $user->last_name; | ||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | =cut | ||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | 1 | our $VERSION = '0.92_003'; | |||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | 1 | ▶ | sub _test__init { | ||||||||||||||||
|
Subroutine
_test__init: called CC=1 SCAR=3.5
| |||||||||||||||||||
| 24 | 1 | my $rh = t::Utility::rh_instance(1); | |||||||||||||||||
| 25 | 0 | my $user = $rh->user; | |||||||||||||||||
| 26 | 0 | isa_ok($user, __PACKAGE__); | |||||||||||||||||
| 27 | 0 | t::Utility::stash('USER', $user); # Store it for later | |||||||||||||||||
| 28 | } | ||||||||||||||||||
| 29 | 1 | ▶ | use Mojo::Base-base, -signatures; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 30 | 1 | ▶ | use Mojo::URL; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 31 | # | ||||||||||||||||||
| 32 | 1 | ▶ | use Time::Moment; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 33 | 1 | ▶ | use Finance::Robinhood::User::AdditionalInfo; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 34 | 1 | ▶ | use Finance::Robinhood::User::BasicInfo; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 35 | 1 | ▶ | use Finance::Robinhood::User::Employment; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 36 | 1 | ▶ | use Finance::Robinhood::User::IDInfo; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 37 | 1 | ▶ | use Finance::Robinhood::User::InternationalInfo; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 38 | 1 | ▶ | use Finance::Robinhood::User::Profile; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 39 | # | ||||||||||||||||||
| 40 | 1 | has _rh => undef => weak => 1; | |||||||||||||||||
| 41 | |||||||||||||||||||
| 42 | =head1 METHODS | ||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | =head2 C<email( )> | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | Email address attached to the account. | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | =head2 C<email_verified( )> | ||||||||||||||||||
| 49 | |||||||||||||||||||
| 50 | Returns true if the email has been verified. | ||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | =head2 C<id( )> | ||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | UUID used to represent this user. | ||||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | =head2 C<first_name( )> | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | Legal first name of the account's owner. | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | =head2 C<last_name( )> | ||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | Legal last name of the account's owner. | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | =head2 C<username( )> | ||||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | The username used to log in to the account. | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | =cut | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | 1 | has ['email', 'email_verified', 'first_name', 'last_name', 'id', 'username']; | |||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | =head2 C<additional_info( )> | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | $user->additional_info(); | ||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | Returns a Finance::Robinhood::User::AdditionalInfo object. | ||||||||||||||||||
| 77 | |||||||||||||||||||
| 78 | =cut | ||||||||||||||||||
| 79 | |||||||||||||||||||
| 80 | 0 | ▶ | sub additional_info($s) { | ||||||||||||||||
|
Subroutine
additional_info: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 81 | 0 | my $res = $s->_rh->_get($s->{additional_info}); | |||||||||||||||||
| 82 | $_[0] = $res->is_success | ||||||||||||||||||
| 83 | ? Finance::Robinhood::User::AdditionalInfo->new(_rh => $s->_rh, | ||||||||||||||||||
| 84 | 0 | ▶ | %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 85 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 86 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 87 | } | ||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | 1 | ▶ | sub _test_additional_info { | ||||||||||||||||
|
Subroutine
_test_additional_info: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 90 | 1 | ▶ | t::Utility::stash('USER') // skip_all('No user object in stash'); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("USER") // skip_all("No user object in stash")
MC/DC0%0/2
t::Utility::stash("USER") // skip_all("No user object in stash")
t::Utility::stash("USER")
skip_all("No user object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("USER")B= skip_all("No user object in stash")
| |||||||||||||||||||
| 91 | 0 | isa_ok(t::Utility::stash('USER')->additional_info, | |||||||||||||||||
| 92 | 'Finance::Robinhood::User::AdditionalInfo'); | ||||||||||||||||||
| 93 | } | ||||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | =head2 C<basic_info( )> | ||||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | $user->basic_info(); | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | Returns a Finance::Robinhood::User::BasicInfo object. | ||||||||||||||||||
| 100 | |||||||||||||||||||
| 101 | =cut | ||||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | 0 | ▶ | sub basic_info($s) { | ||||||||||||||||
|
Subroutine
basic_info: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 104 | 0 | my $res = $s->_rh->_get($s->{basic_info}); | |||||||||||||||||
| 105 | $_[0] = $res->is_success | ||||||||||||||||||
| 106 | ? Finance::Robinhood::User::BasicInfo->new(_rh => $s->_rh, | ||||||||||||||||||
| 107 | 0 | ▶ | %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 108 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 109 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 110 | } | ||||||||||||||||||
| 111 | |||||||||||||||||||
| 112 | 1 | ▶ | sub _test_basic_info { | ||||||||||||||||
|
Subroutine
_test_basic_info: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 113 | 1 | ▶ | t::Utility::stash('USER') // skip_all('No user object in stash'); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("USER") // skip_all("No user object in stash")
MC/DC0%0/2
t::Utility::stash("USER") // skip_all("No user object in stash")
t::Utility::stash("USER")
skip_all("No user object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("USER")B= skip_all("No user object in stash")
| |||||||||||||||||||
| 114 | 0 | isa_ok(t::Utility::stash('USER')->basic_info, | |||||||||||||||||
| 115 | 'Finance::Robinhood::User::BasicInfo'); | ||||||||||||||||||
| 116 | } | ||||||||||||||||||
| 117 | |||||||||||||||||||
| 118 | =head2 C<created_at( )> | ||||||||||||||||||
| 119 | |||||||||||||||||||
| 120 | $user->created_at(); | ||||||||||||||||||
| 121 | |||||||||||||||||||
| 122 | Returns a Time::Moment object. | ||||||||||||||||||
| 123 | |||||||||||||||||||
| 124 | =cut | ||||||||||||||||||
| 125 | |||||||||||||||||||
| 126 | 0 | ▶ | sub created_at ($s) { | ||||||||||||||||
|
Subroutine
created_at: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 127 | 0 | Time::Moment->from_string($s->{created_at}); | |||||||||||||||||
| 128 | } | ||||||||||||||||||
| 129 | |||||||||||||||||||
| 130 | 1 | ▶ | sub _test_created_at { | ||||||||||||||||
|
Subroutine
_test_created_at: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 131 | 1 | ▶ | t::Utility::stash('USER') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("USER") // skip_all()
MC/DC0%0/2
t::Utility::stash("USER") // skip_all()
t::Utility::stash("USER")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("USER")B= skip_all()
| |||||||||||||||||||
| 132 | 0 | isa_ok(t::Utility::stash('USER')->created_at(), 'Time::Moment'); | |||||||||||||||||
| 133 | } | ||||||||||||||||||
| 134 | |||||||||||||||||||
| 135 | =head2 C<employment( )> | ||||||||||||||||||
| 136 | |||||||||||||||||||
| 137 | $user->employment(); | ||||||||||||||||||
| 138 | |||||||||||||||||||
| 139 | Returns a Finance::Robinhood::User::Employment object. | ||||||||||||||||||
| 140 | |||||||||||||||||||
| 141 | =cut | ||||||||||||||||||
| 142 | |||||||||||||||||||
| 143 | 0 | ▶ | sub employment($s) { | ||||||||||||||||
|
Subroutine
employment: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 144 | 0 | my $res = $s->_rh->_get($s->{employment}); | |||||||||||||||||
| 145 | $_[0] = $res->is_success | ||||||||||||||||||
| 146 | ? Finance::Robinhood::User::Employment->new(_rh => $s->_rh, | ||||||||||||||||||
| 147 | 0 | ▶ | %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 148 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 149 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 150 | } | ||||||||||||||||||
| 151 | |||||||||||||||||||
| 152 | 1 | ▶ | sub _test_employment { | ||||||||||||||||
|
Subroutine
_test_employment: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 153 | 1 | ▶ | t::Utility::stash('USER') // skip_all('No user object in stash'); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("USER") // skip_all("No user object in stash")
MC/DC0%0/2
t::Utility::stash("USER") // skip_all("No user object in stash")
t::Utility::stash("USER")
skip_all("No user object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("USER")B= skip_all("No user object in stash")
| |||||||||||||||||||
| 154 | 0 | isa_ok(t::Utility::stash('USER')->employment, | |||||||||||||||||
| 155 | 'Finance::Robinhood::User::Employment'); | ||||||||||||||||||
| 156 | } | ||||||||||||||||||
| 157 | |||||||||||||||||||
| 158 | =head2 C<id_info( )> | ||||||||||||||||||
| 159 | |||||||||||||||||||
| 160 | $user->id_info(); | ||||||||||||||||||
| 161 | |||||||||||||||||||
| 162 | Returns a Finance::Robinhood::User::IDInfo object. | ||||||||||||||||||
| 163 | |||||||||||||||||||
| 164 | =cut | ||||||||||||||||||
| 165 | |||||||||||||||||||
| 166 | 0 | ▶ | sub id_info($s) { | ||||||||||||||||
|
Subroutine
id_info: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 167 | 0 | my $res = $s->_rh->_get($s->{id_info}); | |||||||||||||||||
| 168 | $_[0] | ||||||||||||||||||
| 169 | = $res->is_success | ||||||||||||||||||
| 170 | 0 | ▶ | ? Finance::Robinhood::User::IDInfo->new(_rh => $s->_rh, %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 171 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 172 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 173 | } | ||||||||||||||||||
| 174 | |||||||||||||||||||
| 175 | 1 | ▶ | sub _test_id_info { | ||||||||||||||||
|
Subroutine
_test_id_info: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 176 | 1 | ▶ | t::Utility::stash('USER') // skip_all('No user object in stash'); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("USER") // skip_all("No user object in stash")
MC/DC0%0/2
t::Utility::stash("USER") // skip_all("No user object in stash")
t::Utility::stash("USER")
skip_all("No user object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("USER")B= skip_all("No user object in stash")
| |||||||||||||||||||
| 177 | 0 | isa_ok(t::Utility::stash('USER')->id_info, | |||||||||||||||||
| 178 | 'Finance::Robinhood::User::IDInfo'); | ||||||||||||||||||
| 179 | } | ||||||||||||||||||
| 180 | |||||||||||||||||||
| 181 | =head2 C<international_info( )> | ||||||||||||||||||
| 182 | |||||||||||||||||||
| 183 | $user->international_info(); | ||||||||||||||||||
| 184 | |||||||||||||||||||
| 185 | Returns a Finance::Robinhood::User::InternationalInfo object if the user is a | ||||||||||||||||||
| 186 | non-US citizen. | ||||||||||||||||||
| 187 | |||||||||||||||||||
| 188 | =cut | ||||||||||||||||||
| 189 | |||||||||||||||||||
| 190 | 0 | ▶ | sub international_info($s) { | ||||||||||||||||
|
Subroutine
international_info: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 191 | 0 | my $res = $s->_rh->_get($s->{international_info}); | |||||||||||||||||
| 192 | $_[0] = $res->is_success | ||||||||||||||||||
| 193 | ? Finance::Robinhood::User::InternationalInfo->new(_rh => $s->_rh, | ||||||||||||||||||
| 194 | 0 | ▶ | %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 195 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 196 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 197 | } | ||||||||||||||||||
| 198 | |||||||||||||||||||
| 199 | 1 | ▶ | sub _test_international_info { | ||||||||||||||||
|
Subroutine
_test_international_info: called CC=2 SCAR=10.5
| |||||||||||||||||||
| 200 | 1 | ▶ | t::Utility::stash('USER') // skip_all('No user object in stash'); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("USER") // skip_all("No user object in stash")
MC/DC0%0/2
t::Utility::stash("USER") // skip_all("No user object in stash")
t::Utility::stash("USER")
skip_all("No user object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("USER")B= skip_all("No user object in stash")
| |||||||||||||||||||
| 201 | todo( | ||||||||||||||||||
| 202 | 0 | ▶ | 'As a US citizen, this will fail for me' => sub { | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 203 | 0 | isa_ok(t::Utility::stash('USER')->international_info, | |||||||||||||||||
| 204 | 'Finance::Robinhood::User::InternationalInfo'); | ||||||||||||||||||
| 205 | } | ||||||||||||||||||
| 206 | 0 | ); | |||||||||||||||||
| 207 | } | ||||||||||||||||||
| 208 | |||||||||||||||||||
| 209 | =head2 C<profile( )> | ||||||||||||||||||
| 210 | |||||||||||||||||||
| 211 | $user->profile(); | ||||||||||||||||||
| 212 | |||||||||||||||||||
| 213 | Returns a Finance::Robinhood::User::Profile object. | ||||||||||||||||||
| 214 | |||||||||||||||||||
| 215 | =cut | ||||||||||||||||||
| 216 | |||||||||||||||||||
| 217 | 0 | ▶ | sub profile($s) { | ||||||||||||||||
|
Subroutine
profile: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 218 | 0 | my $res = $s->_rh->_get($s->{investment_profile}); | |||||||||||||||||
| 219 | $_[0] | ||||||||||||||||||
| 220 | = $res->is_success | ||||||||||||||||||
| 221 | ? Finance::Robinhood::User::Profile->new(_rh => $s->_rh, | ||||||||||||||||||
| 222 | 0 | ▶ | %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 223 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 224 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 225 | } | ||||||||||||||||||
| 226 | |||||||||||||||||||
| 227 | 1 | ▶ | sub _test_profile { | ||||||||||||||||
|
Subroutine
_test_profile: called CC=2 SCAR=10.5
| |||||||||||||||||||
| 228 | 1 | ▶ | t::Utility::stash('USER') // skip_all('No user object in stash'); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("USER") // skip_all("No user object in stash")
MC/DC0%0/2
t::Utility::stash("USER") // skip_all("No user object in stash")
t::Utility::stash("USER")
skip_all("No user object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("USER")B= skip_all("No user object in stash")
| |||||||||||||||||||
| 229 | todo( | ||||||||||||||||||
| 230 | 0 | ▶ | 'As a US citizen, this will fail for me' => sub { | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 231 | 0 | isa_ok(t::Utility::stash('USER')->profile, | |||||||||||||||||
| 232 | 'Finance::Robinhood::User::Profile'); | ||||||||||||||||||
| 233 | } | ||||||||||||||||||
| 234 | 0 | ); | |||||||||||||||||
| 235 | } | ||||||||||||||||||
| 236 | |||||||||||||||||||
| 237 | =head1 LEGAL | ||||||||||||||||||
| 238 | |||||||||||||||||||
| 239 | This is a simple wrapper around the API used in the official apps. The author | ||||||||||||||||||
| 240 | provides no investment, legal, or tax advice and is not responsible for any | ||||||||||||||||||
| 241 | damages incurred while using this software. This software is not affiliated | ||||||||||||||||||
| 242 | with Robinhood Financial LLC in any way. | ||||||||||||||||||
| 243 | |||||||||||||||||||
| 244 | For Robinhood's terms and disclosures, please see their website at | ||||||||||||||||||
| 245 | https://robinhood.com/legal/ | ||||||||||||||||||
| 246 | |||||||||||||||||||
| 247 | =head1 LICENSE | ||||||||||||||||||
| 248 | |||||||||||||||||||
| 249 | Copyright (C) Sanko Robinson. | ||||||||||||||||||
| 250 | |||||||||||||||||||
| 251 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||
| 252 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||||||||||||||||||
| 253 | conditions may apply to data transmitted through this module. Please refer to | ||||||||||||||||||
| 254 | the L<LEGAL> section. | ||||||||||||||||||
| 255 | |||||||||||||||||||
| 256 | =head1 AUTHOR | ||||||||||||||||||
| 257 | |||||||||||||||||||
| 258 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||
| 259 | |||||||||||||||||||
| 260 | =cut | ||||||||||||||||||
| 261 | |||||||||||||||||||
| 262 | 1 | 1; | |||||||||||||||||