File Coverage

lib/Finance/Robinhood/News.pm
Criterion Covered Total %
statement 17 64 26.5
branch 0 10 0.0
condition 7 23 30.4
subroutine 11 18 61.1
pod 6 7 85.7
total 41 122 33.6


line stmt bran cond sub pod time code
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             our $VERSION = '0.92_003';
23              
24             sub _test__init {
25 1     1   12580 my $rh = t::Utility::rh_instance(1);
26 0         0 my $msft = $rh->news('MSFT')->current;
27 0         0 my $btc = $rh->news('d674efea-e623-4396-9026-39574b92b093')->current;
28 0         0 isa_ok($msft, __PACKAGE__);
29 0         0 t::Utility::stash('MSFT', $msft); # Store it for later
30 0         0 isa_ok($btc, __PACKAGE__);
31 0         0 t::Utility::stash('BTC', $btc); # Store it for later
32             }
33 1     1   9 use Mojo::Base-base, -signatures;
  1         2  
  1         13  
34 1     1   313 use Mojo::URL;
  1         2  
  1         7  
35 1     1   29 use Time::Moment;
  1         3  
  1         754  
36             #
37             has _rh => undef => weak => 1;
38              
39             =head2 C
40              
41             Returns the article's source.
42              
43             =head2 C
44              
45             If available, this will return the author who wrote the article.
46              
47             =head2 C
48              
49             The current total number of times this article has been clicked by Robinhod's
50             users.
51              
52             =head2 C
53              
54             Returns the article's source in a format suited for display.
55              
56             =head2 C
57              
58             Returns a brief (often truncated) summary of the article.
59              
60             =head2 C
61              
62             Returns the article's title.
63              
64             =head2 C
65              
66             Returns the article's unique ID.
67              
68             =cut
69              
70             has ['api_source', 'author', 'num_clicks', 'source',
71             'summary', 'title', 'uuid'
72             ];
73              
74             =head2 C
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     0 1 0 sub preview_image_url($s) {
  0         0  
  0         0  
82 0 0       0 $s->{preview_image_url} ? Mojo::URL->new($s->{preview_image_url}) : ();
83             }
84              
85             sub _test_preview_image_url {
86 1   50 1   1866 t::Utility::stash('MSFT') // skip_all();
87 0         0 isa_ok(t::Utility::stash('MSFT')->preview_image_url, 'Mojo::URL');
88 0   0     0 t::Utility::stash('BTC') // skip_all();
89 0         0 isa_ok(t::Utility::stash('BTC')->preview_image_url, 'Mojo::URL');
90             }
91              
92             =head2 C
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     0 1 0 sub relay_url($s) {
  0         0  
  0         0  
100 0 0       0 $s->{relay_url} ? Mojo::URL->new($s->{relay_url}) : ();
101             }
102              
103             sub _test_relay_url {
104 1   50 1   1850 t::Utility::stash('MSFT') // skip_all();
105 0         0 isa_ok(t::Utility::stash('MSFT')->relay_url, 'Mojo::URL');
106 0   0     0 t::Utility::stash('BTC') // skip_all();
107 0         0 isa_ok(t::Utility::stash('BTC')->relay_url, 'Mojo::URL');
108             }
109              
110             =head2 C
111              
112             Mojo::URL object containing a direct link to the article.
113              
114             =cut
115              
116 0     0 1 0 sub url($s) {
  0         0  
  0         0  
117 0 0       0 $s->{url} ? Mojo::URL->new($s->{url}) : ();
118             }
119              
120             sub _test_url {
121 1   50 1   1841 t::Utility::stash('MSFT') // skip_all();
122 0         0 isa_ok(t::Utility::stash('MSFT')->url, 'Mojo::URL');
123 0   0     0 t::Utility::stash('BTC') // skip_all();
124 0         0 isa_ok(t::Utility::stash('BTC')->url, 'Mojo::URL');
125             }
126              
127             =head2 C
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     0 0 0 sub currency($s) {
  0         0  
  0         0  
135 0 0       0 $s->{currency_id} ? $s->_rh->forex_currency_by_id($s->{currency_id}) : ();
136             }
137              
138             sub _test_currency {
139 1   50 1   2042 t::Utility::stash('BTC') // skip_all();
140 0         0 isa_ok(t::Utility::stash('BTC')->currency,
141             'Finance::Robinhood::Forex::Currency');
142             }
143              
144             =head2 C
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     0 1 0 sub instrument($s) {
  0         0  
  0         0  
152             $s->{instrument}
153             ? $s->_rh->equity_instruments_by_id($s->{instrument}
154 0 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
155             )
156             : ();
157             }
158              
159             sub _test_instrument {
160 1   50 1   1893 t::Utility::stash('MSFT') // skip_all();
161 0         0 isa_ok(t::Utility::stash('MSFT')->instrument,
162             'Finance::Robinhood::Equity::Instrument');
163             }
164              
165             =head2 C
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     0 1 0 sub published_at($s) {
  0         0  
  0         0  
174 0         0 Time::Moment->from_string($s->{published_at});
175             }
176              
177             sub _test_published_at {
178 1   50 1   1883 t::Utility::stash('MSFT') // skip_all();
179 0         0 isa_ok(t::Utility::stash('MSFT')->published_at, 'Time::Moment');
180             }
181              
182             =head2 C
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     0 1 0 sub updated_at($s) {
  0         0  
  0         0  
192 0         0 Time::Moment->from_string($s->{updated_at});
193             }
194              
195             sub _test_updated_at {
196 1   50 1   1867 t::Utility::stash('MSFT') // skip_all();
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 section.
218              
219             =head1 AUTHOR
220              
221             Sanko Robinson Esanko@cpan.orgE
222              
223             =cut
224              
225             1;