source: perl/modules/Facebook/lib/Facebook/Graph/Publish.pm @ 2a42248

release-1.10release-1.9
Last change on this file since 2a42248 was 2a42248, 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
Line 
1package Facebook::Graph::Publish;
2BEGIN {
3  $Facebook::Graph::Publish::VERSION = '1.0300';
4}
5
6use Any::Moose;
7use Facebook::Graph::Response;
8with 'Facebook::Graph::Role::Uri';
9use LWP::UserAgent;
10use URI::Encode qw(uri_decode);
11
12has secret => (
13    is          => 'ro',
14    required    => 0,
15    predicate   => 'has_secret',
16);
17
18has access_token => (
19    is          => 'ro',
20    predicate   => 'has_access_token',
21);
22
23has object_name => (
24    is          => 'rw',
25    default     => 'me',
26);
27
28sub to {
29    my ($self, $object_name) = @_;
30    $self->object_name($object_name);
31    return $self;
32}
33
34sub 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
43sub 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
55no Any::Moose;
56__PACKAGE__->meta->make_immutable;
57
58
59=head1 NAME
60
61Facebook::Graph::Publish - A base class for publishing various things to facebook.
62
63=head1 VERSION
64
65version 1.0300
66
67=head1 DESCRIPTION
68
69This module shouldn't be used by you directly for any purpose.
70
71=head1 LEGAL
72
73Facebook::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.