[cfca761] | 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'; |
---|
[9820d55] | 9 | use AnyEvent::HTTP; |
---|
| 10 | use LWP::UserAgent; # XXX blegh |
---|
| 11 | use HTTP::Request::Common; |
---|
[cfca761] | 12 | use URI::Encode qw(uri_decode); |
---|
| 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 { |
---|
[9820d55] | 46 | my ($self, $cb) = @_; |
---|
[cfca761] | 47 | my $uri = $self->uri; |
---|
| 48 | $uri->path($self->object_name.$self->object_path); |
---|
[9820d55] | 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)); |
---|
[cfca761] | 63 | } |
---|
| 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 | |
---|
[9820d55] | 86 | =cut |
---|