Strava.pm

filter: Statementstmt 33.0% 69 / 209 Branchbran 0.0% 0 / 62 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 66.6% 26 / 39 Podpod n/a totaltotal 30.6% 96 / 313 CC 36 SCAR 28.0
CC
36
Cov
26%
list_activities
62.7
list_friends_activities
34.8
list_starred_segments
34.3
CRAP 16.5
« Strava/Auth.pm ↑ Summary Strava/Athlete.pm »
1 package WebService::Strava;
2 4 ▶use v5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Method::Signatures 20140224;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶our $DEBUG = $ENV{STRAVA_DEBUG} || 0;
Condition50%1/2
$ENV{'STRAVA_DEBUG'} || 0
l!l
04
MC/DC0%0/1
$ENV{'STRAVA_DEBUG'} || 0
$ENV{'STRAVA_DEBUG'}
Truth table50%1/2
A
A= $ENV{'STRAVA_DEBUG'}
Aresult
11
00
13  
14 # ABSTRACT: Access Strava via version 3 of the API
15  
16 4 our $VERSION = '0.06'; # VERSION: Generated by DZP::OurPkg:Version
17  
18  
19 4 ▶use WebService::Strava::Auth;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 has 'auth' => (
22 is => 'ro',
23 0 ▶ isa => sub { "WebService::Strava::Auth" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 4 lazy => 1,
25 builder => 1,
26 handles => [ qw( get post ) ],
27 );
28  
29 0 ▶method _build_auth() {
Subroutine BEGIN: called CC=1 SCAR=2.6
Subroutine _build_auth: not called CC=2 SCAR=12.4
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
30 0 return WebService::Strava::Auth->new();
31 }
32  
33  
34 4 ▶use WebService::Strava::Athlete;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 0 ▶method athlete($id?) {
Subroutine BEGIN: called CC=1 SCAR=3.1
Subroutine athlete: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 1 0 0 0
37 0 return WebService::Strava::Athlete->new(id =>$id, auth => $self->auth);
38 }
39  
40  
41 0 ▶method clubs($build = 0) {
Subroutine BEGIN: called CC=1 SCAR=3.9
Subroutine clubs: not called CC=4 SCAR=27.1
Branch: 2 branches
BranchTrueFalseTotal
scalar @_ > 0 ? : 0 0 0
if scalar @_ > 1 0 0 0
42 0 my $data = $self->auth->get_api("/athlete/clubs");
43 0 my $index = 0;
44 0 foreach my $club (@{$data}) {
45 0 @{$data}[$index] = WebService::Strava::Club->new(id => $club->{id}, auth => $self->auth, _build => $build);
46 0 $index++;
47 }
48 0 return $data;
49 }
50  
51  
52 4 ▶use WebService::Strava::Segment;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 0 ▶method segment($id) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine segment: not called CC=3 SCAR=20.7
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
55 0 return WebService::Strava::Segment->new(id =>$id, auth => $self->auth);
56 }
57  
58  
59 0 ▶method list_starred_segments(:$activities = 25, :$page = 1) {
Subroutine BEGIN: called CC=1 SCAR=5.3
Subroutine list_starred_segments: not called CC=6 SCAR=35.4
Branch: 4 branches
BranchTrueFalseTotal
exists $args{'activities'} ? : 0 0 0
exists $args{'page'} ? : 0 0 0
if keys %args 0 0 0
if scalar @_ > 4 0 0 0
60 # TODO: Handle pagination better use #4's solution when found.
61 0 my $data = $self->auth->get_api("/segments/starred?per_page=$activities&page=$page");
62 0 my $index = 0;
63 0 foreach my $segment (@{$data}) {
64 0 @{$data}[$index] = WebService::Strava::Segment->new(id => $segment->{id}, auth => $self->auth, _build => 0);
65 0 $index++;
66 }
67 0 return $data;
68 }
69  
70  
71 4 ▶use WebService::Strava::Athlete::Segment_Effort;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 0 ▶method effort($id) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine effort: not called CC=3 SCAR=20.7
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
74 0 return WebService::Strava::Athlete::Segment_Effort->new(id =>$id, auth => $self->auth);
75 }
76  
77  
78 4 ▶use WebService::Strava::Athlete::Activity;
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80 0 ▶method activity($id) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine activity: not called CC=3 SCAR=20.7
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
81 0 return WebService::Strava::Athlete::Activity->new(id =>$id, auth => $self->auth);
82 }
83  
84  
85 0 ▶method list_activities(:$activities = 25, :$page = 1, :$before?, :$after?) {
Subroutine BEGIN: called CC=1 SCAR=5.6
Subroutine list_activities: not called CC=8 SCAR=41.4
Branch: 4 branches
BranchTrueFalseTotal
exists $args{'activities'} ? : 0 0 0
exists $args{'page'} ? : 0 0 0
if keys %args 0 0 0
if scalar @_ > 8 0 0 0
86 # TODO: Handle pagination better use #4's solution when found.
87 0 my $url = "/athlete/activities?per_page=$activities&page=$page";
88 0 ▶ $url .= "&before=$before" if $before;
Branch: 1 branch
BranchTrueFalseTotal
if $before 0 0 0
89 0 ▶ $url .= "&after=$after" if $after;
Branch: 1 branch
BranchTrueFalseTotal
if $after 0 0 0
90 0 my $data = $self->auth->get_api("$url");
91 0 my $index = 0;
92 0 foreach my $activity_data (@{$data}) {
93 0 my $activity = WebService::Strava::Athlete::Activity->new(id => $activity_data->{id}, auth => $self->auth, _build => 0);
94 0 $activity->_init_from_api($activity_data);
95 0 @{$data}[$index] = $activity;
96 0 $index++;
97 }
98 0 return $data;
99 }
100  
101  
102 0 ▶method list_friends_activities(:$activities = 25, :$page = 1) {
Subroutine BEGIN: called CC=1 SCAR=5.3
Subroutine list_friends_activities: not called CC=6 SCAR=35.5
Branch: 4 branches
BranchTrueFalseTotal
exists $args{'activities'} ? : 0 0 0
exists $args{'page'} ? : 0 0 0
if keys %args 0 0 0
if scalar @_ > 4 0 0 0
103 # TODO: Handle pagination better use #4's solution when found.
104 0 my $data = $self->auth->get_api("/activities/following?per_page=$activities&page=$page");
105 0 my $index = 0;
106 0 foreach my $activity_data (@{$data}) {
107 0 my $activity = WebService::Strava::Athlete::Activity->new(id => $activity_data->{id}, auth => $self->auth, _build => 0);
108 0 $activity->_init_from_api($activity_data);
109 0 @{$data}[$index] = $activity;
110 0 $index++;
111 }
112 0 return $data;
113 }
114  
115  
116 0 ▶method upload_activity(
Subroutine BEGIN: called CC=1 SCAR=2.0
Subroutine upload_activity: not called CC=4 SCAR=28.7
117 0 :$file,
118 0 ▶ :$type = 'gpx',
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'type'} ? : 0 0 0
119 0 :$activity_type?,
120 0 :$name?,
121 0 :$description?,
122 0 :$private?,
123 0 :$trainer?,
124 0 ▶ :$external_id?,
Branch: 2 branches
BranchTrueFalseTotal
if keys %args 0 0 0
if scalar @_ > 16 0 0 0
125 ) {
126 0 my $data = $self->auth->uploads_api(
127 file => $file,
128 type => $type,
129 activity_type => $activity_type,
130 name => $name,
131 description => $description,
132 private => $private,
133 trainer => $trainer,
134 external_id => $external_id,
135 );
136 0 return $data;
137 }
138  
139  
140 0 ▶method upload_status(:$id) {
Subroutine BEGIN: called CC=1 SCAR=4.6
Subroutine upload_status: not called CC=3 SCAR=21.6
Branch: 2 branches
BranchTrueFalseTotal
if keys %args 0 0 0
if scalar @_ > 2 0 0 0
141 0 my $data = $self->auth->get_api("/uploads/$id");
142 0 return $data;
143 }
144  
145  
146 0 ▶method delete_activity(:$id) {
Subroutine BEGIN: called CC=1 SCAR=4.6
Subroutine delete_activity: not called CC=3 SCAR=21.6
Branch: 2 branches
BranchTrueFalseTotal
if keys %args 0 0 0
if scalar @_ > 2 0 0 0
147 0 my $data = $self->auth->delete_api("/activities/$id");
148 0 return $data;
149 }
150  
151  
152 4 1;
153  
154 __END__
« Strava/Auth.pm ↑ Summary Strava/Athlete.pm »