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

release-1.9
Last change on this file since 7777ac2 was 7777ac2, checked in by Edward Z. Yang <ezyang@mit.edu>, 10 years ago
Convert to async (both Facebook::Graph and us.) Work items: - Documentation is all out of date - Think more carefully about error handling (right now it's delayed into the response object) - Really bad HTTP POST hack in Publish.pm. 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}
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.