forked from rizen/Facebook-Graph
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |