File Coverage

lib/Finance/Robinhood/Equity/Mover.pm
Criterion Covered Total %
statement 20 46 43.4
branch 0 4 0.0
condition 4 8 50.0
subroutine 10 14 71.4
pod 3 3 100.0
total 37 75 49.3


line stmt bran cond sub pod time code
1             package Finance::Robinhood::Equity::Mover;
2              
3             =encoding utf-8
4              
5             =for stopwords watchlist watchlists untradable urls
6              
7             =head1 NAME
8              
9             Finance::Robinhood::Equity::Mover - Represents a Top Moving Equity Instrument
10              
11             =head1 SYNOPSIS
12              
13             use Text::Wrap qw[wrap];
14             use Finance::Robinhood;
15             my $rh = Finance::Robinhood->new;
16             my $movers = $rh->top_movers(direction => 'up');
17              
18             for my $mover ($movers->all) {
19             CORE::say $mover->instrument->name;
20             }
21              
22             =head1 METHODS
23              
24             =cut
25              
26             our $VERSION = '0.92_002';
27              
28 1     1   12 use Mojo::Base-base, -signatures;
  1         3  
  1         16  
29 1     1   724 use Mojo::URL;
  1         3  
  1         14  
30 1     1   10754 use Time::Moment;
  1         6  
  1         94  
31 1     1   9 use Finance::Robinhood::Equity::PriceMovement;
  1         3  
  1         42  
32              
33             sub _test__init {
34 1     1   14974 my $rh = t::Utility::rh_instance(1);
35 0         0 my $top = $rh->top_movers( direction => 'up' )->current;
36 0         0 isa_ok( $top, __PACKAGE__ );
37 0         0 t::Utility::stash( 'MOVER', $top ); # Store it for later
38             }
39              
40 1     1   247 use overload '""' => sub ( $s, @ ) { $s->{instrument_url} }, fallback => 1;
  1     0   2  
  1         17  
  0         0  
  0         0  
  0         0  
  0         0  
41              
42             sub _test_stringify {
43 1   50 1   1919 t::Utility::stash('MOVER') // skip_all();
44 0         0 like(
45             +t::Utility::stash('MOVER'),
46             qr'https://api.robinhood.com/instruments/.+/',
47             );
48             }
49             #
50             has _rh => undef => weak => 1;
51              
52             =head2 C
53              
54             Returns a full text description suited for display.
55              
56             =head2 C
57              
58             Returns the ticker symbol of the instrument.
59              
60             =cut
61              
62             has [ 'description', 'symbol' ];
63              
64             =head2 C
65              
66             $article->updated_at->to_string;
67              
68             Returns the time the article was published or last updated as a Time::Moment
69             object.
70              
71             =cut
72              
73 0     0 1 0 sub updated_at($s) {
  0         0  
  0         0  
74 0         0 Time::Moment->from_string( $s->{updated_at} );
75             }
76              
77             sub _test_updated_at {
78 1   50 1   1857 t::Utility::stash('MOVER') // skip_all();
79 0         0 isa_ok( t::Utility::stash('MOVER')->updated_at, 'Time::Moment' );
80             }
81              
82             =head2 C
83              
84             my $instrument = $mover->instrument();
85              
86             Builds a Finance::Robinhood::Equity::Instrument object.
87              
88             =cut
89              
90 0     0 1 0 sub instrument ($s) {
  0         0  
  0         0  
91 0         0 my $res = $s->_rh->_get( $s->{instrument_url} );
92             $res->is_success
93 0 0       0 ? Finance::Robinhood::Equity::Instrument->new( _rh => $s->_rh, %{ $res->json } )
  0 0       0  
94             : Finance::Robinhood::Error->new(
95             $res->is_server_error ? ( details => $res->message ) : $res->json );
96             }
97              
98             sub _test_instrument {
99 1   50 1   2248 t::Utility::stash('MOVER') // skip_all();
100 0         0 isa_ok( t::Utility::stash('MOVER')->instrument(), 'Finance::Robinhood::Equity::Instrument' );
101             }
102              
103             =head2 C
104              
105             my $price_movement = $mover->price_movement();
106              
107             Builds a Finance::Robinhood::Equity::PriceMovement object.
108              
109             =cut
110              
111 0     0 1 0 sub price_movement ($s) {
  0         0  
  0         0  
112 0         0 Finance::Robinhood::Equity::PriceMovement->new( _rh => $s->_rh, %{ $s->{price_movement} } );
  0         0  
113             }
114              
115             sub _test_price_movement {
116 1   50 1   1888 t::Utility::stash('MOVER') // skip_all();
117 0           isa_ok(
118             t::Utility::stash('MOVER')->price_movement(),
119             'Finance::Robinhood::Equity::PriceMovement'
120             );
121             }
122              
123             =head1 LEGAL
124              
125             This is a simple wrapper around the API used in the official apps. The author
126             provides no investment, legal, or tax advice and is not responsible for any
127             damages incurred while using this software. This software is not affiliated
128             with Robinhood Financial LLC in any way.
129              
130             For Robinhood's terms and disclosures, please see their website at
131             https://robinhood.com/legal/
132              
133             =head1 LICENSE
134              
135             Copyright (C) Sanko Robinson.
136              
137             This library is free software; you can redistribute it and/or modify it under
138             the terms found in the Artistic License 2. Other copyrights, terms, and
139             conditions may apply to data transmitted through this module. Please refer to
140             the L section.
141              
142             =head1 AUTHOR
143              
144             Sanko Robinson Esanko@cpan.orgE
145              
146             =cut
147              
148             1;