API-Instagram
view release on metacpan or search on metacpan
lib/API/Instagram.pm view on Meta::CPAN
my $self = shift;
carp "User already authorized with code: " . $self->code if $self->code;
my @auth_fields = qw(client_id redirect_uri response_type scope);
for ( @auth_fields ) {
carp "ERROR: $_ required for generating authorization URL" and return unless defined $self->$_;
}
my $uri = URI->new( $self->_authorize_url );
$uri->query_form( map { $_ => $self->$_ } @auth_fields );
$uri->as_string();
}
sub get_access_token {
my $self = shift;
my @access_token_fields = qw(client_id redirect_uri grant_type client_secret code);
for ( @access_token_fields ) {
carp "ERROR: $_ required for generating access token." and return unless defined $self->$_;
}
my $data = { map { $_ => $self->$_ } @access_token_fields };
my $json = $self->_request( 'post', $self->_access_token_url, $data, { token_not_required => 1 } );
wantarray ? ( $json->{access_token}, $self->user( $json->{user} ) ) : $json->{access_token};
}
sub media { shift->_get_obj( 'Media', 'id', shift ) }
sub user { shift->_get_obj( 'User', 'id', shift // 'self' ) }
lib/API/Instagram.pm view on Meta::CPAN
return $return;
}
###################################
# Returns a list of Media Objects #
###################################
sub _medias {
my ($self, $url, $params, $opts) = @_;
$params->{count} //= 33;
$params->{url} = $url;
[ map { $self->media($_) } $self->_get_list( { %$params, url => $url }, $opts ) ]
}
####################################################################
# Returns a list of the requested items. Does pagination if needed #
####################################################################
sub _get_list {
my $self = shift;
my $params = shift;
my $opts = shift;
lib/API/Instagram/Media.pm view on Meta::CPAN
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;
lib/API/Instagram/Media.pm view on Meta::CPAN
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} } ]
}
sub get_comments {
my $self = shift;
my %opts = @_;
my $url = sprintf "media/%s/comments", $self->id;
my $api = $self->_api;
[ map { $api->_comment( { %$_, media => $self } ) } $api->_get_list( { %opts, url => $url } ) ]
}
sub comment {
my $self = shift;
my $text = shift;
my $url = sprintf "media/%s/comments", $self->id;
$self->_api->_post( $url, { text => $text } )
}
lib/API/Instagram/Media.pm view on Meta::CPAN
############################################################
# Attributes coercion that API::Instagram object reference #
############################################################
sub _coerce_user { API::Instagram->instance->user ( $_[0] ) };
sub _coerce_location { API::Instagram->instance->location( $_[0] ) if $_[0] };
sub _coerce_tags {
my $data = $_[0];
return if ref $data ne 'ARRAY';
[ map { API::Instagram->instance->tag($_) } @$data ]
};
sub _coerce_users_in_photo {
my $data = $_[0];
return if ref $data ne 'ARRAY';
[
map {{
user => API::Instagram->instance->user( $_->{user} ),
position => $_->{position},
}} @$data
]
};
1;
__END__
lib/API/Instagram/Search.pm view on Meta::CPAN
has type => ( is => 'ro', required => 1, isa => sub { die "Type not supported." unless $search->{$_[0]} } );
sub find {
my $self = shift;
my %opts = @_;
my $type = $self->type;
my $url = $search->{$type};
my $api = API::Instagram->instance;
[ map { $api->$type($_) } $api->_get_list( { %opts, url => $url } ) ]
}
1;
__END__
=pod
=encoding UTF-8
lib/API/Instagram/Search.pm view on Meta::CPAN
See L<http://instagram.com/developer/endpoints/tags/#get_tags_search>.
B<location> parameters:
my $search = $instagram->search('location');
$search->find(
distance => 2000, # Default is 1000m (distance=1000), max distance is 5000.
lat => 48.858844, # Latitude of the center search coordinate. If used, lng is required.
lng => 2.294351, # Longitude of the center search coordinate. If used, lat is required.
facebook_places_id => 123, # Returns a location mapped off of a Facebook places id. If used, a Foursquare id and lat, lng are not required.
foursquare_id => 456, # Returns a location mapped off of a foursquare v1 api location id. If used, you are not required to use lat and lng. Note that this method is deprecated; you should use the new foursquare IDs with V2 of their API.
foursquare_v2_id => 789, # Returns a location mapped off of a foursquare v2 api location id. If used, you are not required to use lat and lng.
);
See L<http://instagram.com/developer/endpoints/locations/#get_locations_search>.
=head1 AUTHOR
Gabriel Vieira <gabriel.vieira@gmail.com>
=head1 COPYRIGHT AND LICENSE
lib/API/Instagram/User.pm view on Meta::CPAN
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' );
lib/API/Instagram/User.pm view on Meta::CPAN
$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;
}
( run in 0.717 second using v1.01-cache-2.11-cpan-140bd7fdf52 )