File Coverage

lib/Finance/Robinhood/Notification.pm
Criterion Covered Total %
statement 18 49 36.7
branch 0 2 0.0
condition 4 14 28.5
subroutine 10 15 66.6
pod 4 4 100.0
total 36 84 42.8


line stmt bran cond sub pod time code
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             our $VERSION = '0.92_002';
23 1     1   5007 use Mojo::Base-base, -signatures;
  1         3  
  1         11  
24 1     1   372 use Mojo::URL;
  1         2  
  1         12  
25 1     1   28 use Time::Moment;
  1         2  
  1         192  
26              
27             sub _test__init {
28 1     1   8321 my $rh = t::Utility::rh_instance(1);
29 0         0 my $notifications = $rh->notifications;
30 0         0 my $notification;
31 0   0     0 do {
32 0         0 $notification = $notifications->next;
33             } while $notification && $notification->type ne 'referral_hook_asset_stock';
34 0   0     0 $notification // skip_all('Failed to fine executied equity order');
35 0         0 isa_ok( $notification, __PACKAGE__ );
36 0         0 t::Utility::stash( 'CARD', $notification ); # Store it for later
37             }
38              
39 1     1   9 use overload '""' => sub ( $s, @ ) { $s->{url} }, fallback => 1;
  1     0   2  
  1         11  
  0         0  
  0         0  
  0         0  
  0         0  
40              
41             sub _test_stringify {
42 1   50 1   1882 t::Utility::stash('CARD') // skip_all();
43 0         0 like(
44             +t::Utility::stash('CARD'),
45             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
46             );
47             }
48             #
49             has _rh => undef => weak => 1;
50              
51             =head2 C
52              
53             Text provided to direct attention to the action. C, C,
54             etc.
55              
56             =head2 C
57              
58             If true, this notification is locked into place.
59              
60             =head2 C
61              
62             For display, this sets a uniform type size.
63              
64             =head2 C
65              
66             Returns which icon should be used. These are built into the apps, btw.
67              
68             =head2 C
69              
70             The actual text shown in the notification card.
71              
72             =head2 C
73              
74              
75             =head2 C
76              
77             Returns a hash with asset information for the official clients.
78              
79             =head2 C
80              
81             Returns the type of notification.
82              
83             =head2 C
84              
85             Returns the article's title.
86              
87             =head2 C
88              
89             What sort of notification is is. C, C, etc.
90              
91             =cut
92              
93             has [
94             'call_to_action', 'fixed', 'font_size', 'icon', 'message', 'show_if_unsupported',
95             'side_image', 'title', 'type'
96             ];
97              
98             =head2 C
99              
100             Returns the (usually app internal) action that should take place when the
101             notification is activated.
102              
103             =cut
104              
105 0     0 1 0 sub action($s) {
  0         0  
  0         0  
106 0         0 Mojo::URL->new( $s->{action} );
107             }
108              
109             sub _test_action {
110 1   50 1   2076 t::Utility::stash('CARD') // skip_all();
111 0         0 isa_ok( t::Utility::stash('CARD')->action, 'Mojo::URL' );
112             }
113              
114             =head2 C
115              
116             $notification->time->to_string;
117              
118             Returns the time the notification was published as a Time::Moment object.
119              
120             Note that some notifications do not have a timestamp.
121              
122             =cut
123              
124 0     0 1 0 sub time($s) {
  0         0  
  0         0  
125 0 0       0 $s->{time} ? Time::Moment->from_string( $s->{time} ) : ();
126             }
127              
128             sub _test_time {
129 1   50 1   1837 t::Utility::stash('CARD') // skip_all();
130 0         0 isa_ok( t::Utility::stash('CARD')->time, 'Time::Moment' );
131             }
132              
133             =head2 C
134              
135             $notification->dismiss();
136              
137             Marks the notification as read and hides it from the stack.
138              
139             =cut
140              
141 0     0 1 0 sub dismiss ($s) {
  0         0  
  0         0  
142 0         0 $s->_rh->_post( $s->{url} . 'dismiss/' )->is_success;
143             }
144              
145             sub _test_dismiss { # I'd rather not mark a notification as read...
146 1     1   1828 skip_all();
147             }
148              
149             =head2 C
150              
151             Returns a UUID.
152              
153             =cut
154              
155 0     0 1 0 sub id($s) {
  0         0  
  0         0  
156             $s->{url}
157 0         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;
158             }
159              
160             sub _test_id {
161 1   50 1   1822 t::Utility::stash('CARD') // skip_all();
162 0           like(
163             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 section.
186              
187             =head1 AUTHOR
188              
189             Sanko Robinson Esanko@cpan.orgE
190              
191             =cut
192              
193             1;