Last change
on this file since cfca761 was
cfca761,
checked in by Edward Z. Yang <ezyang@mit.edu>, 13 years ago
|
Add vanilla Facebook::Graph.
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[cfca761] | 1 | package Facebook::Graph::Publish; |
---|
| 2 | BEGIN { |
---|
| 3 | $Facebook::Graph::Publish::VERSION = '1.0300'; |
---|
| 4 | } |
---|
| 5 | |
---|
| 6 | use Any::Moose; |
---|
| 7 | use Facebook::Graph::Response; |
---|
| 8 | with 'Facebook::Graph::Role::Uri'; |
---|
| 9 | use LWP::UserAgent; |
---|
| 10 | use URI::Encode qw(uri_decode); |
---|
| 11 | |
---|
| 12 | has secret => ( |
---|
| 13 | is => 'ro', |
---|
| 14 | required => 0, |
---|
| 15 | predicate => 'has_secret', |
---|
| 16 | ); |
---|
| 17 | |
---|
| 18 | has access_token => ( |
---|
| 19 | is => 'ro', |
---|
| 20 | predicate => 'has_access_token', |
---|
| 21 | ); |
---|
| 22 | |
---|
| 23 | has object_name => ( |
---|
| 24 | is => 'rw', |
---|
| 25 | default => 'me', |
---|
| 26 | ); |
---|
| 27 | |
---|
| 28 | sub to { |
---|
| 29 | my ($self, $object_name) = @_; |
---|
| 30 | $self->object_name($object_name); |
---|
| 31 | return $self; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | sub get_post_params { |
---|
| 35 | my $self = shift; |
---|
| 36 | my @post; |
---|
| 37 | if ($self->has_access_token) { |
---|
| 38 | push @post, access_token => uri_decode($self->access_token); |
---|
| 39 | } |
---|
| 40 | return \@post; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | sub publish { |
---|
| 44 | my ($self) = @_; |
---|
| 45 | my $uri = $self->uri; |
---|
| 46 | $uri->path($self->object_name.$self->object_path); |
---|
| 47 | my $response = LWP::UserAgent->new->post($uri, $self->get_post_params); |
---|
| 48 | my %params = (response => $response); |
---|
| 49 | if ($self->has_secret) { |
---|
| 50 | $params{secret} = $self->secret; |
---|
| 51 | } |
---|
| 52 | return Facebook::Graph::Response->new(%params); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | no Any::Moose; |
---|
| 56 | __PACKAGE__->meta->make_immutable; |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | =head1 NAME |
---|
| 60 | |
---|
| 61 | Facebook::Graph::Publish - A base class for publishing various things to facebook. |
---|
| 62 | |
---|
| 63 | =head1 VERSION |
---|
| 64 | |
---|
| 65 | version 1.0300 |
---|
| 66 | |
---|
| 67 | =head1 DESCRIPTION |
---|
| 68 | |
---|
| 69 | This module shouldn't be used by you directly for any purpose. |
---|
| 70 | |
---|
| 71 | =head1 LEGAL |
---|
| 72 | |
---|
| 73 | Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself. |
---|
| 74 | |
---|
| 75 | =cut |
---|
Note: See
TracBrowser
for help on using the repository browser.