1 | package Facebook::Graph::Publish; |
---|
2 | BEGIN { |
---|
3 | $Facebook::Graph::Publish::VERSION = '1.0300'; |
---|
4 | } |
---|
5 | |
---|
6 | use Any::Moose; |
---|
7 | use Facebook::Graph::Response; |
---|
8 | with 'Facebook::Graph::Role::Uri'; |
---|
9 | use AnyEvent::HTTP; |
---|
10 | use LWP::UserAgent; # XXX blegh |
---|
11 | use HTTP::Request::Common; |
---|
12 | use URI::Encode qw(uri_decode uri_encode); |
---|
13 | |
---|
14 | has secret => ( |
---|
15 | is => 'ro', |
---|
16 | required => 0, |
---|
17 | predicate => 'has_secret', |
---|
18 | ); |
---|
19 | |
---|
20 | has access_token => ( |
---|
21 | is => 'ro', |
---|
22 | predicate => 'has_access_token', |
---|
23 | ); |
---|
24 | |
---|
25 | has object_name => ( |
---|
26 | is => 'rw', |
---|
27 | default => 'me', |
---|
28 | ); |
---|
29 | |
---|
30 | sub to { |
---|
31 | my ($self, $object_name) = @_; |
---|
32 | $self->object_name($object_name); |
---|
33 | return $self; |
---|
34 | } |
---|
35 | |
---|
36 | sub 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 | |
---|
45 | sub 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 | |
---|
66 | no Any::Moose; |
---|
67 | __PACKAGE__->meta->make_immutable; |
---|
68 | |
---|
69 | |
---|
70 | =head1 NAME |
---|
71 | |
---|
72 | Facebook::Graph::Publish - A base class for publishing various things to facebook. |
---|
73 | |
---|
74 | =head1 VERSION |
---|
75 | |
---|
76 | version 1.0300 |
---|
77 | |
---|
78 | =head1 DESCRIPTION |
---|
79 | |
---|
80 | This module shouldn't be used by you directly for any purpose. |
---|
81 | |
---|
82 | =head1 LEGAL |
---|
83 | |
---|
84 | Facebook::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 |
---|