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