File Coverage

blib/lib/Facebook/Graph/Publish/Post.pm
Criterion Covered Total %
statement 9 58 15.5
branch 0 2 0.0
condition n/a
subroutine 3 18 16.6
pod 15 15 100.0
total 27 93 29.0


line stmt bran cond sub pod time code
1             package Facebook::Graph::Publish::Post;
2             $Facebook::Graph::Publish::Post::VERSION = '1.1204';
3 4     4   23 use Moo;
  4         10  
  4         20  
4 4     4   1016 use Ouch;
  4         8  
  4         340  
5             extends 'Facebook::Graph::Publish';
6              
7 4     4   25 use constant object_path => '/feed';
  4         15  
  4         4281  
8              
9             has message => (
10             is => 'rw',
11             predicate => 'has_message',
12             );
13              
14             sub set_message {
15 0     0 1   my ($self, $message) = @_;
16 0           $self->message($message);
17 0           return $self;
18             }
19              
20             has picture_uri => (
21             is => 'rw',
22             predicate => 'has_picture_uri',
23             );
24              
25             sub set_picture_uri {
26 0     0 1   my ($self, $picture) = @_;
27 0           $self->picture_uri($picture);
28 0           return $self;
29             }
30              
31              
32             has link_uri => (
33             is => 'rw',
34             predicate => 'has_link_uri',
35             );
36              
37             sub set_link_uri {
38 0     0 1   my ($self, $source) = @_;
39 0           $self->link_uri($source);
40 0           return $self;
41             }
42              
43              
44             has link_name => (
45             is => 'rw',
46             predicate => 'has_link_name',
47             );
48              
49             sub set_link_name {
50 0     0 1   my ($self, $source) = @_;
51 0           $self->link_name($source);
52 0           return $self;
53             }
54              
55              
56             has link_caption => (
57             is => 'rw',
58             predicate => 'has_link_caption',
59             );
60              
61             sub set_link_caption {
62 0     0 1   my ($self, $source) = @_;
63 0           $self->link_caption($source);
64 0           return $self;
65             }
66              
67              
68             has link_description => (
69             is => 'rw',
70             predicate => 'has_link_description',
71             );
72              
73             sub set_link_description {
74 0     0 1   my ($self, $source) = @_;
75 0           $self->link_description($source);
76 0           return $self;
77             }
78              
79             has target_countries => (
80             is => 'rw',
81             default => sub {[]},
82             lazy => 1,
83             isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
84             predicate => 'has_target_countries',
85             );
86              
87             sub set_target_countries {
88 0     0 1   my ($self, $source) = @_;
89 0           $self->target_countries($source);
90 0           return $self;
91             }
92              
93             has target_cities => (
94             is => 'rw',
95             default => sub {[]},
96             lazy => 1,
97             isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
98             predicate => 'has_target_cities',
99             );
100              
101             sub set_target_cities {
102 0     0 1   my ($self, $source) = @_;
103 0           $self->target_cities($source);
104 0           return $self;
105             }
106              
107             has target_regions => (
108             is => 'rw',
109             default => sub {[]},
110             lazy => 1,
111             isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
112             predicate => 'has_target_regions',
113             );
114              
115             sub set_target_regions {
116 0     0 1   my ($self, $source) = @_;
117 0           $self->target_regions($source);
118 0           return $self;
119             }
120              
121             has target_locales => (
122             is => 'rw',
123             default => sub {[]},
124             lazy => 1,
125             isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
126             predicate => 'has_target_locales',
127             );
128              
129             sub set_target_locales {
130 0     0 1   my ($self, $source) = @_;
131 0           $self->target_locales($source);
132 0           return $self;
133             }
134              
135             has source => (
136             is => 'rw',
137             predicate => 'has_source',
138             );
139              
140             sub set_source {
141 0     0 1   my ($self, $source) = @_;
142 0           $self->source($source);
143 0           return $self;
144             }
145              
146             has actions => (
147             is => 'rw',
148             default => sub {[]},
149             lazy => 1,
150             isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'ARRAY' },
151             predicate => 'has_actions',
152             );
153              
154             sub set_actions {
155 0     0 1   my ($self, $actions) = @_;
156 0           $self->actions($actions);
157 0           return $self;
158             }
159              
160             sub add_action {
161 0     0 1   my ($self, $name, $link) = @_;
162 0           my $actions = $self->actions;
163 0           push @$actions, { name => $name, link => $link };
164 0           $self->actions($actions);
165 0           return $self;
166             }
167              
168             has privacy => (
169             is => 'rw',
170             predicate => 'has_privacy',
171             );
172              
173             has privacy_options => (
174             is => 'rw',
175             isa => sub { ouch(442,"$_[0] is not an Array Reference") unless ref $_[0] eq 'HASH' },
176             default => sub {{}},
177             );
178              
179             sub set_privacy {
180 0     0 1   my ($self, $privacy, $options) = @_;
181 0           $self->privacy($privacy);
182 0           $self->privacy_options($options);
183 0           return $self;
184             }
185              
186             has 'properties' => (
187             is => 'rw',
188             predicate => 'has_properties'
189             );
190              
191             sub set_properties {
192 0     0 1   my $self = shift;
193 0 0         my $properties = @_ % 2 ? shift @_ : { @_ };
194 0           $self->properties($properties);
195 0           return $self;
196             }
197              
198             around get_post_params => sub {
199             my ($orig, $self) = @_;
200             my $post = $orig->($self);
201             if ($self->has_message) {
202             push @$post, message => $self->message;
203             }
204             if ($self->has_link_uri) {
205             push @$post, link => $self->link_uri;
206             }
207             if ($self->has_link_name) {
208             push @$post, name => $self->link_name;
209             }
210             if ($self->has_link_caption) {
211             push @$post, caption => $self->link_caption;
212             }
213             if ($self->has_link_description) {
214             push @$post, description => $self->link_description;
215             }
216             if ($self->has_picture_uri) {
217             push @$post, picture => $self->picture_uri;
218             }
219             if ($self->has_source) {
220             push @$post, source => $self->source;
221             }
222             if ($self->has_actions) {
223             foreach my $action (@{$self->actions}) {
224             push @$post, actions => JSON->new->encode($action);
225             }
226             }
227             if ($self->has_privacy) {
228             my %privacy = %{$self->privacy_options};
229             $privacy{value} = $self->privacy;
230             push @$post, privacy => JSON->new->encode(\%privacy);
231             }
232             if ($self->has_properties) {
233             push @$post, properties => JSON->new->encode($self->properties);
234             }
235             return $post;
236             };
237              
238             1;
239              
240             =head1 NAME
241              
242             Facebook::Graph::Publish::Post - Publish to a user's wall.
243              
244             =head1 VERSION
245              
246             version 1.1204
247              
248             =head1 SYNOPSIS
249              
250             my $fb = Facebook::Graph->new;
251              
252             $fb->add_post
253             ->set_message('I like beer.')
254             ->publish;
255              
256             my $response = $fb->add_post
257             ->set_message('I like Perl.')
258             ->set_picture_uri('http://www.perl.org/i/camel_head.png')
259             ->set_link_uri('http://www.perl.org/')
260             ->set_link_name('Perl.org')
261             ->set_link_caption('Perl is a programming language.')
262             ->set_link_description('A link to the Perl web site.')
263             ->publish;
264              
265              
266             =head1 DESCRIPTION
267              
268             This module gives you quick and easy access to publish to a user's Facebook feed.
269              
270             B<ATTENTION:> You must have the C<publish_stream> privilege to use this module.
271              
272             B<TIP:> Facebook seems to use these terms interchangeably: Feed, Post, News, Wall. So if you want to publish to a user's wall, this is the mechanism you use to do that.
273              
274             =head1 METHODS
275              
276             =head2 to ( id )
277              
278             Specify a profile id to post to. Defaults to 'me', which is the currently logged in user.
279              
280              
281             =head2 set_message ( message )
282              
283             Sets the text to post to the wall.
284              
285             =head3 message
286              
287             A string of text.
288              
289              
290             =head2 set_picture_uri ( uri )
291              
292             Sets the URI of a picture to be displayed in the message.
293              
294             =head3 uri
295              
296             A URI to a picture.
297              
298              
299             =head2 set_link_uri ( uri )
300              
301             Sets the URI of a link that viewers can click on for more information about whatever you posted in C<set_message>.
302              
303             =head3 uri
304              
305             A URI to a site.
306              
307              
308             =head2 set_link_name ( name )
309              
310             If you want to give the link you set in C<set_link_uri> a human friendly name, use this method.
311              
312             =head2 name
313              
314             A text string to be used as the name of the link.
315              
316              
317             =head2 set_link_caption ( caption )
318              
319             Sets a short blurb to be displayed below the link/picture.
320              
321             =head3 caption
322              
323             A text string.
324              
325              
326             =head2 set_link_description ( description )
327              
328             Sets a longer description of the site you're linking to. Can also be a portion of the article you're linking to.
329              
330             =head3 description
331              
332             A text string.
333              
334              
335             =head2 set_source ( uri )
336              
337             Sets a source URI for a flash or video file.
338              
339             =head3 uri
340              
341             The URI you wish to set. For example if you wanted to include a YouTube video:
342              
343             $post->set_source('http://www.youtube.com/watch?v=efsJRdJ6dog');
344              
345              
346             =head2 set_actions ( actions )
347              
348             Sets a list of actions (or links) that should go in the post as things people can do with the post. This allows for integration of the post with third party sites.
349              
350             =head3 actions
351              
352             An array reference of hash references containing C<name> / C<link> pairs.
353              
354             $post->actions([
355             {
356             name => 'Click Me!',
357             link => 'http://www.somesite.com/click',
358             },
359             ...
360             ]);
361              
362             =head2 add_action ( name, link )
363              
364             Adds an action to the list of actions set either by previously calling C<add_action> or by calling C<set_actions>.
365              
366             =head3 name
367              
368             The name of the action (the clickable label).
369              
370             =head3 link
371              
372             The URI of the action.
373              
374              
375              
376             =head2 set_privacy ( setting, options )
377              
378             A completely optional privacy setting.
379              
380             =head2 set_properties ( properties )
381              
382             "property" values assigned when the post is published. This is typically rendered as a list of links.
383              
384             $post->set_properties( { "search engine:" => { "text" => "Google", "href" => "http://www.google.com/" } } );
385              
386             =head3 setting
387              
388             The privacy setting. Choose from: EVERYONE, CUSTOM, ALL_FRIENDS, NETWORKS_FRIENDS, and FRIENDS_OF_FRIENDS. See L<http://developers.facebook.com/docs/reference/api/post> for changes in this list.
389              
390             =head3 options
391              
392             A hash reference of options to tweak the privacy setting. Some options are required depending on what privacy setting you chose. See L<http://developers.facebook.com/docs/reference/api/post> for details.
393              
394             $post->set_privacy('CUSTOM', { friends => 'SOME_FRIENDS', allow => [qw( 119393 993322 )] });
395              
396             =over
397              
398             =item friends
399              
400             A string that must be one of EVERYONE, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS, ALL_FRIENDS, SOME_FRIENDS, SELF, or NO_FRIENDS.
401              
402             =item networks
403              
404             An array reference of network ids.
405              
406             =item allow
407              
408             An array reference of user ids.
409              
410             =item deny.
411              
412             An array reference of user ids.
413              
414             =back
415              
416              
417             =head2 set_target_countries ( countries )
418              
419             Makes a post only available to viewers in certain countries.
420              
421             $post->set_target_countries( ['US'] );
422            
423             =head3 countries
424              
425             An array reference of two letter country codes (upper case). You can find a list of country codes in the list of city ids here: L<http://developers.facebook.com/attachment/all_cities_final.csv>.
426              
427              
428             =head2 set_target_regions ( regions )
429              
430             Makes a post only available to viewers in certain regions.
431              
432             $post->set_target_regions( [6,53] );
433            
434             =head3 regions
435              
436             An array reference of region numbers however Facebook defines that. I've got no idea because their documentation sucks. I'm not even sure what a region is. Is it a region of a country? Of a continent? No idea. I do know it is an integer, but that's about it.
437              
438              
439              
440             =head2 set_target_cities ( cities )
441              
442             Makes a post only available to viewers in certain cities.
443              
444             $post->set_target_cities( [2547804] );
445            
446             =head3 cities
447              
448             An array reference of cities ids. In the example above I've listed Madison, WI. You can find a list of their cities here: L<http://developers.facebook.com/attachment/all_cities_final.csv>
449              
450              
451              
452             =head2 set_target_locales ( locales )
453              
454             Makes a post only available to viewers in certain locales.
455              
456             $post->set_target_locales( [6] );
457            
458             =head3 locales
459              
460             An array reference of locales ids. You can find their list of locales here: L<http://developers.facebook.com/attachment/locales_final.csv>
461              
462              
463              
464             =head2 publish ( )
465              
466             Posts the data and returns a L<Facebook::Graph::Response> object. The response object should contain the id:
467              
468             {"id":"1647395831_130068550371568"}
469              
470             =head1 LEGAL
471              
472             Facebook::Graph is Copyright 2010 - 2012 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
473              
474             =cut