lib/Finance/Robinhood/News.pm

filter: Statementstmt 44.6% 21 / 47 Branchbran 0.0% 0 / 10 Conditioncond 30.4% 7 / 23 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 61.1% 11 / 18 Podpod 85.7% 6 / 7 totaltotal 36.0% 45 / 125 CC 16 SCAR 15.4
CC
16
Cov
35%
_test_preview_image_url
7.2
_test_relay_url
7.2
_test_url
7.2
CRAP 4.7
« lib/Finance/Robinhood/Notification.pm ↑ Summary lib/Finance/Robinhood/Equity/Prices.pm »
1 package Finance::Robinhood::News;
2  
3 =encoding utf-8
4  
5 =for stopwords watchlist watchlists untradable urls
6  
7 =head1 NAME
8  
9 Finance::Robinhood::News - Represents a Single News Article
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" . $_->summary ) for $rh->news('TSLA')->take(10);
17  
18 =head1 METHODS
19  
20 =cut
21  
22 1 our $VERSION = '0.92_003';
23  
24 1 ▶sub _test__init {
Subroutine _test__init: called CC=1 SCAR=4.9
25 1 my $rh = t::Utility::rh_instance(1);
26 0 my $msft = $rh->news('MSFT')->current;
27 0 my $btc = $rh->news('d674efea-e623-4396-9026-39574b92b093')->current;
28 0 isa_ok($msft, __PACKAGE__);
29 0 t::Utility::stash('MSFT', $msft); # Store it for later
30 0 isa_ok($btc, __PACKAGE__);
31 0 t::Utility::stash('BTC', $btc); # Store it for later
32 }
33 1 ▶use Mojo::Base-base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 1 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 #
37 1 has _rh => undef => weak => 1;
38  
39 =head2 C<api_source( )>
40  
41 Returns the article's source.
42  
43 =head2 C<author( )>
44  
45 If available, this will return the author who wrote the article.
46  
47 =head2 C<num_clicks( )>
48  
49 The current total number of times this article has been clicked by Robinhod's
50 users.
51  
52 =head2 C<source( )>
53  
54 Returns the article's source in a format suited for display.
55  
56 =head2 C<summary( )>
57  
58 Returns a brief (often truncated) summary of the article.
59  
60 =head2 C<title( )>
61  
62 Returns the article's title.
63  
64 =head2 C<uuid( )>
65  
66 Returns the article's unique ID.
67  
68 =cut
69  
70 1 has ['api_source', 'author', 'num_clicks', 'source',
71 'summary', 'title', 'uuid'
72 ];
73  
74 =head2 C<preview_image_url( )>
75  
76 If this article has a thumbnail, this will return the URL as a Mojo::Url
77 object.
78  
79 =cut
80  
81 0 ▶sub preview_image_url($s) {
Subroutine preview_image_url: not called CC=2 SCAR=17.9
Pod documented
82 0 ▶ $s->{preview_image_url} ? Mojo::URL->new($s->{preview_image_url}) : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'preview_image_url'} ? : 0 0 0
83 }
84  
85 1 ▶sub _test_preview_image_url {
Subroutine _test_preview_image_url: called CC=3 SCAR=19.8
86 1 ▶ t::Utility::stash('MSFT') // skip_all();
Condition50%1/2
t::Utility::stash("MSFT") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("MSFT") // skip_all()
t::Utility::stash("MSFT") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MSFT")B= skip_all()
ABresult
1X1
011
000
87 0 isa_ok(t::Utility::stash('MSFT')->preview_image_url, 'Mojo::URL');
88 0 ▶ t::Utility::stash('BTC') // skip_all();
Condition0%0/3
t::Utility::stash("BTC") // skip_all()
l!l&&r!l&&!r
000
MC/DC0%0/2
t::Utility::stash("BTC") // skip_all()
t::Utility::stash("BTC") skip_all()
Truth table0%0/3
A // B
A= t::Utility::stash("BTC")B= skip_all()
ABresult
1X1
011
000
89 0 isa_ok(t::Utility::stash('BTC')->preview_image_url, 'Mojo::URL');
90 }
91  
92 =head2 C<relay_url( )>
93  
94 Returns a Mojo::URL object containing the URL Robinhood would like you to use.
95 This will register as a click and will then redirect to the article itself.
96  
97 =cut
98  
99 0 ▶sub relay_url($s) {
Subroutine relay_url: not called CC=2 SCAR=17.9
Pod documented
100 0 ▶ $s->{relay_url} ? Mojo::URL->new($s->{relay_url}) : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'relay_url'} ? : 0 0 0
101 }
102  
103 1 ▶sub _test_relay_url {
Subroutine _test_relay_url: called CC=3 SCAR=19.8
104 1 ▶ t::Utility::stash('MSFT') // skip_all();
Condition50%1/2
t::Utility::stash("MSFT") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("MSFT") // skip_all()
t::Utility::stash("MSFT") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MSFT")B= skip_all()
ABresult
1X1
011
000
105 0 isa_ok(t::Utility::stash('MSFT')->relay_url, 'Mojo::URL');
106 0 ▶ t::Utility::stash('BTC') // skip_all();
Condition0%0/3
t::Utility::stash("BTC") // skip_all()
l!l&&r!l&&!r
000
MC/DC0%0/2
t::Utility::stash("BTC") // skip_all()
t::Utility::stash("BTC") skip_all()
Truth table0%0/3
A // B
A= t::Utility::stash("BTC")B= skip_all()
ABresult
1X1
011
000
107 0 isa_ok(t::Utility::stash('BTC')->relay_url, 'Mojo::URL');
108 }
109  
110 =head2 C<url( )>
111  
112 Mojo::URL object containing a direct link to the article.
113  
114 =cut
115  
116 0 ▶sub url($s) {
Subroutine url: not called CC=2 SCAR=17.9
Pod documented
117 0 ▶ $s->{url} ? Mojo::URL->new($s->{url}) : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'url'} ? : 0 0 0
118 }
119  
120 1 ▶sub _test_url {
Subroutine _test_url: called CC=3 SCAR=19.8
121 1 ▶ t::Utility::stash('MSFT') // skip_all();
Condition50%1/2
t::Utility::stash("MSFT") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("MSFT") // skip_all()
t::Utility::stash("MSFT") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MSFT")B= skip_all()
ABresult
1X1
011
000
122 0 isa_ok(t::Utility::stash('MSFT')->url, 'Mojo::URL');
123 0 ▶ t::Utility::stash('BTC') // skip_all();
Condition0%0/3
t::Utility::stash("BTC") // skip_all()
l!l&&r!l&&!r
000
MC/DC0%0/2
t::Utility::stash("BTC") // skip_all()
t::Utility::stash("BTC") skip_all()
Truth table0%0/3
A // B
A= t::Utility::stash("BTC")B= skip_all()
ABresult
1X1
011
000
124 0 isa_ok(t::Utility::stash('BTC')->url, 'Mojo::URL');
125 }
126  
127 =head2 C<currency_id( )>
128  
129 If the news is related to a particular forex currency, this will return the
130 Finance::Robinhood::Forex::Currency object.
131  
132 =cut
133  
134 0 ▶sub currency($s) {
Subroutine currency: not called CC=2 SCAR=17.9
Pod undocumented
135 0 ▶ $s->{currency_id} ? $s->_rh->forex_currency_by_id($s->{currency_id}) : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'currency_id'} ? : 0 0 0
136 }
137  
138 1 ▶sub _test_currency {
Subroutine _test_currency: called CC=2 SCAR=9.2
139 1 ▶ t::Utility::stash('BTC') // skip_all();
Condition50%1/2
t::Utility::stash("BTC") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("BTC") // skip_all()
t::Utility::stash("BTC") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("BTC")B= skip_all()
ABresult
1X1
011
000
140 0 isa_ok(t::Utility::stash('BTC')->currency,
141 'Finance::Robinhood::Forex::Currency');
142 }
143  
144 =head2 C<instrument( )>
145  
146 If the new is related to a particular equity instrument, this will return the
147 Finance::Robihood::Equity::Instrument object.
148  
149 =cut
150  
151 0 ▶sub instrument($s) {
Subroutine instrument: not called CC=2 SCAR=17.9
Pod documented
152 $s->{instrument}
153 ? $s->_rh->equity_instruments_by_id($s->{instrument}
154 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
Branch: 1 branch
BranchTrueFalseTotal
$s->{'instrument'} ? : 0 0 0
155 )
156 : ();
157 }
158  
159 1 ▶sub _test_instrument {
Subroutine _test_instrument: called CC=2 SCAR=9.2
160 1 ▶ t::Utility::stash('MSFT') // skip_all();
Condition50%1/2
t::Utility::stash("MSFT") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("MSFT") // skip_all()
t::Utility::stash("MSFT") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MSFT")B= skip_all()
ABresult
1X1
011
000
161 0 isa_ok(t::Utility::stash('MSFT')->instrument,
162 'Finance::Robinhood::Equity::Instrument');
163 }
164  
165 =head2 C<published_at( )>
166  
167 $article->published_at->to_string;
168  
169 Returns the time the article was published as a Time::Moment object.
170  
171 =cut
172  
173 0 ▶sub published_at($s) {
Subroutine published_at: not called CC=1 SCAR=6.9
Pod documented
174 0 Time::Moment->from_string($s->{published_at});
175 }
176  
177 1 ▶sub _test_published_at {
Subroutine _test_published_at: called CC=2 SCAR=9.2
178 1 ▶ t::Utility::stash('MSFT') // skip_all();
Condition50%1/2
t::Utility::stash("MSFT") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("MSFT") // skip_all()
t::Utility::stash("MSFT") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MSFT")B= skip_all()
ABresult
1X1
011
000
179 0 isa_ok(t::Utility::stash('MSFT')->published_at, 'Time::Moment');
180 }
181  
182 =head2 C<updated_at( )>
183  
184 $article->updated_at->to_string;
185  
186 Returns the time the article was published or last updated as a Time::Moment
187 object.
188  
189 =cut
190  
191 0 ▶sub updated_at($s) {
Subroutine updated_at: not called CC=1 SCAR=6.9
Pod documented
192 0 Time::Moment->from_string($s->{updated_at});
193 }
194  
195 1 ▶sub _test_updated_at {
Subroutine _test_updated_at: called CC=2 SCAR=9.2
196 1 ▶ t::Utility::stash('MSFT') // skip_all();
Condition50%1/2
t::Utility::stash("MSFT") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("MSFT") // skip_all()
t::Utility::stash("MSFT") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MSFT")B= skip_all()
ABresult
1X1
011
000
197 0 isa_ok(t::Utility::stash('MSFT')->updated_at, 'Time::Moment');
198 }
199  
200 =head1 LEGAL
201  
202 This is a simple wrapper around the API used in the official apps. The author
203 provides no investment, legal, or tax advice and is not responsible for any
204 damages incurred while using this software. This software is not affiliated
205 with Robinhood Financial LLC in any way.
206  
207 For Robinhood's terms and disclosures, please see their website at
208 https://robinhood.com/legal/
209  
210 =head1 LICENSE
211  
212 Copyright (C) Sanko Robinson.
213  
214 This library is free software; you can redistribute it and/or modify it under
215 the terms found in the Artistic License 2. Other copyrights, terms, and
216 conditions may apply to data transmitted through this module. Please refer to
217 the L<LEGAL> section.
218  
219 =head1 AUTHOR
220  
221 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
222  
223 =cut
224  
225 1 1;
« lib/Finance/Robinhood/Notification.pm ↑ Summary lib/Finance/Robinhood/Equity/Prices.pm »