line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
454640
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
65
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
45
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
28
|
use v5.010; |
|
2
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$WebService::SmartRow::VERSION = '0.007'; |
7
|
|
|
|
|
|
|
# ABSTRACT: Connect and get data from SmartRow API |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use HTTP::Tiny; |
10
|
2
|
|
|
2
|
|
1864
|
use JSON::MaybeXS; |
|
2
|
|
|
|
|
89003
|
|
|
2
|
|
|
|
|
96
|
|
11
|
2
|
|
|
2
|
|
920
|
|
|
2
|
|
|
|
|
11759
|
|
|
2
|
|
|
|
|
119
|
|
12
|
|
|
|
|
|
|
use Moo; |
13
|
2
|
|
|
2
|
|
1079
|
use namespace::clean; |
|
2
|
|
|
|
|
14686
|
|
|
2
|
|
|
|
|
9
|
|
14
|
2
|
|
|
2
|
|
3843
|
|
|
2
|
|
|
|
|
30581
|
|
|
2
|
|
|
|
|
16
|
|
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
|
|
|
|
|
|
|
# https://smartrow.fit/api/challenge |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
0
|
1
|
0
|
my ( $user, $pass ) = $self->_credentials_via_env; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
0
|
my $response = $self->http->request( 'GET', |
31
|
|
|
|
|
|
|
'https://' |
32
|
0
|
|
|
|
|
0
|
. $user . ':' |
33
|
|
|
|
|
|
|
. $pass . '@' |
34
|
|
|
|
|
|
|
. 'smartrow.fit/api/challenge' ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
if ( !$response->{success} ) { |
37
|
|
|
|
|
|
|
return 'Response error'; |
38
|
0
|
0
|
|
|
|
0
|
} |
39
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
my $json = decode_json $response->{content}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
return $json; |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
# https://smartrow.fit/api/account |
46
|
|
|
|
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my ( $user, $pass ) = $self->_credentials_via_env; |
49
|
0
|
|
|
0
|
1
|
0
|
|
50
|
|
|
|
|
|
|
my $response = $self->http->request( 'GET', |
51
|
0
|
|
|
|
|
0
|
'https://' . $user . ':' . $pass . '@' . 'smartrow.fit/api/account' ); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
if ( !$response->{success} ) { |
54
|
|
|
|
|
|
|
return 'Response error'; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
0
|
|
|
|
0
|
|
57
|
0
|
|
|
|
|
0
|
my $json = decode_json $response->{content}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return $json->[0]; |
60
|
0
|
|
|
|
|
0
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
# https://smartrow.fit/api/public-game |
63
|
|
|
|
|
|
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my ( $user, $pass ) = $self->_credentials_via_env; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
1
|
0
|
my $response = $self->http->request( 'GET', |
68
|
|
|
|
|
|
|
'https://' |
69
|
0
|
|
|
|
|
0
|
. $user . ':' |
70
|
|
|
|
|
|
|
. $pass . '@' |
71
|
0
|
|
|
|
|
0
|
. 'smartrow.fit/api/public-game' ); |
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
|
|
265
|
my $pass = $self->password || $ENV{SMARTROW_PASSWORD}; |
116
|
|
|
|
|
|
|
|
117
|
2
|
|
66
|
|
|
14
|
return ( $user, $pass ),; |
118
|
|
|
|
|
|
|
} |
119
|
2
|
|
|
|
|
7
|
|
120
|
|
|
|
|
|
|
|
121
|
2
|
|
66
|
|
|
11
|
1; |
122
|
|
|
|
|
|
|
|
123
|
2
|
|
|
|
|
8
|
|
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.007 |
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 |