1 | <?php |
||
16 | class Workouts |
||
17 | { |
||
18 | private const URL_BASE = 'https://api.mobile.endomondo.com/mobile'; |
||
19 | private const URL_WORKOUTS = 'https://api.mobile.endomondo.com/mobile/api/workouts'; |
||
20 | private const URL_WORKOUT_GET = 'https://api.mobile.endomondo.com/mobile/api/workout/get'; |
||
21 | private const URL_WORKOUT_POST = 'https://api.mobile.endomondo.com/mobile/api/workout/post'; |
||
22 | private const URL_TRACK = 'https://api.mobile.endomondo.com/mobile/track'; |
||
23 | private const URL_FRIENDS = 'https://api.mobile.endomondo.com/mobile/friends'; |
||
24 | |||
25 | private const INSTRUCTION_PAUSE = 0; |
||
26 | private const INSTRUCTION_RESUME = 1; |
||
27 | private const INSTRUCTION_START = 2; |
||
28 | private const INSTRUCTION_STOP = 3; |
||
29 | private const INSTRUCTION_NONE = 4; |
||
30 | private const INSTRUCTION_GPS_OFF = 5; |
||
31 | private const INSTRUCTION_LAP = 6; |
||
32 | |||
33 | /** |
||
34 | * Endomondo authentication token. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $authentication; |
||
39 | |||
40 | /** |
||
41 | * @var Client |
||
42 | */ |
||
43 | protected $client; |
||
44 | |||
45 | /** |
||
46 | * @param Authentication $authentication |
||
47 | * @param Client $client |
||
48 | */ |
||
49 | public function __construct(Authentication $authentication, Client $client) |
||
54 | |||
55 | /** |
||
56 | * Get the details of a workout. |
||
57 | * |
||
58 | * Possible fields when getting the workout: |
||
59 | * device,simple,basic,motivation,interval,hr_zones,weather,polyline_encoded_small,points,lcp_count,tagged_users,pictures,feed |
||
60 | * |
||
61 | * @param string $idWorkout The ID of the workout. |
||
62 | * @return array |
||
63 | * @throws \RuntimeException |
||
64 | */ |
||
65 | public function getWorkout($idWorkout): array |
||
88 | |||
89 | /** |
||
90 | * Get a list of workouts in a date interval. |
||
91 | * |
||
92 | * @param \DateTimeImmutable $startDate The start date for the workouts. |
||
93 | * @param \DateTimeImmutable $endDate The end date for the workouts. |
||
94 | * @return array |
||
95 | */ |
||
96 | public function listWorkouts(\DateTimeImmutable $startDate, \DateTimeImmutable $endDate): array |
||
117 | |||
118 | /** |
||
119 | * Post one workout track to Endomondo. |
||
120 | * |
||
121 | * @param Track $track |
||
122 | * @param string $sport |
||
123 | * @return null|string |
||
124 | */ |
||
125 | public function postTrack(Track $track, string $sport) |
||
158 | |||
159 | /** |
||
160 | * Post the workout end data. |
||
161 | * |
||
162 | * @param Track $track The track. |
||
163 | * @param float $speed The speed for the last point. |
||
164 | * @return string The workout ID. |
||
165 | */ |
||
166 | private function flattenEndWorkoutTrackPoint(Track $track, $speed) |
||
186 | |||
187 | /** |
||
188 | * Post workout data chunk. |
||
189 | * |
||
190 | * @param string $deviceWorkoutId The workout ID in progress of the device. |
||
191 | * @param string $sport The sport. |
||
192 | * @param integer $duration The duration in seconds. |
||
193 | * @param array $data The data points to post. |
||
194 | * @return string The workout ID. |
||
195 | * @throws \RuntimeException |
||
196 | */ |
||
197 | private function postWorkoutData($deviceWorkoutId, $sport, $duration, array $data): string |
||
232 | |||
233 | /** |
||
234 | * Flatten a track point to be posted on Endomondo. |
||
235 | * |
||
236 | * @param TrackPoint $trackPoint The track point to flatten. |
||
237 | * @param float $distance The total distance the point in meters. |
||
238 | * @param float $speed The speed the point in km/h from the previous point. |
||
239 | * @return string |
||
240 | */ |
||
241 | private function flattenTrackPoint(TrackPoint $trackPoint, $distance, $speed): string |
||
257 | |||
258 | /** |
||
259 | * Format a point to send to Endomondo when posting a new workout. |
||
260 | * |
||
261 | * Type: |
||
262 | * 0 - pause |
||
263 | * 1 - running ? |
||
264 | * 2 - running |
||
265 | * 3 - stop |
||
266 | * |
||
267 | * @param \DateTimeImmutable $dateTime |
||
268 | * @param integer $type The post type (0-6). Don't know what they mean. |
||
269 | * @param string $lat The latitude of the point. |
||
270 | * @param string $lon The longitude of the point. |
||
271 | * @param string $distance The distance in meters. |
||
272 | * @param string $speed The speed in km/h. |
||
273 | * @param string $elevation The elevation |
||
274 | * @param string $heartRate The heart rate. |
||
275 | * @param string $cadence The cadence (in rpm). |
||
276 | * @return string |
||
277 | */ |
||
278 | private function formatEndomondoTrackPoint( |
||
305 | |||
306 | /** |
||
307 | * Generate a big number of specified length. |
||
308 | * |
||
309 | * @return string |
||
310 | */ |
||
311 | private function generateDeviceWorkoutId() |
||
321 | } |
||
322 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..