| 1 | package WebService::Strava::Club; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 4 | ▶ | use v5.010; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 4 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||
|
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 Scalar::Util::Reftype; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 4 | ▶ | use Data::Dumper; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 4 | ▶ | use Method::Signatures 20140224; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | 4 | ▶ | use Moo; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 4 | ▶ | use namespace::clean; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | # ABSTRACT: A Strava Club Object | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | 4 | our $VERSION = '0.06'; # VERSION: Generated by DZP::OurPkg:Version | |||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | # Validation functions | ||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | 0 | ▶ | my $Ref = sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 22 | 0 | ▶ | croak "auth isn't a 'WebService::Strava::Auth' object!" unless reftype( $_[0] )->class eq "WebService::Strava::Auth"; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 23 | 4 | }; | |||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | 0 | ▶ | my $Bool = sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 26 | 0 | ▶ | croak "$_[0] must be 0|1" unless $_[0] =~ /^[01]$/; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 27 | 4 | }; | |||||||||||||||||||||
| 28 | |||||||||||||||||||||||
| 29 | 0 | ▶ | my $Num = sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 30 | 0 | ▶ | croak "$_[0] isn't a valid id" unless looks_like_number $_[0]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 31 | 4 | }; | |||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | # Debugging hooks in case things go weird. (Thanks @pjf) | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | 0 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 36 | 0 | my $orig = shift; | |||||||||||||||||||||
| 37 | 0 | my $class = shift; | |||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | 0 | ▶ | if ($WebService::Strava::DEBUG) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 40 | 0 | warn "Building task with:\n"; | |||||||||||||||||||||
| 41 | 0 | warn Dumper(\@_), "\n"; | |||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 0 | return $class->$orig(@_); | |||||||||||||||||||||
| 45 | 4 | }; | |||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | # Authentication Object | ||||||||||||||||||||||
| 48 | 4 | has 'auth' => ( is => 'ro', required => 1, isa => $Ref ); | |||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | # Defaults + Required | ||||||||||||||||||||||
| 51 | 4 | has 'id' => ( is => 'ro', required => 1, isa => $Num); | |||||||||||||||||||||
| 52 | 0 | ▶ | has '_build' => ( is => 'ro', default => sub { 1 }, isa => $Bool ); | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | 4 | has 'profile' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 55 | 4 | has 'name' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 56 | 4 | has 'state' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 57 | 4 | has 'city' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 58 | 4 | has 'sport_type' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 59 | 4 | has 'description' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 60 | 4 | has 'member_count' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 61 | 4 | has 'country' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 62 | 4 | has 'club_type' => ( is => 'ro', lazy => 1, builder => '_build_club' ); | |||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||
|
Subroutine
BUILD: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | 0 | ▶ | if ($self->{_build}) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 68 | 0 | $self->_build_club(); | |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | 0 | return; | |||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | 0 | ▶ | method _build_club() { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
_build_club: not called CC=3 SCAR=20.7
Branch: 1 branch
| |||||||||||||||||||||||
| 74 | 0 | my $club = $self->auth->get_api("/clubs/$self->{id}"); | |||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | 0 | foreach my $key (keys %{ $club }) { | |||||||||||||||||||||
| 77 | 0 | $self->{$key} = $club->{$key}; | |||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | 0 | return; | |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | 0 | ▶ | method retrieve() { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
Subroutine
retrieve: not called CC=2 SCAR=12.4
Branch: 1 branch
| |||||||||||||||||||||||
| 85 | 0 | $self->_build_club(); | |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | 0 | ▶ | method list_members(:$members = 25, :$page = 1) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=5.3
Subroutine
list_members: not called CC=6 SCAR=35.4
Branch: 4 branches
| |||||||||||||||||||||||
| 90 | # TODO: Handle pagination better use #4's solution when found. | ||||||||||||||||||||||
| 91 | 0 | my $data = $self->auth->get_api("/clubs/$self->{id}/members?per_page=$members&page=$page"); | |||||||||||||||||||||
| 92 | 0 | my $index = 0; | |||||||||||||||||||||
| 93 | 0 | foreach my $member (@{$data}) { | |||||||||||||||||||||
| 94 | 0 | @{$data}[$index] = WebService::Strava::Athlete->new(id => $member->{id}, auth => $self->auth, _build => 0); | |||||||||||||||||||||
| 95 | 0 | $index++; | |||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||
| 97 | 0 | return $data; | |||||||||||||||||||||
| 98 | }; | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | 0 | ▶ | method list_activities(:$activities = 25, :$page = 1) { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=5.3
Subroutine
list_activities: not called CC=6 SCAR=35.4
Branch: 4 branches
| |||||||||||||||||||||||
| 102 | # TODO: Handle pagination better use #4's solution when found. | ||||||||||||||||||||||
| 103 | 0 | my $data = $self->auth->get_api("/clubs/$self->{id}/activities?per_page=$activities&page=$page"); | |||||||||||||||||||||
| 104 | 0 | my $index = 0; | |||||||||||||||||||||
| 105 | 0 | foreach my $activity (@{$data}) { | |||||||||||||||||||||
| 106 | 0 | @{$data}[$index] = WebService::Strava::Athlete::Activity->new(id => $activity->{id}, auth => $self->auth, _build => 0); | |||||||||||||||||||||
| 107 | 0 | $index++; | |||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||
| 109 | 0 | return $data; | |||||||||||||||||||||
| 110 | }; | ||||||||||||||||||||||
| 111 | |||||||||||||||||||||||
| 112 | 4 | 1; | |||||||||||||||||||||
| 113 | |||||||||||||||||||||||
| 114 | __END__ | ||||||||||||||||||||||