lib/Finance/Robinhood/Forex/Watchlist.pm

filter: Statementstmt 55.2% 21 / 38 Branchbran 0.0% 0 / 6 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 69.2% 9 / 13 Podpod 100% 3 / 3 totaltotal 48.6% 37 / 76 CC 8 SCAR 17.2
CC
8
Cov
48%
pair_ids
20.0
_test_pair_ids
3.2
_test_stringify
2.5
CRAP 5.6
« lib/Finance/Robinhood/User.pm ↑ Summary lib/Finance/Robinhood/Equity/Fundamentals.pm »
1 package Finance::Robinhood::Forex::Watchlist;
2  
3 =encoding utf-8
4  
5 =for stopwords watchlist watchlists untradable urls
6  
7 =head1 NAME
8  
9 Finance::Robinhood::Forex::Watchlist - Represents a Single Forex/Crypto
10 Watchlist
11  
12 =head1 SYNOPSIS
13  
14 use Finance::Robinhood;
15 my $rh = Finance::Robinhood->new;
16  
17 # TODO
18  
19 =cut
20  
21 1 our $VERSION = '0.92_003';
22 1 ▶use Mojo::Base-base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 ▶sub _test__init {
Subroutine _test__init: called CC=1 SCAR=3.5
27 1 my $rh = t::Utility::rh_instance(1);
28 0 my $watchlist = $rh->forex_watchlists->current;
29 0 isa_ok($watchlist, __PACKAGE__);
30 0 t::Utility::stash('WATCHLIST', $watchlist); # Store it for later
31 }
32 0 ▶use overload '""' => sub ($s, @) { $s->{id} }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
33  
34 1 ▶sub _test_stringify {
Subroutine _test_stringify: called CC=2 SCAR=9.2
35 1 ▶ t::Utility::stash('WATCHLIST') // skip_all();
Condition50%1/2
t::Utility::stash("WATCHLIST") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("WATCHLIST") // skip_all()
t::Utility::stash("WATCHLIST") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("WATCHLIST")B= skip_all()
ABresult
1X1
011
000
36 0 like(+t::Utility::stash('WATCHLIST'),
37 qr'^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'i
38 );
39 }
40 #
41 1 has _rh => undef => weak => 1;
42  
43 =head1 METHODS
44  
45 =head2 C<created_at( )>
46  
47 Returns a Time::Moment object.
48  
49 =head2 C<id( )>
50  
51 Returns a UUID.
52  
53 =head2 C<name( )>
54  
55  
56  
57 =head2 C<updated_at( )>
58  
59 Returns a Time::Moment object.
60  
61 =cut
62  
63 1 has ['id', 'name'];
64  
65 0 ▶sub created_at ($s) {
Subroutine created_at: not called CC=1 SCAR=6.9
Pod documented
66 0 Time::Moment->from_string($s->{created_at});
67 }
68  
69 1 ▶sub _test_created_at {
Subroutine _test_created_at: called CC=2 SCAR=9.2
70 1 ▶ t::Utility::stash('WATCHLIST') // skip_all();
Condition50%1/2
t::Utility::stash("WATCHLIST") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("WATCHLIST") // skip_all()
t::Utility::stash("WATCHLIST") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("WATCHLIST")B= skip_all()
ABresult
1X1
011
000
71 0 isa_ok(t::Utility::stash('WATCHLIST')->created_at, 'Time::Moment');
72 }
73  
74 0 ▶sub updated_at ($s) {
Subroutine updated_at: not called CC=1 SCAR=6.9
Pod documented
75 0 Time::Moment->from_string($s->{updated_at});
76 }
77  
78 1 ▶sub _test_updated_at {
Subroutine _test_updated_at: called CC=2 SCAR=9.2
79 1 ▶ t::Utility::stash('WATCHLIST') // skip_all();
Condition50%1/2
t::Utility::stash("WATCHLIST") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("WATCHLIST") // skip_all()
t::Utility::stash("WATCHLIST") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("WATCHLIST")B= skip_all()
ABresult
1X1
011
000
80 0 isa_ok(t::Utility::stash('WATCHLIST')->updated_at, 'Time::Moment');
81 }
82  
83 =head2 C<pair_ids( [...] )>
84  
85 $watchlist->pair_ids( )
86  
87 Returns a list of UUIDs.
88  
89 $watchlist->pair_ids(
90 "76637d50-c702-4ed1-bcb5-5b0732a81f48",
91 "3d961844-d360-45fc-989b-f6fca761d511" );
92  
93 Updates the watchlist with a list of currency pairs.
94  
95 =cut
96  
97 0 ▶sub pair_ids ($s, @ids) {
Subroutine pair_ids: not called CC=4 SCAR=30.0
Pod documented
98 0 ▶ return $s->{pair_ids} if !@ids;
Branch: 1 branch
BranchTrueFalseTotal
unless @ids 0 0 0
99 my $res
100 = $s->_rh->_patch(
101 0 'https://nummus.robinhood.com/watchlists/' . $s->{id} . '/',
102 pair_ids => @ids);
103 return $_[0]
104 = Finance::Robinhood::Forex::Watchlist->new(_rh => $s->_rh,
105 0 ▶ %{$res->json}
Branch: 1 branch
BranchTrueFalseTotal
if $res->is_success 0 0 0
106 ) if $res->is_success;
107 0 ▶ Finance::Robinhood::Error->new(
Branch: 1 branch
BranchTrueFalseTotal
$res->is_server_error ? : 0 0 0
108 $res->is_server_error ? (details => $res->message) : $res->json);
109 }
110  
111 1 ▶sub _test_pair_ids {
Subroutine _test_pair_ids: called CC=2 SCAR=11.6
112 1 ▶ t::Utility::stash('WATCHLIST') // skip_all();
Condition50%1/2
t::Utility::stash("WATCHLIST") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("WATCHLIST") // skip_all()
t::Utility::stash("WATCHLIST") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("WATCHLIST")B= skip_all()
ABresult
1X1
011
000
113 0 my @ids = t::Utility::stash('WATCHLIST')->pair_ids;
114 0 ok(t::Utility::stash('WATCHLIST')->pair_ids(reverse @ids));
115 0 is(t::Utility::stash('WATCHLIST')->pair_ids(), reverse @ids);
116 }
117  
118 =head1 LEGAL
119  
120 This is a simple wrapper around the API used in the official apps. The author
121 provides no investment, legal, or tax advice and is not responsible for any
122 damages incurred while using this software. This software is not affiliated
123 with Robinhood Financial LLC in any way.
124  
125 For Robinhood's terms and disclosures, please see their website at
126 https://robinhood.com/legal/
127  
128 =head1 LICENSE
129  
130 Copyright (C) Sanko Robinson.
131  
132 This library is free software; you can redistribute it and/or modify it under
133 the terms found in the Artistic License 2. Other copyrights, terms, and
134 conditions may apply to data transmitted through this module. Please refer to
135 the L<LEGAL> section.
136  
137 =head1 AUTHOR
138  
139 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
140  
141 =cut
142  
143 1 1;
« lib/Finance/Robinhood/User.pm ↑ Summary lib/Finance/Robinhood/Equity/Fundamentals.pm »