| 1 | package Net::Async::Spotify::API; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.002'; # VERSION | |||||||||||||||||||||||||||
| 7 | 2 | our $AUTHORITY = 'cpan:VNEALV'; # AUTHORITY | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Scalar::Util qw(isweak weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Module::Runtime qw(require_module); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =encoding utf8 | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Net::Async::Spotify::API - Common Wrapper Package for Spotify API Classes. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Created to give you back Generic Spotify API wrapper. | ||||||||||||||||||||||||||||
| 23 | Not to be used by itself, as in Net::Async::Spotify object must be present. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | use Net::Async::Spotify; | ||||||||||||||||||||||||||||
| 26 | use Net::Async::Spotify::API; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $spotify = Net::Async::Spotify->new; | ||||||||||||||||||||||||||||
| 29 | my $api = Net::Async::Spotify::API->new( | ||||||||||||||||||||||||||||
| 30 | spotify => Net::Async::Spotify->new, # Required | ||||||||||||||||||||||||||||
| 31 | apis => [qw(albums tracks)], # optional | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | ref($api->albums); # Net::Async::Spotify::API::Albums | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # However the way it should be used is the following: | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | my $spotify = Net::Async::Spotify->new(..., apis => [qw(albums tracks)]); | ||||||||||||||||||||||||||||
| 39 | # With apis being optional, and if not set all APIs classes will be present. | ||||||||||||||||||||||||||||
| 40 | $spotify->api->player->skip_users_playback_to_next_track->get(); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | Common Wrapper class to be used in order to give you access for all available Spotify APIs | ||||||||||||||||||||||||||||
| 45 | It will create an instance for the requested API when invoked. | ||||||||||||||||||||||||||||
| 46 | also you can limit which APIs you want to be available by passing them in C<apis> | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head1 METHODS | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head2 new | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Initiate Spotify API Common wrapper. Accepts: | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =over 4 | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item spotify | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | C<Net::Async::Spotify> object must be passed. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item apis | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | arrayref of the needed Spotify APIs to be availabe, if not passed will define all available APIs. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =back | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | die "Net::Async::Spotify has to be provided" unless $args{spotify} and $args{spotify}->isa('Net::Async::Spotify'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"spotify"} and $args{"spotify"}->isa("Net::Async::Spotify")
MC/DC0%0/2
$args{"spotify"} and $args{"spotify"}->isa("Net::Async::Spotify")
$args{"spotify"}
$args{"spotify"}->isa("Net::Async::Spotify")
Truth table0%0/3
A and B
A= $args{"spotify"}B= $args{"spotify"}->isa("Net::Async::Spotify")
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $apis = delete $args{apis} || [qw(albums artists browse episodes follow library markets personalization player playlists search shows tracks users)]; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'apis'} || ['albums', 'artists', 'browse', 'episodes', 'follow', 'library', 'markets', 'personalization', 'player', 'playlists', 'search', 'shows', 'tracks', 'users']
MC/DC0%0/1
delete $args{'apis'} || ['albums', 'artists', 'browse', 'episodes', 'follow', 'library', 'markets', 'personalization', 'player', 'playlists', 'search', 'shows', 'tracks', 'users']
delete $args{'apis'}
Truth table0%0/2
A
A= delete $args{'apis'}
| |||||||||||||||||||||||||||||
| 72 | 0 | my $self = bless \%args, $class; | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | weaken($self->{spotify}) unless isweak($self->{spotify}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | $self->prepare_apis($apis); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | return $self; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub spotify { shift->{spotify} } | ||||||||||||||||||||||||||
|
Subroutine
spotify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub prepare_apis { | ||||||||||||||||||||||||||
|
Subroutine
prepare_apis: not called CC=2 SCAR=14.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 0 | my ($self, $apis) = @_; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | for ( @$apis ) { | |||||||||||||||||||||||||||
| 85 | 0 | my $api = lc $_; | |||||||||||||||||||||||||||
| 86 | 0 | my $accessor = join '::', ref($self), $api; | |||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 0 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | *{$accessor} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | # Define when called. And then cache it. | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | return $self->{$api} //= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{$api} //= do {
my $class = join("::", "Net::Async::Spotify::API", ucfirst $api);
&require_module($class);
$class->new("spotify", $self->spotify)
}
MC/DC0%0/2
$self->{$api} //= do {
my $class = join("::", "Net::Async::Spotify::API", ucfirst $api);
&require_module($class);
$class->new("spotify", $self->spotify)
}
$self->{$api}
do {
my $class = join("::", "Net::Async::Spotify::API", ucfirst $api);
&require_module($class);
$class->new("spotify", $self->spotify)
}
Truth table0%0/3
A //= B
A= $self->{$api}B= do {
my $class = join("::", "Net::Async::Spotify::API", ucfirst $api);
&require_module($class);
$class->new("spotify", $self->spotify)
}
| |||||||||||||||||||||||||||||
| 93 | 0 | my $class = join '::', 'Net::Async::Spotify::API', ucfirst $api; | |||||||||||||||||||||||||||
| 94 | 0 | require_module($class); | |||||||||||||||||||||||||||
| 95 | # Note its not weak anymore, since passing a copy. | ||||||||||||||||||||||||||||
| 96 | 0 | $class->new(spotify => $self->spotify); | |||||||||||||||||||||||||||
| 97 | }; | ||||||||||||||||||||||||||||
| 98 | 0 | }; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 2 | 1; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 APIs | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | List of available APIs for Spotify. Official list found here L<https://developer.spotify.com/documentation/web-api/reference/#reference-index> | ||||||||||||||||||||||||||||
| 108 | These are the defined classes for them: | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =over 4 | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | =item * | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | L<Net::Async::Spotify::API::Albums> | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =item * | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | L<Net::Async::Spotify::API::Artists> | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item * | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | L<Net::Async::Spotify::API::Base> | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =item * | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | L<Net::Async::Spotify::API::Browse> | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =item * | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | L<Net::Async::Spotify::API::Episodes> | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =item * | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | L<Net::Async::Spotify::API::Follow> | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =item * | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | L<Net::Async::Spotify::API::Library> | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =item * | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | L<Net::Async::Spotify::API::Markets> | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =item * | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | L<Net::Async::Spotify::API::Personalization> | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =item * | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | L<Net::Async::Spotify::API::Player> | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =item * | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | L<Net::Async::Spotify::API::Playlists> | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =item * | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | L<Net::Async::Spotify::API::Search> | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | =item * | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | L<Net::Async::Spotify::API::Shows> | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =item * | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | L<Net::Async::Spotify::API::Tracks> | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =item * | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | L<Net::Async::Spotify::API::Users> | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =back | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||