WSBetsAPI.pm

filter: Statementstmt 94.1% 64 / 68 Branchbran 62.5% 10 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 3 totaltotal 87.3% 90 / 103 CC 16 SCAR 16.6
CC
16
Cov
88%
date_formatter
12.0
ttm_squeeze_stocks
4.7
reddit
3.0
CRAP 5.2
↑ Summary WSBetsAPI/Reddit.pm »
1 package Tradestie::WSBetsAPI;
2  
3 # ABSTRACT: Tradestie's Wallstreet Bets API
4  
5 1 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Tradestie::WSBetsAPI::Reddit;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Tradestie::WSBetsAPI::TTM_Squeeze_Stocks;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $VERSION = '0.001';
18  
19 1 Readonly my $API_BASE_URL => 'https://tradestie.com/api/v1/apps/';
20  
21 1 has 'ua' => (
22 isa => 'LWP::UserAgent',
23 is => 'ro',
24 lazy_build => 1,
25 );
26  
27 3 ▶sub date_formatter( $self, $month = '11', $day = '17', $year = '2022' ) {
Subroutine date_formatter: called CC=10 SCAR=24.9
Pod undocumented
28 3 ▶ croak "Error: The month given is not a valid integer or date"
Branch: 1 branch
BranchTrueFalseTotal
unless int $month 0 3 3
29 unless int($month);
30  
31 3 ▶ croak "Error: The day given is not a valid integer or date"
Branch: 1 branch
BranchTrueFalseTotal
unless int $day 0 3 3
32 unless int($day);
33  
34 3 ▶ croak "Error: The year given is not a valid integer or date"
Branch: 1 branch
BranchTrueFalseTotal
unless int $year 0 3 3
35 unless int($year);
36  
37 3 ▶ croak "Error: The month must contain a two digit value"
Branch: 1 branch
BranchTrueFalseTotal
unless length $month == 2 0 3 3
38 unless length($month) == 2;
39  
40 3 ▶ croak "Error: The day must contain a two digit value"
Branch: 1 branch
BranchTrueFalseTotal
unless length $day == 2 0 3 3
41 unless length($day) == 2;
42  
43 3 ▶ croak "Error: The year must contain a four digit value"
Branch: 1 branch
BranchTrueFalseTotal
unless length $year == 4 0 3 3
44 unless length($year) == 4;
45  
46 3 return "$year-$month-$day";
47 }
48  
49 3 ▶sub reddit( $self, $date = undef ) {
Subroutine reddit: called CC=3 SCAR=11.0
Pod undocumented
50 3 my $path = $self->_build_path( 'reddit', $date );
51 3 my $response_list = $self->_request($path);
52 3 my @responses;
53  
54 # Create an array that contains Reddit objects
55 3 for my $response (@$response_list) {
56 100 push @responses, Tradestie::WSBetsAPI::Reddit->new($response);
57 }
58  
59 3 return @responses;
60 }
61  
62 1 ▶sub ttm_squeeze_stocks( $self, $date = "2022-11-17" ) {
Subroutine ttm_squeeze_stocks: called CC=3 SCAR=15.4
Pod undocumented
63 1 my $path = $self->_build_path( 'ttm-squeeze-stocks', $date );
64 1 my $response_list = $self->_request($path);
65 0 my @responses;
66  
67 # Create an array that contains TTM_Squeeze_Stocks objects
68 0 for my $response (@$response_list) {
69 0 push @responses,
70 Tradestie::WSBetsAPI::TTM_Squeeze_Stocks->new($response);
71 }
72  
73 0 return @responses;
74 }
75  
76 4 ▶sub _build_path( $self, $endpoint, $date ) {
Subroutine _build_path: called CC=2 SCAR=6.9
77 4 my $uri = URI->new( $API_BASE_URL . $endpoint );
78  
79 4 ▶ $uri->query( $uri->query_form( date => $date ) ) if $date;
Branch: 1 branch
BranchTrueFalseTotal
if $date 3 1 4
80  
81 4 return $uri;
82 }
83  
84 1 ▶sub _build_ua($self) {
Subroutine _build_ua: called CC=1 SCAR=0.0
85  
86 1 my $ua = LWP::UserAgent->new;
87 1 $ua->agent("");
88  
89 1 return $ua;
90 }
91  
92 4 ▶sub _request( $self, $uri ) {
Subroutine _request: called CC=2 SCAR=6.9
93 4 my $response = $self->ua->get($uri);
94 4 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 3 1 4
95 3 return decode_json( $response->decoded_content );
96 }
97 else {
98 1 my $code = $response->code;
99 1 confess "Tradestie API status code ($code)\n"
100 . "Error: "
101 . $response->status_line;
102 }
103 }
104  
105 1 1;
106  
107 __END__
↑ Summary WSBetsAPI/Reddit.pm »