view release on metacpan or search on metacpan
Holder, and derivatives of that collection of files created through
textual modification.
- "Standard Version" refers to such a Package if it has not been modified,
or has been modified in accordance with the wishes of the Copyright
Holder.
- "Copyright Holder" is whoever is named in the copyright or copyrights for
the package.
- "You" is you, if you're thinking about copying or distributing this Package.
- "Reasonable copying fee" is whatever you can justify on the basis of media
cost, duplication charges, time of people involved, and so on. (You will
not be required to justify it to the Copyright Holder, but only to the
computing community at large as a market that must bear the fee.)
- "Freely Available" means that no fee is charged for the item itself, though
there may be fees involved in handling the item. It also means that
recipients of the item may redistribute it under the same conditions they
received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated disclaimers.
lib/API/Instagram.pm view on Meta::CPAN
use JSON;
use Furl;
use API::Instagram::User;
use API::Instagram::Location;
use API::Instagram::Tag;
use API::Instagram::Media;
use API::Instagram::Media::Comment;
use API::Instagram::Search;
has client_id => ( is => 'ro', required => 1 );
has client_secret => ( is => 'ro', required => 1 );
has redirect_uri => ( is => 'ro', required => 1 );
has scope => ( is => 'ro', default => sub { 'basic' } );
has response_type => ( is => 'ro', default => sub { 'code' } );
has grant_type => ( is => 'ro', default => sub { 'authorization_code' } );
has code => ( is => 'rw', isa => sub { confess "Code not provided" unless $_[0] } );
has access_token => ( is => 'rw', isa => sub { confess "No access token provided" unless $_[0] } );
has no_cache => ( is => 'rw', default => sub { 0 } );
has _ua => ( is => 'ro', default => sub { Furl->new() } );
has _obj_cache => ( is => 'ro', default => sub { { User => {}, Media => {}, Location => {}, Tag => {}, 'Media::Comment' => {} } } );
has _endpoint_url => ( is => 'ro', default => sub { 'https://api.instagram.com/v1' } );
lib/API/Instagram.pm view on Meta::CPAN
sub instance { $instance //= shift->new(@_) }
sub get_auth_url {
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' ) }
sub location { shift->_get_obj( 'Location', 'id', shift, 1 ) }
lib/API/Instagram.pm view on Meta::CPAN
}
##############################################################
# Requests the data from the given URL with QUERY parameters #
##############################################################
sub _request {
my ( $self, $method, $url, $params, $opts ) = @_;
# Verifies access requirements
unless ( defined $self->access_token ) {
if ( !$opts->{token_not_required} or !defined $self->client_id ) {
carp "A valid access_token is required";
return {}
}
}
# If URL is not prepared, prepares it
unless ( $opts->{prepared_url} ){
$url =~ s|^/||;
$params->{access_token} = $self->access_token;
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' } );
lib/API/Instagram/Media/Comment.pm view on Meta::CPAN
package API::Instagram::Media::Comment;
# ABSTRACT: Instagram Media Comment Object
use Moo;
use Time::Moment;
has id => ( is => 'ro', required => 1 );
has from => ( is => 'ro', required => 1, coerce => sub { API::Instagram->instance->user( $_[0] ) } );
has text => ( is => 'ro', required => 1 );
has media => ( is => 'ro', required => 1 );
has created_time => ( is => 'ro', coerce => sub { Time::Moment->from_epoch( $_[0] ) } );
sub remove {
my $self = shift;
my $url = sprintf "media/%s/comments/%s", $self->media->id, $self->id;
$self->media->_api->_del( $url )
}
1;
lib/API/Instagram/Search.pm view on Meta::CPAN
use Moo;
my $search = {
user => 'users/search',
media => 'media/search',
tag => 'tags/search',
location => 'locations/search',
};
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 } ) ]
}
lib/API/Instagram/Search.pm view on Meta::CPAN
q => 'larry', # A query string
count => 5, # Number of users to return
);
See L<http://instagram.com/developer/endpoints/users/#get_users_search>.
B<media> parameters:
my $search = $instagram->search('media');
$search->find(
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.
min_timestamp => 1408720000, # A unix timestamp. All media returned will be taken later than this timestamp.
max_timestamp => 1408723333, # A unix timestamp. All media returned will be taken earlier than this timestamp.
distance => 500, # Default is 1km (distance=1000), max distance is 5km.
);
See L<http://instagram.com/developer/endpoints/media/#get_media_search>.
B<tag> parameters:
my $search = $instagram->search('tag');
lib/API/Instagram/Search.pm view on Meta::CPAN
q => 'perl', # A valid tag name without a leading #.
);
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/Tag.pm view on Meta::CPAN
package API::Instagram::Tag;
# ABSTRACT: Instagram Tag Object
use Moo;
has name => ( is => 'ro', required => 1 );
has _data => ( is => 'rwp', lazy => 1, builder => 1, clearer => 1 );
sub media_count {
my $self = shift;
$self->_clear_data if shift;
$self->_data->{media_count}
}
sub recent_medias {
lib/API/Instagram/User.pm view on Meta::CPAN
package API::Instagram::User;
# ABSTRACT: Instagram User Object
use Moo;
use Carp;
has id => ( is => 'ro', required => 1 );
has username => ( is => 'lazy' );
has full_name => ( is => 'lazy' );
has bio => ( is => 'lazy' );
has website => ( is => 'lazy' );
has profile_picture => ( is => 'lazy' );
has _api => ( is => 'lazy' );
has _data => ( is => 'rwp', lazy => 1, builder => 1, clearer => 1 );
sub media {
my $self = shift;
lib/API/Instagram/User.pm view on Meta::CPAN
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 ) {