File Coverage

blib/lib/Facebook/Graph/Page/Feed.pm
Criterion Covered Total %
statement 9 35 25.7
branch 0 4 0.0
condition 0 3 0.0
subroutine 3 11 27.2
pod 5 7 71.4
total 17 60 28.3


line stmt bran cond sub pod time code
1             package Facebook::Graph::Page::Feed;
2             $Facebook::Graph::Page::Feed::VERSION = '1.1204';
3 4     4   30 use strict;
  4         8  
  4         108  
4 4     4   20 use Moo;
  4         8  
  4         22  
5             extends 'Facebook::Graph::Publish';
6              
7             has page_id => (
8             is => 'rw',
9             predicate => 'has_page_id',
10             );
11              
12             sub set_page_id {
13 0     0 1   my ($self, $page_id) = @_;
14 0           $self->object_name(''); # not sure it's a good way here
15 0           $self->set_published(1); # it's a default value on FB side;
16 0           $self->page_id($page_id);
17 0           return $self;
18             }
19              
20 4     4   3372 use subs qw(object_path);
  4         115  
  4         20  
21             sub object_path{
22 0     0     my $s = shift;
23            
24 0 0         return $s->has_page_id ?
25             sprintf( '%s/feed', $s->page_id )
26             : die "You must set_page_id first";
27             }
28              
29             has message => (
30             is => 'rw',
31             predicate => 'has_message',
32             );
33              
34             sub set_message {
35 0     0 1   my ($self, $message) = @_;
36 0           $self->message($message);
37 0           return $self;
38             }
39              
40             has link_uri => (
41             is => 'rw',
42             predicate => 'has_link_uri',
43             );
44              
45             sub set_link_uri {
46 0     0 1   my ($self, $link_uri) = @_;
47 0           $self->link_uri($link_uri);
48 0           return $self;
49             }
50              
51             has backdated_time => (
52             is => 'rw',
53             predicate => 'has_backdated_time',
54             );
55              
56             sub set_backdated_time
57             {
58 0     0 1   my ($self, $backdated_time) = @_;
59 0           $self->backdated_time($backdated_time);
60 0           return $self;
61             }
62              
63             has scheduled_publish_time => (
64             is => 'rw',
65             predicate => 'has_scheduled_publish_time'
66             );
67              
68             sub set_scheduled_publish_time
69             {
70 0     0 1   my ($self, $scheduled_publish_time) = @_;
71 0           $self->scheduled_publish_time($scheduled_publish_time);
72 0           return $self;
73             }
74              
75             has published => (
76             is => 'rw',
77             predicate => 'has_published',
78             reader => '_get_published',
79             writer => '_set_published',
80             );
81              
82             sub published
83             {
84 0     0 0   my($self, $published) = @_;
85            
86 0 0         if( scalar @_ > 1 )
87             {
88 0           $self->_set_published($published);
89             }
90            
91 0   0       return $self->_get_published && $self->_get_published ne 'false';
92             }
93              
94             sub set_published
95             {
96 0     0 0   my ($self, $published) = @_;
97 0           $self->published($published);
98 0           return $self;
99             }
100              
101             around get_post_params => sub {
102             my ($orig, $self) = @_;
103             my $post = $orig->($self);
104             if ($self->has_message) {
105             push @$post, message => $self->message;
106             }
107             if ($self->has_link_uri) {
108             push @$post, link => $self->link_uri;
109             }
110             if ($self->has_backdated_time) {
111             push @$post, backdated_time => $self->backdated_time + 10*3600; # temporary fix for FB::Graph API
112             }
113             if (
114             $self->has_scheduled_publish_time
115             and (
116             not $self->has_published or not $self->published
117             )
118             ) {
119             push @$post, scheduled_publish_time => $self->scheduled_publish_time;
120             }
121             if ($self->has_published) {
122             push @$post, published => $self->published ? 'true': 'false';
123             }
124             return $post;
125             };
126              
127             1;
128              
129             =head1 NAME
130              
131             Facebook::Graph::Page::Feed - Add a post to a Facebook page.
132              
133             =head1 VERSION
134              
135             version 1.1204
136              
137             =head1 SYNOPSIS
138              
139             my $fb = Facebook::Graph->new;
140              
141             $fb->add_page_feed
142             ->set_page_id($page_id)
143             ->set_message('This is a test post')
144             ->set_backdated_time(time-3600)
145             ->set_scheduled_publish_time(time+3600)
146             ->set_published('false')
147             ->set_link_uri('http://mysite.com/testpage')
148             ->publish;
149              
150              
151             =head1 DESCRIPTION
152              
153             This module gives you quick and easy access to publish posts on FB pages.
154              
155             Implements publishing protocol available here:
156             L<https://developers.facebook.com/docs/graph-api/reference/v2.0/page/feed/>
157              
158             B<ATTENTION:> You must have the page access token to use this module.
159             It's available in C<$fb->fetch('me/accounts')>, but, you must have a user
160             token with C<manage_page> permission.
161              
162             More information about tokens could be found here:
163             L<https://developers.facebook.com/docs/facebook-login/access-tokens>
164              
165             =head1 METHODS
166              
167             =head2 set_page_id ( page_id )
168              
169             Specify a page id to post to. This is required field and must be set before
170             publishing.
171              
172             =head2 set_message ( message )
173              
174             Sets the description of the link.
175              
176             =head3 message
177              
178             A string of text.
179              
180              
181             =head2 set_link_uri ( uri )
182              
183             Sets the URI to link to.
184              
185             =head3 uri
186              
187             A URI.
188              
189             =head2 set_backdated_time ( time )
190              
191             Set a date of your post, different from now. Just a backdate. Time should be a
192             timestamp, no fancy formats.
193              
194             =head2 set_scheduled_publish_time( time )
195              
196             Set a publishing time for scheduled posts. Time should be a desired timestamp of
197             post in future. Doesn't work with minutes from now, but works fine with hour+
198              
199             =head2 publish ( )
200              
201             Posts the data and returns a L<Facebook::Graph::Response> object. The response object should contain the id:
202              
203             {"id":"1647395831_130068550371568"}
204              
205            
206             =head1 LEGAL
207              
208             Facebook::Graph is Copyright 2010 - 2012 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
209              
210             Facebook::Graph::Page::Feed is Copyright 2014 Alexandr Evstigneev (L<http://evstigneev.com>) and is licensed under the same terms as Perl itself.
211              
212             =cut