API-Instagram
view release on metacpan or search on metacpan
lib/API/Instagram/User.pm view on Meta::CPAN
sub follows {
my $self = shift;
$self->_clear_data if shift;
return $_->{follows} for $self->_data->{counts}
}
sub followed_by {
my $self = shift;
$self->_clear_data if shift;
return $_->{followed_by} for $self->_data->{counts}
}
sub feed {
my $self = shift;
my @list = $self->_self_requests( 'feed', '/users/self/feed', @_ ) or return;
[ map { $self->_api->media($_) } @list ];
}
sub liked_media {
my $self = shift;
my @list = $self->_self_requests( 'liked-media', '/users/self/media/liked', @_ ) or return;
[ map { $self->_api->media($_) } @list ];
}
sub requested_by {
my $self = shift;
my @list = $self->_self_requests( 'requested-by', '/users/self/requested-by', @_ ) or return;
[ map { $self->_api->user($_) } @list ];
}
sub get_follows {
shift->_get_relashions( @_, relationship => 'follows' );
}
sub get_followers {
shift->_get_relashions( @_, relationship => 'followed-by' );
}
sub recent_medias {
my $self = shift;
my $url = sprintf "users/%s/media/recent", $self->id;
$self->_api->_medias( $url, { @_%2?():@_ }, { token_not_required => 1 } );
}
sub relationship {
my $self = shift;
my $action = shift;
my $url = sprintf "users/%s/relationship", $self->id;
my @actions = qw/ follow unfollow block unblock approve ignore/;
use experimental 'smartmatch';
if ( $action ) {
if ( $action ~~ @actions ){
return $self->_api->_post( $url, { action => $action } )
}
carp "Invalid action";
}
$self->_api->_get( $url );
}
sub _get_relashions {
my $self = shift;
my %opts = @_;
my $url = sprintf "users/%s/%s", $self->id, $opts{relationship};
my $api = $self->_api;
[ map { $api->user($_) } $api->_get_list( { %opts, url => $url } ) ]
}
sub _self_requests {
my ($self, $type, $url, %opts) = @_;
if ( $self->id ne $self->_api->user->id ){
carp "The $type is only available for the authenticated user";
return;
}
$self->_api->_get_list( { %opts, url => $url } )
}
sub BUILDARGS {
my $self = shift;
my $opts = shift;
$opts->{profile_picture} //= delete $opts->{profile_pic_url} if exists $opts->{profile_pic_url};
return $opts;
}
sub _build__api { API::Instagram->instance }
sub _build_username { shift->_data->{username} }
sub _build_full_name { shift->_data->{full_name} }
sub _build_bio { shift->_data->{bio} }
sub _build_website { shift->_data->{website} }
sub _build_profile_picture { shift->_data->{profile_picture} }
sub _build__data {
my $self = shift;
my $url = sprintf "users/%s", $self->id;
$self->_api->_get( $url );
}
1;
__END__
=pod
=encoding UTF-8
( run in 0.700 second using v1.01-cache-2.11-cpan-ceb78f64989 )