lib/Finance/Robinhood/Notification.pm

filter: Statementstmt 57.8% 22 / 38 Branchbran 0.0% 0 / 4 Conditioncond 28.5% 4 / 14 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 66.6% 10 / 15 Podpod 100% 4 / 4 totaltotal 45.9% 40 / 87 CC 9 SCAR 15.9
CC
9
Cov
46%
_test__init
17.2
time
6.0
_test_stringify
2.5
CRAP 4.9
« lib/Finance/Robinhood/Equity/Account.pm ↑ Summary lib/Finance/Robinhood/News.pm »
1 package Finance::Robinhood::Notification;
2  
3 =encoding utf-8
4  
5 =for stopwords watchlist watchlists untradable urls btw
6  
7 =head1 NAME
8  
9 Finance::Robinhood::Notification - Represents a Single Notification Card
10  
11 =head1 SYNOPSIS
12  
13 use Text::Wrap qw[wrap];
14 use Finance::Robinhood;
15 my $rh = Finance::Robinhood->new;
16 CORE::say wrap( '', ' ', $_->title . "\n" . $_->message ) for $rh->notifications->take(10);
17  
18 =head1 METHODS
19  
20 =cut
21  
22 1 our $VERSION = '0.92_003';
23 1 ▶use Mojo::Base-base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶sub _test__init {
Subroutine _test__init: called CC=4 SCAR=28.4
28 1 my $rh = t::Utility::rh_instance(1);
29 0 my $notifications = $rh->notifications;
30 0 my $notification;
31 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$notification and $notification->type ne "referral_hook_asset_stock" and do { do { $notification = $notifications->next } } 0 0 0
Condition0%0/3
$notification and $notification->type ne "referral_hook_asset_stock"
!ll&&!rl&&r
000
MC/DC0%0/2
$notification and $notification->type ne "referral_hook_asset_stock"
$notification $notification->type ne "referral_hook_asset_stock"
Truth table0%0/3
A and B
A= $notificationB= $notification->type ne "referral_hook_asset_stock"
ABresult
0X0
100
111
32 0 $notification = $notifications->next;
33 } while $notification &&
34 $notification->type ne 'referral_hook_asset_stock';
35 0 ▶ $notification // skip_all('Failed to fine executied equity order');
Condition0%0/3
$notification // skip_all("Failed to fine executied equity order")
l!l&&r!l&&!r
000
MC/DC0%0/2
$notification // skip_all("Failed to fine executied equity order")
$notification skip_all("Failed to fine executied equity order")
Truth table0%0/3
A // B
A= $notificationB= skip_all("Failed to fine executied equity order")
ABresult
1X1
011
000
36 0 isa_ok($notification, __PACKAGE__);
37 0 t::Utility::stash('CARD', $notification); # Store it for later
38 }
39 0 ▶use overload '""' => sub ($s, @) { $s->{url} }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
40  
41 1 ▶sub _test_stringify {
Subroutine _test_stringify: called CC=2 SCAR=9.2
42 1 ▶ t::Utility::stash('CARD') // skip_all();
Condition50%1/2
t::Utility::stash("CARD") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("CARD") // skip_all()
t::Utility::stash("CARD") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("CARD")B= skip_all()
ABresult
1X1
011
000
43 0 like(+t::Utility::stash('CARD'),
44 qr'^https://midlands.robinhood.com/notifications/stack/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/$'i
45 );
46 }
47 #
48 1 has _rh => undef => weak => 1;
49  
50 =head2 C<call_to_action( )>
51  
52 Text provided to direct attention to the action. C<See More>, C<View Article>,
53 etc.
54  
55 =head2 C<fixed( )>
56  
57 If true, this notification is locked into place.
58  
59 =head2 C<font_size( )>
60  
61 For display, this sets a uniform type size.
62  
63 =head2 C<icon( )>
64  
65 Returns which icon should be used. These are built into the apps, btw.
66  
67 =head2 C<message( )>
68  
69 The actual text shown in the notification card.
70  
71 =head2 C<show_if_unsupported( )>
72  
73  
74 =head2 C<side_image( )>
75  
76 Returns a hash with asset information for the official clients.
77  
78 =head2 C<type( )>
79  
80 Returns the type of notification.
81  
82 =head2 C<title( )>
83  
84 Returns the article's title.
85  
86 =head2 C<type( )>
87  
88 What sort of notification is is. C<news>, C<top_sp500_gainers>, etc.
89  
90 =cut
91  
92 1 has ['call_to_action', 'fixed',
93 'font_size', 'icon',
94 'message', 'show_if_unsupported',
95 'side_image', 'title',
96 'type'
97 ];
98  
99 =head2 C<action( )>
100  
101 Returns the (usually app internal) action that should take place when the
102 notification is activated.
103  
104 =cut
105  
106 0 ▶sub action($s) {
Subroutine action: not called CC=1 SCAR=6.9
Pod documented
107 0 Mojo::URL->new($s->{action});
108 }
109  
110 1 ▶sub _test_action {
Subroutine _test_action: called CC=2 SCAR=9.2
111 1 ▶ t::Utility::stash('CARD') // skip_all();
Condition50%1/2
t::Utility::stash("CARD") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("CARD") // skip_all()
t::Utility::stash("CARD") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("CARD")B= skip_all()
ABresult
1X1
011
000
112 0 isa_ok(t::Utility::stash('CARD')->action, 'Mojo::URL');
113 }
114  
115 =head2 C<time( )>
116  
117 $notification->time->to_string;
118  
119 Returns the time the notification was published as a Time::Moment object.
120  
121 Note that some notifications do not have a timestamp.
122  
123 =cut
124  
125 0 ▶sub time($s) {
Subroutine time: not called CC=2 SCAR=17.9
Pod documented
126 0 ▶ $s->{time} ? Time::Moment->from_string($s->{time}) : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'time'} ? : 0 0 0
127 }
128  
129 1 ▶sub _test_time {
Subroutine _test_time: called CC=2 SCAR=9.2
130 1 ▶ t::Utility::stash('CARD') // skip_all();
Condition50%1/2
t::Utility::stash("CARD") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("CARD") // skip_all()
t::Utility::stash("CARD") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("CARD")B= skip_all()
ABresult
1X1
011
000
131 0 isa_ok(t::Utility::stash('CARD')->time, 'Time::Moment');
132 }
133  
134 =head2 C<dismiss( )>
135  
136 $notification->dismiss();
137  
138 Marks the notification as read and hides it from the stack.
139  
140 =cut
141  
142 0 ▶sub dismiss ($s) {
Subroutine dismiss: not called CC=1 SCAR=6.9
Pod documented
143 0 $s->_rh->_post($s->{url} . 'dismiss/')->is_success;
144 }
145  
146 1 ▶sub _test_dismiss { # I'd rather not mark a notification as read...
Subroutine _test_dismiss: called CC=1 SCAR=0.0
147 1 skip_all();
148 }
149  
150 =head2 C<id( )>
151  
152 Returns a UUID.
153  
154 =cut
155  
156 0 ▶sub id($s) {
Subroutine id: not called CC=1 SCAR=6.9
Pod documented
157 $s->{url}
158 0 =~ m'^.+/([0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12})/$'i;
159 }
160  
161 1 ▶sub _test_id {
Subroutine _test_id: called CC=2 SCAR=9.2
162 1 ▶ t::Utility::stash('CARD') // skip_all();
Condition50%1/2
t::Utility::stash("CARD") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("CARD") // skip_all()
t::Utility::stash("CARD") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("CARD")B= skip_all()
ABresult
1X1
011
000
163 0 like(t::Utility::stash('CARD')->id,
164 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
165 );
166 }
167  
168 =head1 LEGAL
169  
170 This is a simple wrapper around the API used in the official apps. The author
171 provides no investment, legal, or tax advice and is not responsible for any
172 damages incurred while using this software. This software is not affiliated
173 with Robinhood Financial LLC in any way.
174  
175 For Robinhood's terms and disclosures, please see their website at
176 https://robinhood.com/legal/
177  
178 =head1 LICENSE
179  
180 Copyright (C) Sanko Robinson.
181  
182 This library is free software; you can redistribute it and/or modify it under
183 the terms found in the Artistic License 2. Other copyrights, terms, and
184 conditions may apply to data transmitted through this module. Please refer to
185 the L<LEGAL> section.
186  
187 =head1 AUTHOR
188  
189 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
190  
191 =cut
192  
193 1 1;
« lib/Finance/Robinhood/Equity/Account.pm ↑ Summary lib/Finance/Robinhood/News.pm »