source: perl/modules/Facebook/lib/Facebook/Graph/Publish/Checkin.pm @ c104b43

Last change on this file since c104b43 was cfca761, checked in by Edward Z. Yang <ezyang@mit.edu>, 13 years ago
Add vanilla Facebook::Graph. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
  • Property mode set to 100644
File size: 3.6 KB
Line 
1package Facebook::Graph::Publish::Checkin;
2BEGIN {
3  $Facebook::Graph::Publish::Checkin::VERSION = '1.0300';
4}
5
6use Any::Moose;
7extends 'Facebook::Graph::Publish';
8
9use constant object_path => '/checkins';
10
11has message => (
12    is          => 'rw',
13    predicate   => 'has_message',
14);
15
16sub set_message {
17    my ($self, $message) = @_;
18    $self->message($message);
19    return $self;
20}
21
22has place => (
23    is          => 'rw',
24    predicate   => 'has_place',
25);
26
27sub set_place {
28    my ($self, $value) = @_;
29    $self->place($value);
30    return $self;
31}
32
33has longitude => (
34    is          => 'rw',
35    isa         => 'Num',
36    predicate   => 'has_longitude',
37);
38
39sub set_longitude {
40    my ($self, $value) = @_;
41    $self->longitude($value);
42    return $self;
43}
44
45has latitude => (
46    is          => 'rw',
47    isa         => 'Num',
48    predicate   => 'has_latitude',
49);
50
51sub set_latitude {
52    my ($self, $value) = @_;
53    $self->latitude($value);
54    return $self;
55}
56
57has tags => (
58    is          => 'rw',
59    isa         => 'ArrayRef',
60    predicate   => 'has_tags',
61    lazy        => 1,
62    default     => sub {[]},
63);
64
65sub set_tags {
66    my ($self, $value) = @_;
67    $self->tags($value);
68    return $self;
69}
70
71
72around get_post_params => sub {
73    my ($orig, $self) = @_;
74    my $post = $orig->($self);
75    if ($self->has_message) {
76        push @$post, message => $self->message;
77    }
78    if ($self->has_place) {
79        push @$post, place => $self->place;
80    }
81    if ($self->has_tags) {
82        push @$post, tags => join(', ',@{$self->tags});
83    }
84    if ($self->has_latitude && $self->has_longitude) {
85        push @$post, coordinates => JSON->new->encode({ latitude => $self->latitude, longitude => $self->longitude });
86    }
87   return $post;
88};
89
90
91no Any::Moose;
92__PACKAGE__->meta->make_immutable;
93
94
95=head1 NAME
96
97Facebook::Graph::Publish::Checkin - Publish a location checkin.
98
99=head1 VERSION
100
101version 1.0300
102
103=head1 SYNOPSIS
104
105 my $fb = Facebook::Graph->new;
106
107 $fb->add_checkin
108    ->set_place(222047056390)
109    ->publish;
110
111 my $response = $fb->add_checkin
112    ->set_place(222047056390)
113    ->set_message('Mmm...pizza.')
114    ->set_tags([qw(sarah.bownds 1647395831)])
115    ->set_latitude()
116    ->set_longitude()
117    ->publish;
118
119
120=head1 DESCRIPTION
121
122This module gives you quick and easy access to publish user checkins to locations.
123
124B<ATTENTION:> You must have the C<user_checkins> privilege to use this module, and C<friends_checkins> to get friends checkins.
125
126=head1 METHODS
127
128=head2 to ( id )
129
130Specify a profile id to post to. Defaults to 'me', which is the currently logged in user.
131
132
133=head2 set_message ( message )
134
135Sets the text to post to the wall.
136
137=head3 message
138
139A string of text.
140
141
142=head2 set_place ( id )
143
144Sets the id of the place you are checking in to.
145
146=head3 id
147
148The id of a page for a place. For example C<222047056390> is the id of Pete's Pizza and Pub in Milwaukee, WI.
149
150
151=head2 set_latitude ( coord )
152
153Sets sets the coords of your location. See also C<set_longitude>
154
155=head3 coord
156
157The decimal latitude of your current location.
158
159
160=head2 set_longitude ( coord )
161
162Sets sets the coords of your location. See also C<set_latitude>
163
164=head3 coord
165
166The decimal longitude of your current location.
167
168
169=head2 set_tags ( list )
170
171Sets the list of users at the location.
172
173=head3 list
174
175An array reference of Facebook user ids that are currently at this location with you.
176
177
178
179=head2 publish ( )
180
181Posts the data and returns a L<Facebook::Graph::Response> object. The response object should contain the id:
182
183 {"id":"1647395831_130068550371568"}
184
185=head1 LEGAL
186
187Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
188
189=cut
Note: See TracBrowser for help on using the repository browser.