API-Instagram

 view release on metacpan or  search on metacpan

CHANGES  view on Meta::CPAN


------------------------------------------
version 0.013 at 2014-08-28 03:57:09 +0000
------------------------------------------

  Change: c9e9ae4852ac563c904f3a1a22d750ef47373db6
  Author: Gabriel Vieira <gabriel.vieira@gmail.com>
  Date : 2014-08-28 00:52:40 +0000

    Starting version 0.013. Removed comment method from API::Instagram
    (replaced by internal _comment method). Added _post, _get_, _del
    methods, proxy to _request main method in API::Instagram. Added
    like,dislike and comment methods to API::Instagram::Media. Added
    media attribute to API::Instagram::Media::Comment. Added remove
    method to API::Instagram::Media::Comment. 

  Change: ec7504d1d44f315b5db6c0d07a19fffe3dcbf9d5
  Author: Gabriel Vieira <gabriel.vieira@gmail.com>
  Date : 2014-08-27 00:20:02 +0000

    Tests reorganized 

LICENSE  view on Meta::CPAN


2. You may apply bug fixes, portability fixes and other modifications derived
from the Public Domain or from the Copyright Holder. A Package modified in such
a way shall still be considered the Standard Version.

3. You may otherwise modify your copy of this Package in any way, provided that
you insert a prominent notice in each changed file stating how and when you
changed that file, and provided that you do at least ONE of the following:

  a) place your modifications in the Public Domain or otherwise make them
     Freely Available, such as by posting said modifications to Usenet or an
     equivalent medium, or placing the modifications on a major archive site
     such as ftp.uu.net, or by allowing the Copyright Holder to include your
     modifications in the Standard Version of the Package.

  b) use the modified Package only within your corporation or organization.

  c) rename any non-standard executables so the names do not conflict with
     standard executables, which must also be provided, and provide a separate
     manual page for each non-standard executable that clearly documents how it
     differs from the Standard Version.

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


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


use Data::Dumper;
# die Dumper $res;
	$res;
}

sub _request_data { shift->_request(@_)->{data} || {} }

sub _del  { shift->_request_data( 'delete', @_ ) }
sub _get  { shift->_request_data( 'get',    @_ ) }
sub _post { shift->_request_data( 'post',   @_ ) }

################################
# Returns requested cache hash #
################################
sub _cache { shift->_obj_cache->{ shift() } }


1;

__END__

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

	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;

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

	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 } )
}


sub _build__api           { API::Instagram->instance       }
sub _build_user           { shift->_data->{user}           }
sub _build_tags           { shift->_data->{tags}           }
sub _build_location       { shift->_data->{location}       }
sub _build_users_in_photo { shift->_data->{users_in_photo} }
sub _build_type           { shift->_data->{type}           }
sub _build_link           { shift->_data->{link}           }

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

=head2 id

Returns media id.

=head2 type

Returns media type.

=head2 user

Returns the L<API::Instagram::User> object of the user who posted the media.

=head2 link

Returns media shortlink.

=head2 filter

Returns media filter.

=head2 tags

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

=head2 text

Returns the text commented.

=head2 created_time

Returns the comment date in a L<Time::Moment> object.

=head2 media

Returns the media where the comment was posted.

=head1 METHODS

=head2 remove

	$comment->remove;

Removes the comment either on the authenticated user's media object or authored by the authenticated user.

=head1 AUTHOR

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


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;

t/00-instagram.t  view on Meta::CPAN

use Inline::Files;

use API::Instagram;
use Test::More tests => 17;

my $data = join '', <DATA>;
my $ua   = Test::MockObject::Extends->new( Furl->new() );
my $res  = Test::MockObject::Extends->new( Furl::Response->new( 1, 200, 'OK', {}, $data) );

$ua->mock('get',  sub { $res });
$ua->mock('post', sub { $res });

my $api = API::Instagram->new({
			client_id     => '123',
			client_secret => '456',
			redirect_uri  => 'http://localhost',
            no_cache      => 1,
            _ua           => $ua,
});


t/04-user.t  view on Meta::CPAN

			client_id     => '123',
			client_secret => '456',
			redirect_uri  => 'http://localhost',
            no_cache      => 1
	})
);

my $data = join '', <DATA>;
my $json = decode_json $data;
$api->mock('_request', sub { $json });
$api->mock('_post',    sub { $json });

my $user = $api->user( 123 );
isa_ok( $user, 'API::Instagram::User' );

is ref $user->relationship, 'HASH';
is $user->relationship->{incoming_status}, 'requested_by';
is ref $user->relationship('block'), 'HASH';
is ref $user->relationship('undef'), 'HASH';

__DATA__

weaver.ini  view on Meta::CPAN

 
[Collect / ATTRIBUTES]
command = attr
 
[Collect / METHODS]
command = method
 
[Collect / FUNCTIONS]
command = func
  
[Region  / postlude]
 
[Authors]
[Legal]

[-Transformer]
transformer = List



( run in 1.516 second using v1.01-cache-2.11-cpan-ceb78f64989 )