Completed
Push — master ( f0f8ea...68f02b )
by Bas van
02:50
created

Client::getActivityFollowing()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
crap 6
1
<?php
2
namespace Strava\API;
3
4
use Strava\API\Service\ServiceInterface;
5
use Strava\API\Exception as ClientException;
6
use Strava\API\Service\Exception as ServiceException;
7
8
/**
9
 * Strava API Client
10
 *
11
 * @author Bas van Dorst
12
 * @package StravaPHP
13
 */
14
class Client {
15
    /**
16
     * @var ServiceInterface $service
17
     */
18
    protected $service;
19
20
    /**
21
     * Initiate this class with a subclass of ServiceInterface. There are two
22
     * service subclasses available:
23
     * - Service\REST: Service which makes calls to the live Strava API
24
     * - Service\Stub: Service stub for test purposes (unit tests)
25
     *
26
     * @param ServiceInterface $service
27
     */
28 72
    public function __construct(ServiceInterface $service) {
29 72
        $this->service = $service;
30 72
    }
31
32
    /**
33
     * Retrieve current athlete
34
     *
35
     * @link    https://strava.github.io/api/v3/athlete/#get-details,
36
     *          https://strava.github.io/api/v3/athlete/#get-another-details
37
     * @param   int $id
38
     * @return  array
39
     * @throws  Exception
40
     */
41 2
    public function getAthlete($id = null) {
42
        try {
43 2
            return $this->service->getAthlete($id);
44 1
        } catch (ServiceException $e) {
45 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
46
        }
47
    }
48
49
    /**
50
     * Retrieve athlete stats
51
     *
52
     * Only available for the authenticated athlete.
53
     *
54
     * @link    https://strava.github.io/api/v3/athlete/#stats
55
     * @param   int $id
56
     * @return  array
57
     * @throws  ClientException
58
     */
59 1
    public function getAthleteStats($id) {
60
        try {
61 1
            return $this->service->getAthleteStats($id);
62
        } catch (ServiceException $e) {
63
            throw new ClientException('[SERVICE] '.$e->getMessage());
64
        }
65
    }
66
67
    /**
68
     * List athlete clubs
69
     *
70
     * @link    https://strava.github.io/api/v3/clubs/#get-athletes
71
     * @return  array
72
     * @throws  Exception
73
     */
74 2
    public function getAthleteClubs() {
75
        try {
76 2
            return $this->service->getAthleteClubs();
77 1
        } catch (ServiceException $e) {
78 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
79
        }
80
    }
81
82
    /**
83
     * List athlete activities
84
     *
85
     * @link    https://strava.github.io/api/v3/activities/#get-activities
86
     * @param   string $before
87
     * @param   string $after
88
     * @param   int $page
89
     * @param   int $per_page
90
     * @return  array
91
     * @throws  Exception
92
     */
93 2
    public function getAthleteActivities($before = null, $after = null, $page = null, $per_page = null) {
94
        try {
95 2
            return $this->service->getAthleteActivities($before, $after, $page, $per_page);
96 1
        } catch (ServiceException $e) {
97 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
98
        }
99
    }
100
101
    /**
102
     * List athlete friends
103
     *
104
     * @link    https://strava.github.io/api/v3/follow/#friends
105
     * @param   int $id
106
     * @param   int $page
107
     * @param   int $per_page
108
     * @return  array
109
     * @throws  Exception
110
     */
111 2
    public function getAthleteFriends($id = null, $page = null, $per_page = null) {
112
        try {
113 2
            return $this->service->getAthleteFriends($id, $page, $per_page);
114 1
        } catch (ServiceException $e) {
115 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
116
        }
117
    }
118
119
    /**
120
     * List athlete followers
121
     *
122
     * @link    https://strava.github.io/api/v3/follow/#followers
123
     * @param   int $id
124
     * @param   int $page
125
     * @param   int $per_page
126
     * @return  array
127
     * @throws  Exception
128
     */
129 2
    public function getAthleteFollowers($id = null, $page = null, $per_page = null) {
130
        try {
131 2
            return $this->service->getAthleteFollowers($id, $page, $per_page);
132 1
        } catch (ServiceException $e) {
133 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
134
        }
135
    }
136
137
    /**
138
     * List both following
139
     *
140
     * @link    https://strava.github.io/api/v3/follow/#both
141
     * @param   int $id
142
     * @param   int $page
143
     * @param   int $per_page
144
     * @return  array
145
     * @throws  Exception
146
     */
147 2
    public function getAthleteBothFollowing($id, $page = null, $per_page = null) {
148
        try {
149 2
            return $this->service->getAthleteBothFollowing($id, $page, $per_page);
150 1
        } catch (ServiceException $e) {
151 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
152
        }
153
    }
154
155
    /**
156
     * List athlete K/QOMs/CRs
157
     *
158
     * @link    https://strava.github.io/api/v3/athlete/#koms
159
     * @param   int $id
160
     * @param   int $page
161
     * @param   int $per_page
162
     * @return  array
163
     * @throws  Exception
164
     */
165 2
    public function getAthleteKom($id, $page = null, $per_page = null) {
166
        try {
167 2
            return $this->service->getAthleteKom($id, $page, $per_page);
168 1
        } catch (ServiceException $e) {
169 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
170
        }
171
    }
172
173
    /**
174
     * List starred segment
175
     *
176
     * @link    https://strava.github.io/api/v3/segments/#starred
177
     * @param   int $id
178
     * @param   int $page
179
     * @param   int $per_page
180
     * @return  array
181
     * @throws  Exception
182
     */
183 2
    public function getAthleteStarredSegments($id = null, $page = null, $per_page = null) {
184
        try {
185 2
            return $this->service->getAthleteStarredSegments($id, $page, $per_page);
186 1
        } catch (ServiceException $e) {
187 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
188
        }
189
    }
190
191
    /**
192
     * Update current athlete
193
     *
194
     * @link    https://strava.github.io/api/v3/athlete/#update
195
     * @param   string $city
196
     * @param   string $state
197
     * @param   string $country
198
     * @param   string $sex
199
     * @param   float $weight
200
     * @return  array
201
     * @throws  Exception
202
     */
203 2
    public function updateAthlete($city, $state, $country, $sex, $weight) {
204
        try {
205 2
            return $this->service->updateAthlete($city, $state, $country, $sex, $weight);
206 1
        } catch (ServiceException $e) {
207 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
208
        }
209
    }
210
211
    /**
212
     * Retrieve activity from user followers
213
     * 
214
     * @link https://strava.github.io/api/v3/activities/#get-feed
215
     * 
216
     * @param type $before
217
     * @param type $page
218
     * @param type $per_page
219
     * @return type
220
     * @throws ClientException
221
     */
222
    public function getActivityFollowing($before = null, $page = null, $per_page = null) {
223
        try {
224
            return $this->service->getActivityFollowing($before, $page, $per_page);
225
        } catch (ServiceException $e) {
226
            throw new ClientException('[SERVICE] '.$e->getMessage());
227
        }
228
    }
229
    
230
    
231
    /**
232
     * Retrieve an activity
233
     *
234
     * @link    https://strava.github.io/api/v3/athlete/#get-details,
235
     *          https://strava.github.io/api/v3/athlete/#get-another-details
236
     * @param   int $id
237
     * @param   boolean $include_all_efforts
238
     * @return  array
239
     * @throws  Exception
240
     */
241 2
    public function getActivity($id, $include_all_efforts = null) {
242
        try {
243 2
            return $this->service->getActivity($id, $include_all_efforts);
244 1
        } catch (ServiceException $e) {
245 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
246
        }
247
    }
248
249
    /**
250
     * List activity comments
251
     *
252
     * @link    https://strava.github.io/api/v3/comments/#list
253
     * @param   int $id
254
     * @param   boolean $markdown
255
     * @param   int $page
256
     * @param   int $per_page
257
     * @return  array
258
     * @throws  Exception
259
     */
260 2
    public function getActivityComments($id, $markdown = null, $page = null, $per_page = null) {
261
        try {
262 2
            return $this->service->getActivityComments($id, $markdown, $page, $per_page);
263 1
        } catch (ServiceException $e) {
264 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
265
        }
266
    }
267
268
    /**
269
     * List activity kudoers
270
     *
271
     * @link    https://strava.github.io/api/v3/kudos/#list
272
     * @param   int $id
273
     * @param   int $page
274
     * @param   int $per_page
275
     * @return  array
276
     * @throws  Exception
277
     */
278 2
    public function getActivityKudos($id, $page = null, $per_page = null) {
279
        try {
280 2
            return $this->service->getActivityKudos($id, $page, $per_page);
281 1
        } catch (ServiceException $e) {
282 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
283
        }
284
    }
285
286
    /**
287
     * List activity photos
288
     *
289
     * @link    https://strava.github.io/api/v3/photos/#list
290
     * @param   int $id
291
     * @param   int $size In pixels.
292
     * @param   string $photo_sources Must be "true".
293
     * @return  array
294
     * @throws  Exception
295
     */
296 2
    public function getActivityPhotos($id, $size = 2048, $photo_sources = 'true') {
297
        try {
298 2
            return $this->service->getActivityPhotos($id, $size, $photo_sources);
299 1
        } catch (ServiceException $e) {
300 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
301
        }
302
    }
303
304
    /**
305
     * List activity zones
306
     *
307
     * @link    https://strava.github.io/api/v3/activities/#zones
308
     * @param   int $id
309
     * @return  array
310
     * @throws  Exception
311
     */
312 2
    public function getActivityZones($id) {
313
        try {
314 2
            return $this->service->getActivityZones($id);
315 1
        } catch (ServiceException $e) {
316 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
317
        }
318
    }
319
320
    /**
321
     * List activity laps
322
     *
323
     * @link    https://strava.github.io/api/v3/activities/#laps
324
     * @param   int $id
325
     * @return  array
326
     * @throws  Exception
327
     */
328 2
    public function getActivityLaps($id) {
329
        try {
330 2
            return $this->service->getActivityLaps($id);
331 1
        } catch (ServiceException $e) {
332 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
333
        }
334
    }
335
336
    /**
337
     * Check upload status
338
     *
339
     * @link    https://strava.github.io/api/v3/uploads/#get-status
340
     * @param   int $id
341
     * @return  array
342
     * @throws  Exception
343
     */
344 2
    public function getActivityUploadStatus($id) {
345
        try {
346 2
            return $this->service->getActivityUploadStatus($id);
347 1
        } catch (ServiceException $e) {
348 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
349
        }
350
    }
351
352
    /**
353
     * Create an activity
354
     *
355
     * @link    https://strava.github.io/api/v3/activities/#create
356
     * @param   string $name
357
     * @param   string $type
358
     * @param   string $start_date_local
359
     * @param   int $elapsed_time
360
     * @param   string $description
361
     * @param   float $distance
362
     * @param   int $private
363
     * @param   int $trainer
364
     * @return  array
365
     * @throws  Exception
366
     */
367 2
    public function createActivity($name, $type, $start_date_local, $elapsed_time, $description = null, $distance = null, $private = null, $trainer = null) {
368
        try {
369 2
            return $this->service->createActivity($name, $type, $start_date_local, $elapsed_time, $description, $distance, $private, $trainer);
0 ignored issues
show
Unused Code introduced by
The call to ServiceInterface::createActivity() has too many arguments starting with $private.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
370 1
        } catch (ServiceException $e) {
371 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
372
        }
373
    }
374
375
    /**
376
     * Upload an activity
377
     *
378
     * @link    https://strava.github.io/api/v3/uploads/#post-file
379
     * @param   mixed $file
380
     * @param   string $activity_type
381
     * @param   string $name
382
     * @param   string $description
383
     * @param   int $private
384
     * @param   int $trainer
385
     * @param   int $commute
386
     * @param   string $data_type
387
     * @param   string $external_id
388
     * @return  array
389
     * @throws  Exception
390
     */
391 2
    public function uploadActivity($file, $activity_type = null, $name = null, $description = null, $private = null, $trainer = null, $commute = null, $data_type = null, $external_id = null) {
392
        try {
393 2
            return $this->service->uploadActivity($file, $activity_type, $name, $description, $private, $trainer, $commute, $data_type, $external_id);
0 ignored issues
show
Unused Code introduced by
The call to ServiceInterface::uploadActivity() has too many arguments starting with $external_id.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
394 1
        } catch (ServiceException $e) {
395 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
396
        }
397
    }
398
399
    /**
400
     * Update an activity
401
     *
402
     * @link    https://strava.github.io/api/v3/activities/#put-updates
403
     * @param   int $id
404
     * @param   string $name
405
     * @param   string $type
406
     * @param   boolean $private
407
     * @param   boolean $commute
408
     * @param   boolean $trainer
409
     * @param   string $gear_id
410
     * @param   string $description
411
     * @return  array
412
     * @throws  Exception
413
     */
414 2
    public function updateActivity($id, $name = null, $type = null, $private = false, $commute = false, $trainer = false, $gear_id = null, $description = null) {
415
        try {
416 2
            return $this->service->updateActivity($id, $name, $type, $private, $commute, $trainer, $gear_id, $description);
417 1
        } catch (ServiceException $e) {
418 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
419
        }
420
    }
421
422
    /**
423
     * Delete an activity
424
     *
425
     * @link    https://strava.github.io/api/v3/activities/#delete
426
     * @param   int $id
427
     * @return  array
428
     * @throws  Exception
429
     */
430 2
    public function deleteActivity($id) {
431
        try {
432 2
            return $this->service->deleteActivity($id);
433 1
        } catch (ServiceException $e) {
434 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
435
        }
436
    }
437
438
    /**
439
     * Retrieve gear
440
     *
441
     * @link    https://strava.github.io/api/v3/gear/
442
     * @param   int $id
443
     * @return  array
444
     * @throws  Exception
445
     */
446 2
    public function getGear($id) {
447
        try {
448 2
            return $this->service->getGear($id);
449 1
        } catch (ServiceException $e) {
450 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
451
        }
452
    }
453
454
    /**
455
     * Retrieve a club
456
     *
457
     * @link    https://strava.github.io/api/v3/clubs/#get-details
458
     * @param   int $id
459
     * @return  array
460
     * @throws  Exception
461
     */
462 2
    public function getClub($id) {
463
        try {
464 2
            return $this->service->getClub($id);
465 1
        } catch (ServiceException $e) {
466 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
467
        }
468
    }
469
470
    /**
471
     * List club members
472
     *
473
     * @link    https://strava.github.io/api/v3/clubs/#get-members
474
     * @param   int $id
475
     * @param   int $page
476
     * @param   int $per_page
477
     * @return  array
478
     * @throws  Exception
479
     */
480 2
    public function getClubMembers($id, $page = null, $per_page = null) {
481
        try {
482 2
            return $this->service->getClubMembers($id, $page, $per_page);
483 1
        } catch (ServiceException $e) {
484 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
485
        }
486
    }
487
488
    /**
489
     * List club activities
490
     *
491
     * @link    https://strava.github.io/api/v3/clubs/#get-activities
492
     * @param   int $id
493
     * @param   int $page
494
     * @param   int $per_page
495
     * @return  array
496
     * @throws  Exception
497
     */
498 2
    public function getClubActivities($id, $page = null, $per_page = null) {
499
        try {
500 2
            return $this->service->getClubActivities($id, $page, $per_page);
501 1
        } catch (ServiceException $e) {
502 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
503
        }
504
    }
505
506
    /**
507
     * List club announcements
508
     *
509
     * @link    https://strava.github.io/api/v3/clubs/#get-announcements
510
     * @param   int $id
511
     * @return  array
512
     * @throws  Exception
513
     */
514 2
    public function getClubAnnouncements($id) {
515
        try {
516 2
            return $this->service->getClubAnnouncements($id);
517 1
        } catch (ServiceException $e) {
518 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
519
        }
520
    }
521
522
    /**
523
     * List club group events
524
     *
525
     * @link    https://strava.github.io/api/v3/clubs/#get-group-events
526
     * @param   int $id
527
     * @return  array
528
     * @throws  Exception
529
     */
530 2
    public function getClubGroupEvents($id) {
531
        try {
532 2
            return $this->service->getClubGroupEvents($id);
533 1
        } catch (ServiceException $e) {
534 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
535
        }
536
    }
537
538
    /**
539
     * Join a club
540
     *
541
     * @link    https://strava.github.io/api/v3/clubs/#join
542
     * @param   int $id
543
     * @return  array
544
     * @throws  Exception
545
     */
546 2
    public function joinClub($id) {
547
        try {
548 2
            return $this->service->joinClub($id);
549 1
        } catch (ServiceException $e) {
550 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
551
        }
552
    }
553
554
    /**
555
     * Leave a club
556
     *
557
     * @link    https://strava.github.io/api/v3/clubs/#leave
558
     * @param   int $id
559
     * @return  array
560
     * @throws  Exception
561
     */
562 2
    public function leaveClub($id) {
563
        try {
564 2
            return $this->service->leaveClub($id);
565 1
        } catch (ServiceException $e) {
566 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
567
        }
568
    }
569
570
    /**
571
     * Retrieve a segment
572
     *
573
     * @link    https://strava.github.io/api/v3/segments/#retrieve
574
     * @param   int $id
575
     * @return  array
576
     * @throws  Exception
577
     */
578 2
    public function getSegment($id) {
579
        try {
580 2
            return $this->service->getSegment($id);
581 1
        } catch (ServiceException $e) {
582 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
583
        }
584
    }
585
586
    /**
587
     * Segment leaderboards
588
     *
589
     * @link    https://strava.github.io/api/v3/segments/#leaderboard
590
     * @param   int $id
591
     * @param   string $gender
592
     * @param   string $age_group
593
     * @param   string $weight_class
594
     * @param   boolean $following
595
     * @param   int $club_id
596
     * @param   string $date_range
597
     * @param   int $context_entries
598
     * @param   int $page
599
     * @param   int $per_page
600
     * @return  array
601
     * @throws  Exception
602
     */
603 2
    public function getSegmentLeaderboard($id, $gender = null, $age_group = null, $weight_class = null, $following = null, $club_id = null, $date_range = null, $context_entries = null, $page = null, $per_page = null) {
604
        try {
605 2
            return $this->service->getSegmentLeaderboard($id, $gender, $age_group, $weight_class, $following, $club_id, $date_range, $context_entries, $page, $per_page);
606 1
        } catch (ServiceException $e) {
607 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
608
        }
609
    }
610
611
    /**
612
     * Segment explorer
613
     *
614
     * @link    https://strava.github.io/api/v3/segments/#explore
615
     * @param   string $bounds
616
     * @param   string $activity_type
617
     * @param   int $min_cat
618
     * @param   int $max_cat
619
     * @return  array
620
     * @throws  Exception
621
     */
622 2
    public function getSegmentExplorer($bounds, $activity_type = 'riding', $min_cat = null, $max_cat = null) {
623
        try {
624 2
            return $this->service->getSegmentExplorer($bounds, $activity_type, $min_cat, $max_cat);
625 1
        } catch (ServiceException $e) {
626 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
627
        }
628
    }
629
630
    /**
631
     * List efforts filtered by athlete and/or a date range
632
     *
633
     * @link    https://strava.github.io/api/v3/segments/#efforts
634
     * @param   int $id
635
     * @param   int $athlete_id
636
     * @param   string $start_date_local
637
     * @param   string $end_date_local
638
     * @param   int $page
639
     * @param   int $per_page
640
     * @return  array
641
     * @throws  Exception
642
     */
643 2
    public function getSegmentEffort($id, $athlete_id = null, $start_date_local = null, $end_date_local = null, $page = null, $per_page = null) {
644
        try {
645 2
            return $this->service->getSegmentEffort($id, $athlete_id, $start_date_local, $end_date_local, $page, $per_page);
646 1
        } catch (ServiceException $e) {
647 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
648
        }
649
    }
650
651
    /**
652
     * Retrieve activity streams
653
     *
654
     * @link    https://strava.github.io/api/v3/streams/#activity
655
     * @param   int $id
656
     * @param   string $types
657
     * @param   string $resolution
658
     * @param   string $series_type
659
     * @return  array
660
     * @throws  Exception
661
     */
662 2
    public function getStreamsActivity($id, $types, $resolution = null, $series_type = 'distance') {
663
        try {
664 2
            return $this->service->getStreamsActivity($id, $types, $resolution, $series_type);
665 1
        } catch (ServiceException $e) {
666 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
667
        }
668
    }
669
670
    /**
671
     * Retrieve effort streams
672
     *
673
     * @link    https://strava.github.io/api/v3/streams/#effort
674
     * @param   int $id
675
     * @param   string $types
676
     * @param   string $resolution
677
     * @param   string $series_type
678
     * @return  array
679
     * @throws  Exception
680
     */
681 2
    public function getStreamsEffort($id, $types, $resolution = null, $series_type = 'distance') {
682
        try {
683 2
            return $this->service->getStreamsEffort($id, $types, $resolution, $series_type);
684 1
        } catch (ServiceException $e) {
685 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
686
        }
687
    }
688
689
    /**
690
     * Retrieve segment streams
691
     * @link    https://strava.github.io/api/v3/streams/#segment
692
     * @param   int $id
693
     * @param   string $types
694
     * @param   string $resolution
695
     * @param   string $series_type
696
     * @return  array
697
     * @throws  Exception
698
     */
699 2
    public function getStreamsSegment($id, $types, $resolution = null, $series_type = 'distance') {
700
        try {
701 2
            return $this->service->getStreamsSegment($id, $types, $resolution, $series_type);
702 1
        } catch (ServiceException $e) {
703 1
            throw new ClientException('[SERVICE] '.$e->getMessage());
704
        }
705
    }
706
}
707