API-Instagram

 view release on metacpan or  search on metacpan

lib/API/Instagram/Media.pm  view on Meta::CPAN

package API::Instagram::Media;

# ABSTRACT: Instagram Media Object

use Moo;
use Time::Moment;

has id             => ( is => 'ro', required => 1 );
has type           => ( is => 'lazy' );
has link           => ( is => 'lazy' );
has filter         => ( is => 'lazy' );
has images         => ( is => 'lazy' );
has videos         => ( is => 'lazy' );
has user           => ( is => 'lazy', coerce => \&_coerce_user           );
has tags           => ( is => 'lazy', coerce => \&_coerce_tags           );
has location       => ( is => 'lazy', coerce => \&_coerce_location       );
has users_in_photo => ( is => 'lazy', coerce => \&_coerce_users_in_photo );
has caption        => ( is => 'lazy', coerce => sub { $_[0]->{text} if $_[0] and ref $_[0] eq 'HASH' } );
has created_time   => ( is => 'lazy', coerce => sub { Time::Moment->from_epoch( $_[0] ) } );
has _api           => ( is => 'lazy' );
has _data          => ( is => 'rwp', lazy => 1, builder => 1, clearer => 1 );

sub likes {
	my $self = shift;
	$self->_clear_data if shift;
	$self->_data->{likes}->{count}
}

sub last_likes {
	my $self = shift;
	$self->_clear_data if shift;
	my $api  = $self->_api;
	[ map { $api->user($_) } @{ $self->_data->{likes}->{data} } ]
}

sub get_likes {
	my $self = shift;
	my %opts = @_;
	my $url  = sprintf "media/%s/likes", $self->id;
	my $api  = $self->_api;
	[ map { $api->user($_) } $api->_get_list( { %opts, url => $url } ) ]
}

sub like {
	my $self = shift;
	my $url  = sprintf "media/%s/likes", $self->id;
	$self->_api->_post( $url )
}

sub dislike {
	my $self = shift;
	my $url  = sprintf "media/%s/likes", $self->id;
	$self->_api->_del( $url )
}

sub comments {
	my $self = shift;
	$self->_clear_data if shift;
	$self->_data->{comments}->{count}
}

sub last_comments {
	my $self = shift;
	$self->_clear_data if shift;
	my $api  = $self->_api;
	[ map { $api->_comment( { %$_, media => $self } ) } @{ $self->_data->{comments}->{data} } ]
}



( run in 0.604 second using v1.01-cache-2.11-cpan-13bb782fe5a )