source: perl/modules/Facebook/lib/Facebook/Graph/Publish/Event.pm @ 2a42248

release-1.9
Last change on this file since 2a42248 was 2a42248, checked in by Edward Z. Yang <ezyang@mit.edu>, 10 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::Event;
2BEGIN {
3  $Facebook::Graph::Publish::Event::VERSION = '1.0300';
4}
5
6use Any::Moose;
7extends 'Facebook::Graph::Publish';
8use DateTime;
9use DateTime::Format::Strptime;
10
11use constant object_path => '/events';
12
13has name => (
14    is          => 'rw',
15    predicate   => 'has_name',
16);
17
18sub set_name {
19    my ($self, $input) = @_;
20    $self->name($input);
21    return $self;
22}
23
24has description => (
25    is          => 'rw',
26    predicate   => 'has_description',
27);
28
29sub set_description {
30    my ($self, $input) = @_;
31    $self->description($input);
32    return $self;
33}
34
35has location => (
36    is          => 'rw',
37    predicate   => 'has_location',
38);
39
40sub set_location {
41    my ($self, $input) = @_;
42    $self->location($input);
43    return $self;
44}
45
46has start_time => (
47    is          => 'rw',
48    isa         => 'DateTime',
49    predicate   => 'has_start_time',
50);
51
52sub set_start_time {
53    my ($self, $start_time) = @_;
54    $self->start_time($start_time);
55    return $self;
56}
57
58has end_time => (
59    is          => 'rw',
60    isa         => 'DateTime',
61    predicate   => 'has_end_time',
62);
63
64sub set_end_time {
65    my ($self, $end_time) = @_;
66    $self->end_time($end_time);
67    return $self;
68}
69
70
71
72around get_post_params => sub {
73    my ($orig, $self) = @_;
74    my $post = $orig->($self);
75    unless ($self->object_name eq 'me') {
76        push @$post, page_id => $self->object_name;
77    }
78    if ($self->has_name) {
79        push @$post, name => $self->name;
80    }
81    if ($self->has_description) {
82        push @$post, description => $self->description;
83    }
84    if ($self->has_location) {
85        push @$post, location => $self->location;
86    }
87    my $strp = DateTime::Format::Strptime->new(pattern => '%FT %T%z');
88    if ($self->has_start_time) {
89        push @$post, start_time => $strp->format_datetime($self->start_time);
90    }
91    if ($self->has_end_time) {
92        push @$post, end_time => $strp->format_datetime($self->end_time);
93    }
94    return $post;
95};
96
97
98no Any::Moose;
99__PACKAGE__->meta->make_immutable;
100
101
102=head1 NAME
103
104Facebook::Graph::Publish::Event - Add an event.
105
106=head1 VERSION
107
108version 1.0300
109
110=head1 SYNOPSIS
111
112 my $fb = Facebook::Graph->new;
113
114 my $start = DateTime->new( month=>10, day=>31, year => 2010, hour=>20 );
115 $fb->add_event
116    ->set_start_time($start)
117    ->set_end_time($start->clone->add(hours => 6))
118    ->set_name('Halloween Party')
119    ->publish;
120
121
122=head1 DESCRIPTION
123
124This module gives you quick and easy access to publish events.
125
126B<ATTENTION:> You must have the C<create_event> privilege to use this module.
127
128=head1 METHODS
129
130=head2 to ( id )
131
132Specify a profile id to post to. Defaults to 'me', which is the currently logged in user.
133
134
135=head2 set_name ( name )
136
137Sets the name of the event.
138
139=head3 name
140
141A string of text.
142
143
144=head2 set_description ( description )
145
146Sets the description of the event. Tell people what's going on.
147
148=head3 description
149
150A string of text.
151
152
153=head2 set_location ( location )
154
155Sets a general description of where the event will take place.
156
157=head3 location
158
159A string of text.
160
161
162=head2 set_start_time ( datetime )
163
164Sets the start of the event.
165
166=head3 datetime
167
168A L<DateTime> object.
169
170
171=head2 set_end_time ( datetime )
172
173Sets the end of the event.
174
175=head3 datetime
176
177A L<DateTime> object.
178
179
180=head2 publish ( )
181
182Posts the data and returns a L<Facebook::Graph::Response> object. The response object should contain the id:
183
184 {"id":"1647395831_130068550371568"}
185 
186 
187=head1 TODO
188
189Add venue and privacy as described on L<http://developers.facebook.com/docs/reference/api/event>.
190
191=head1 LEGAL
192
193Facebook::Graph is Copyright 2010 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
194
195=cut
Note: See TracBrowser for help on using the repository browser.