Skip to content

Commit

Permalink
added links
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed Aug 11, 2010
1 parent affbd16 commit 7fa41e1
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Added likes publishing.
- Added comment publishing.
- Added note publishing.
- Added link publishing.

0.0500 August 10, 2010
- Added feed/wall publishing.
Expand Down
18 changes: 18 additions & 0 deletions author.t/publish_comment.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use Test::More tests => 4;
use lib '../lib';

use_ok('Facebook::Graph');
my $fb = Facebook::Graph->new;
isa_ok($fb, 'Facebook::Graph');

die "You need to set an environment variable for FB_ACCESS_TOKEN to test this" unless $ENV{FB_ACCESS_TOKEN};

$fb->access_token($ENV{FB_ACCESS_TOKEN});

my $response = $fb->add_comment('1647395831_1452098916277')
->set_message('This is a test comment.')
->publish;
my $out = $response->as_hashref;
ok(ref $out eq 'HASH', 'got a hash back') or debug($response->as_json);
ok(exists $out->{id}, 'we got back an id');

19 changes: 19 additions & 0 deletions author.t/publish_link.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use Test::More tests => 4;
use lib '../lib';

use_ok('Facebook::Graph');
my $fb = Facebook::Graph->new;
isa_ok($fb, 'Facebook::Graph');

die "You need to set an environment variable for FB_ACCESS_TOKEN to test this" unless $ENV{FB_ACCESS_TOKEN};

$fb->access_token($ENV{FB_ACCESS_TOKEN});

my $response = $fb->add_link
->set_message('The Game Crafter')
->set_link_uri('http://www.thegamecrafter.com/')
->publish;
my $out = $response->as_hashref;
ok(ref $out eq 'HASH', 'got a hash back') or debug($response->as_json);
ok(exists $out->{id}, 'we got back an id');

18 changes: 18 additions & 0 deletions lib/Facebook/Graph.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Facebook::Graph::Publish::Post;
use Facebook::Graph::Publish::Like;
use Facebook::Graph::Publish::Comment;
use Facebook::Graph::Publish::Note;
use Facebook::Graph::Publish::Link;

has app_id => (
is => 'ro',
Expand Down Expand Up @@ -131,6 +132,18 @@ sub add_note {
return Facebook::Graph::Publish::Note->new( %params );
}

sub add_link {
my ($self) = @_;
my %params;
if ($self->has_access_token) {
$params{access_token} = $self->access_token;
}
if ($self->has_secret) {
$params{secret} = $self->secret;
}
return Facebook::Graph::Publish::Link->new( %params );
}



no Any::Moose;
Expand Down Expand Up @@ -300,6 +313,11 @@ The id of the post you want to comment on.
Creates a L<Facebook::Graph::Publish::Note> object, which can be used to publish notes.
=head2 add_link ( )
Creates a L<Facebook::Graph::Publish::Link> object, which can be used to publish links.
Expand Down
108 changes: 108 additions & 0 deletions lib/Facebook/Graph/Publish/Link.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package Facebook::Graph::Publish::Link;

use Any::Moose;
extends 'Facebook::Graph::Publish';

use constant object_path => '/links';

has message => (
is => 'rw',
predicate => 'has_message',
);

sub set_message {
my ($self, $message) = @_;
$self->message($message);
return $self;
}

has link_uri => (
is => 'rw',
predicate => 'has_link_uri',
);

sub set_link_uri {
my ($self, $link_uri) = @_;
$self->link_uri($link_uri);
return $self;
}



around get_post_params => sub {
my ($orig, $self) = @_;
my $post = $orig->($self);
if ($self->has_access_token) {
$post->{access_token} = $self->access_token;
}
if ($self->has_message) {
$post->{message} = $self->message;
}
if ($self->has_link_uri) {
$post->{link} = $self->link_uri;
}
return $post;
};


no Any::Moose;
__PACKAGE__->meta->make_immutable;


=head1 NAME
Facebook::Graph::Publish::Link - Add a link.
=head1 SYNOPSIS
my $fb = Facebook::Graph->new;
$fb->add_link
->set_link_uri('http://www.plainblack.com')
->set_message('Plain Black')
->publish;
=head1 DESCRIPTION
This module gives you quick and easy access to publish notes.
B<ATTENTION:> You must have the C<publish_stream> privilege to use this module.
=head1 METHODS
=head2 to ( id )
Specify a profile id to post to. Defaults to 'me', which is the currently logged in user.
=head2 set_message ( message )
Sets the description of the link.
=head3 message
A string of text.
=head2 set_link_uri ( uri )
Sets the URI to link to.
=head3 uri
A a URI.
=head2 publish ( )
Posts the data and returns a L<Facebook::Graph::Response> object. The response object should contain the id:
{"id":"1647395831_130068550371568"}
=head1 LEGAL
Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
=cut

0 comments on commit 7fa41e1

Please sign in to comment.