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

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