source: perl/modules/Facebook/lib/Facebook/Graph/Publish.pm @ 5ef98c7

release-1.10release-1.9
Last change on this file since 5ef98c7 was 5ef98c7, checked in by Edward Z. Yang <ezyang@mit.edu>, 13 years ago
Fix broken posts, better permission detection, implement deletion. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
  • Property mode set to 100644
File size: 1.9 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 AnyEvent::HTTP;
10use LWP::UserAgent; # XXX blegh
11use HTTP::Request::Common;
12use URI::Encode qw(uri_decode uri_encode);
13
14has secret => (
15    is          => 'ro',
16    required    => 0,
17    predicate   => 'has_secret',
18);
19
20has access_token => (
21    is          => 'ro',
22    predicate   => 'has_access_token',
23);
24
25has object_name => (
26    is          => 'rw',
27    default     => 'me',
28);
29
30sub to {
31    my ($self, $object_name) = @_;
32    $self->object_name($object_name);
33    return $self;
34}
35
36sub get_post_params {
37    my $self = shift;
38    my @post;
39    if ($self->has_access_token) {
40        push @post, access_token => uri_decode($self->access_token);
41    }
42    return \@post;
43}
44
45sub publish {
46    my ($self, $cb) = @_;
47    my $uri = $self->uri;
48    $uri->path($self->object_name.$self->object_path);
49    my $request = POST($uri->as_string,$self->get_post_params);
50    # XXX Do this more elegantly
51    http_post $uri->as_string, $request->content, sub {
52        my ($response, $headers) = @_;
53        my %params = (
54            response => $response,
55            headers  => $headers,
56            uri      => $uri->as_string
57        );
58        if ($self->has_secret) {
59            $params{secret} = $self->secret;
60        }
61        $cb->(Facebook::Graph::Response->new(%params));
62    };
63    () # return nothing
64}
65
66no Any::Moose;
67__PACKAGE__->meta->make_immutable;
68
69
70=head1 NAME
71
72Facebook::Graph::Publish - A base class for publishing various things to facebook.
73
74=head1 VERSION
75
76version 1.0300
77
78=head1 DESCRIPTION
79
80This module shouldn't be used by you directly for any purpose.
81
82=head1 LEGAL
83
84Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
85
86=cut
Note: See TracBrowser for help on using the repository browser.