1 | package Facebook::Graph::Publish::Event; |
---|
2 | BEGIN { |
---|
3 | $Facebook::Graph::Publish::Event::VERSION = '1.0300'; |
---|
4 | } |
---|
5 | |
---|
6 | use Any::Moose; |
---|
7 | extends 'Facebook::Graph::Publish'; |
---|
8 | use DateTime; |
---|
9 | use DateTime::Format::Strptime; |
---|
10 | |
---|
11 | use constant object_path => '/events'; |
---|
12 | |
---|
13 | has name => ( |
---|
14 | is => 'rw', |
---|
15 | predicate => 'has_name', |
---|
16 | ); |
---|
17 | |
---|
18 | sub set_name { |
---|
19 | my ($self, $input) = @_; |
---|
20 | $self->name($input); |
---|
21 | return $self; |
---|
22 | } |
---|
23 | |
---|
24 | has description => ( |
---|
25 | is => 'rw', |
---|
26 | predicate => 'has_description', |
---|
27 | ); |
---|
28 | |
---|
29 | sub set_description { |
---|
30 | my ($self, $input) = @_; |
---|
31 | $self->description($input); |
---|
32 | return $self; |
---|
33 | } |
---|
34 | |
---|
35 | has location => ( |
---|
36 | is => 'rw', |
---|
37 | predicate => 'has_location', |
---|
38 | ); |
---|
39 | |
---|
40 | sub set_location { |
---|
41 | my ($self, $input) = @_; |
---|
42 | $self->location($input); |
---|
43 | return $self; |
---|
44 | } |
---|
45 | |
---|
46 | has start_time => ( |
---|
47 | is => 'rw', |
---|
48 | isa => 'DateTime', |
---|
49 | predicate => 'has_start_time', |
---|
50 | ); |
---|
51 | |
---|
52 | sub set_start_time { |
---|
53 | my ($self, $start_time) = @_; |
---|
54 | $self->start_time($start_time); |
---|
55 | return $self; |
---|
56 | } |
---|
57 | |
---|
58 | has end_time => ( |
---|
59 | is => 'rw', |
---|
60 | isa => 'DateTime', |
---|
61 | predicate => 'has_end_time', |
---|
62 | ); |
---|
63 | |
---|
64 | sub set_end_time { |
---|
65 | my ($self, $end_time) = @_; |
---|
66 | $self->end_time($end_time); |
---|
67 | return $self; |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | |
---|
72 | around 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 | |
---|
98 | no Any::Moose; |
---|
99 | __PACKAGE__->meta->make_immutable; |
---|
100 | |
---|
101 | |
---|
102 | =head1 NAME |
---|
103 | |
---|
104 | Facebook::Graph::Publish::Event - Add an event. |
---|
105 | |
---|
106 | =head1 VERSION |
---|
107 | |
---|
108 | version 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 | |
---|
124 | This module gives you quick and easy access to publish events. |
---|
125 | |
---|
126 | B<ATTENTION:> You must have the C<create_event> privilege to use this module. |
---|
127 | |
---|
128 | =head1 METHODS |
---|
129 | |
---|
130 | =head2 to ( id ) |
---|
131 | |
---|
132 | Specify a profile id to post to. Defaults to 'me', which is the currently logged in user. |
---|
133 | |
---|
134 | |
---|
135 | =head2 set_name ( name ) |
---|
136 | |
---|
137 | Sets the name of the event. |
---|
138 | |
---|
139 | =head3 name |
---|
140 | |
---|
141 | A string of text. |
---|
142 | |
---|
143 | |
---|
144 | =head2 set_description ( description ) |
---|
145 | |
---|
146 | Sets the description of the event. Tell people what's going on. |
---|
147 | |
---|
148 | =head3 description |
---|
149 | |
---|
150 | A string of text. |
---|
151 | |
---|
152 | |
---|
153 | =head2 set_location ( location ) |
---|
154 | |
---|
155 | Sets a general description of where the event will take place. |
---|
156 | |
---|
157 | =head3 location |
---|
158 | |
---|
159 | A string of text. |
---|
160 | |
---|
161 | |
---|
162 | =head2 set_start_time ( datetime ) |
---|
163 | |
---|
164 | Sets the start of the event. |
---|
165 | |
---|
166 | =head3 datetime |
---|
167 | |
---|
168 | A L<DateTime> object. |
---|
169 | |
---|
170 | |
---|
171 | =head2 set_end_time ( datetime ) |
---|
172 | |
---|
173 | Sets the end of the event. |
---|
174 | |
---|
175 | =head3 datetime |
---|
176 | |
---|
177 | A L<DateTime> object. |
---|
178 | |
---|
179 | |
---|
180 | =head2 publish ( ) |
---|
181 | |
---|
182 | Posts 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 | |
---|
189 | Add venue and privacy as described on L<http://developers.facebook.com/docs/reference/api/event>. |
---|
190 | |
---|
191 | =head1 LEGAL |
---|
192 | |
---|
193 | Facebook::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 |
---|