line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
463022
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
99
|
|
2
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
27
|
use v5.010; |
|
2
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package WebService::SmartRow; |
7
|
|
|
|
|
|
|
$WebService::SmartRow::VERSION = '0.008'; |
8
|
|
|
|
|
|
|
# ABSTRACT: Connect and get data from SmartRow API |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1334
|
use HTTP::Tiny; |
|
2
|
|
|
|
|
85419
|
|
|
2
|
|
|
|
|
89
|
|
11
|
2
|
|
|
2
|
|
886
|
use JSON::MaybeXS; |
|
2
|
|
|
|
|
11216
|
|
|
2
|
|
|
|
|
122
|
|
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
1053
|
use Moo; |
|
2
|
|
|
|
|
13967
|
|
|
2
|
|
|
|
|
9
|
|
14
|
2
|
|
|
2
|
|
3793
|
use namespace::clean; |
|
2
|
|
|
|
|
29110
|
|
|
2
|
|
|
|
|
14
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has username => ( is => 'ro', required => 0 ); |
17
|
|
|
|
|
|
|
has password => ( is => 'ro', required => 0 ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has http => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
default => sub { |
22
|
|
|
|
|
|
|
return HTTP::Tiny->new(); |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# https://smartrow.fit/api/challenge |
27
|
|
|
|
|
|
|
sub get_challenges { |
28
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
0
|
my ( $user, $pass ) = $self->_credentials_via_env; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
my $response = $self->http->request( 'GET', |
33
|
|
|
|
|
|
|
'https://' |
34
|
|
|
|
|
|
|
. $user . ':' |
35
|
|
|
|
|
|
|
. $pass . '@' |
36
|
|
|
|
|
|
|
. 'smartrow.fit/api/challenge' ); |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
0
|
if ( !$response->{success} ) { |
39
|
0
|
|
|
|
|
0
|
return 'Response error'; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my $json = decode_json $response->{content}; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
return $json; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# https://smartrow.fit/api/account |
48
|
|
|
|
|
|
|
sub get_profile { |
49
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
my ( $user, $pass ) = $self->_credentials_via_env; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
my $response = $self->http->request( 'GET', |
54
|
|
|
|
|
|
|
'https://' . $user . ':' . $pass . '@' . 'smartrow.fit/api/account' ); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
0
|
if ( !$response->{success} ) { |
57
|
0
|
|
|
|
|
0
|
return 'Response error'; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
my $json = decode_json $response->{content}; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
return $json->[0]; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# https://smartrow.fit/api/public-game |
66
|
|
|
|
|
|
|
sub get_workouts { |
67
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
my ( $user, $pass ) = $self->_credentials_via_env; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
my $response = $self->http->request( 'GET', |
72
|
|
|
|
|
|
|
'https://' |
73
|
|
|
|
|
|
|
. $user . ':' |
74
|
|
|
|
|
|
|
. $pass . '@' |
75
|
|
|
|
|
|
|
. 'smartrow.fit/api/public-game' ); |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
0
|
if ( !$response->{success} ) { |
78
|
0
|
|
|
|
|
0
|
return 'Response error'; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
my $json = decode_json $response->{content}; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
return $json; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_leaderboard { |
87
|
0
|
|
|
0
|
1
|
0
|
my ( $self, %args ) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
0
|
|
|
0
|
$args{distance} //= 2000; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
my $params_string = ''; |
92
|
0
|
|
|
|
|
0
|
for my $key ( keys %args ) { |
93
|
0
|
|
|
|
|
0
|
$params_string .= sprintf( "%s=%s&", $key, $args{$key} ); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
my ( $user, $pass ) = $self->_credentials_via_env; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
my $response = $self->http->request( 'GET', |
99
|
|
|
|
|
|
|
'https://' |
100
|
|
|
|
|
|
|
. $user . ':' |
101
|
|
|
|
|
|
|
. $pass . '@' |
102
|
|
|
|
|
|
|
. 'smartrow.fit/api/leaderboard?' |
103
|
|
|
|
|
|
|
. $params_string ); |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
0
|
if ( !$response->{success} ) { |
106
|
0
|
|
|
|
|
0
|
return 'Response error'; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
0
|
my $json = decode_json $response->{content}; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
return $json->[0]; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _credentials_via_env { |
115
|
2
|
|
|
2
|
|
277
|
my $self = shift; |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
66
|
|
|
16
|
my $user = $self->username || $ENV{SMARTROW_USERNAME}; |
118
|
|
|
|
|
|
|
# Escape the "@" as perl basic auth requirement |
119
|
2
|
|
|
|
|
8
|
$user =~ s/@/%40/g; |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
66
|
|
|
11
|
my $pass = $self->password || $ENV{SMARTROW_PASSWORD}; |
122
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
8
|
return ( $user, $pass ),; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
__END__ |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=pod |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=encoding UTF-8 |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 NAME |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
WebService::SmartRow - Connect and get data from SmartRow API |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 VERSION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
version 0.008 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SYNOPSIS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This module is a basic wrapper to allow Perl apps to access data from https://smartrow.fit |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $smartrow = WebService::SmartRow->new( |
148
|
|
|
|
|
|
|
username => 'foo', |
149
|
|
|
|
|
|
|
password => 'bar', |
150
|
|
|
|
|
|
|
); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
my $profile = $smartrow->get_profile; |
153
|
|
|
|
|
|
|
my $workouts = $smartrow->get_workouts; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Credentials can be passed via environment variables |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
* SMARTROW_USERNAME |
158
|
|
|
|
|
|
|
* SMARTROW_PASSWORD |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
If passing credentials via ENV you can simply use WebService::SmartRow->new; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 http |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
http is a HTTP::Tiny object by default, you can provide your own on construction. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This might be helpful if, for example, you wanted to change the user agent. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 username |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
get/set the username for the API |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Note that we parse the username in get_ methods to escape the "@" char. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
You can also set the SMARTROW_USERNAME environment variable. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 password |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
get/set the password for the API |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
You can also set the SMARTROW_PASSWORD environment variable. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 METHODS |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 get_profile |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This method obtains your profile information |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head2 get_workouts |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This method returns all the workouts you have done via SmartRow |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head2 get_leaderboard |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This method returns the data presented in the leaderboard (AKA Rankings page). |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Unlike the first two methods, get_leaderboard can accept parameters to limit the data. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
e.g. |
201
|
|
|
|
|
|
|
my $leaderboard = $srv->get_leaderboard( |
202
|
|
|
|
|
|
|
distance => 5000, # If not provided will default to 2000 |
203
|
|
|
|
|
|
|
year => 2022, |
204
|
|
|
|
|
|
|
country => 188, |
205
|
|
|
|
|
|
|
age => 'c', |
206
|
|
|
|
|
|
|
gender => 'f', # m or f (male or female) |
207
|
|
|
|
|
|
|
weight => 'l', # l or h (light or heavy) |
208
|
|
|
|
|
|
|
); |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
More details on values able to be used to follow. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 get_challenges |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This method returns an array of challenges, there are no parameters. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 AUTHOR |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Lance Wicks <lw@judocoach.com> |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Lance Wicks. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
This is free software, licensed under: |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
The MIT (X11) License |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |