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

release-1.10release-1.9
Last change on this file since b7fa912 was b7fa912, checked in by Edward Z. Yang <ezyang@mit.edu>, 13 years ago
Force void context on callbacks. 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);
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    # XXX blegh
50    my $request = LWP::UserAgent->new->request(POST $uri->as_string, $self->get_post_params);
51    http_post $uri->as_string, $request->content, sub {
52        warn "whooo";
53        my ($response, $headers) = @_;
54        my %params = (
55            response => $response,
56            headers  => $headers,
57            uri      => $uri->as_string
58        );
59        if ($self->has_secret) {
60            $params{secret} = $self->secret;
61        }
62        $cb->(Facebook::Graph::Response->new(%params));
63    };
64    () # return nothing
65}
66
67no Any::Moose;
68__PACKAGE__->meta->make_immutable;
69
70
71=head1 NAME
72
73Facebook::Graph::Publish - A base class for publishing various things to facebook.
74
75=head1 VERSION
76
77version 1.0300
78
79=head1 DESCRIPTION
80
81This module shouldn't be used by you directly for any purpose.
82
83=head1 LEGAL
84
85Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
86
87=cut
Note: See TracBrowser for help on using the repository browser.