Bump version and update Changes
[webservice-tdwtf.git] / lib / WebService / TDWTF / Article.pm
CommitLineData
54c23de0
MG
1package WebService::TDWTF::Article;
2
3use 5.014000;
4use strict;
5use warnings;
6use parent qw/Class::Accessor::Fast/;
7
be354e3b 8our $VERSION = '0.002';
54c23de0
MG
9
10use WebService::TDWTF ();
11
12sub _article { goto &WebService::TDWTF::article }
13
14__PACKAGE__->mk_ro_accessors(qw/Id Slug SummaryHtml BodyHtml FooterAdHtml Title CoalescedCommentCount DiscourseThreadUrl PublishedDate DisplayDate Url CommentsUrl PreviousArticleId PreviousArticleUrl NextArticleId NextArticleUrl/);
15
16sub AuthorName { shift->{Author}->{Name} }
17sub AuthorShortDescription { shift->{Author}->{ShortDescription} }
18sub AuthorDescriptionHtml { shift->{Author}->{DescriptionHtml} }
19sub AuthorSlug { shift->{Author}->{Slug} }
20sub AuthorImageUrl { shift->{Author}->{ImageUrl} }
21
22sub SeriesSlug { shift->{Series}->{Slug} }
23sub SeriesTitle { shift->{Series}->{Title} }
24sub SeriesDescription { shift->{Series}->{Description} }
25
26sub PreviousArticle { _article shift->PreviousArticleId // return }
27sub NextArticle { _article shift->NextArticleId // return }
28
29sub Body {
30 unless ($_[0]->BodyHtml) {
31 my $ret = _article $_[0]->Id, 1;
32 $_[0]->{$_} = $ret->{$_} for qw/BodyHtml FooterAdHtml/;
33 }
34 $_[0]->BodyHtml
35}
36
371;
38__END__
39
40=encoding utf-8
41
42=head1 NAME
43
44WebService::TDWTF::Article - Class representing information about a TDWTF article
45
46=head1 SYNOPSIS
47
48 use WebService::TDWTF;
49 my $article = tdwtf_article 8301;
50
51 say $article->Id; # 8301
52 say $article->Slug; # your-recommended-virus
53 say $article->SummaryHtml;
54 say $article->BodyHtml;
55 say $article->Body;
56 say $article->Title; # Your Recommended Virus
57 say $article->CoalescedCommentCount;
58 say $article->DiscourseThreadUrl; # http://what.thedailywtf.com/t/your-recommended-virus/52541
59 say $article->PublishedDate; # 2015-11-12T06:30:00
60 say $article->DisplayDate; # 2015-11-12
61 say $article->Url; # http://thedailywtf.com/articles/your-recommended-virus
62 say $article->CommentsUrl; # http://thedailywtf.com/articles/comments/your-recommended-virus
63 say $article->PreviousArticleId; # 8299
64 say $article->PreviousArticleUrl; # //thedailywtf.com/articles/confession-rect-contains-point
65 say $article->NextArticleId; # 8302
66 say $article->NextArticleUrl; # //thedailywtf.com/articles/who-stole-the-search-box
67
68 say $article->AuthorName; # Ellis Morning
69 say $article->AuthorShortDescription; # Editor
70 say $article->AuthorDescriptionHtml;
71 say $article->AuthorSlug; # ellis-morning
72 say $article->AuthorImageUrl; # http://img.thedailywtf.com/images/remy/ellis01.jpg
73
74 say $article->SeriesSlug; # feature-articles
75 say $article->SeriesTitle; # Feature Articles
76 say $article->SeriesDescription;
77
78 say $article->PreviousArticle->Title # Confession: rect.Contains(point)
79 say $article->NextArticle->Title # Who Stole the Search Box?!
80
81=head1 DESCRIPTION
82
83A WebService::TDWTF::Article object represents an article on
84L<http://thedailywtf.com>. Objects of this class are returned by the
85functions in L<WebService::TDWTF>. Each such object is guaranteed to
86be a blessed hashref corresponding to the JSON returned by the TDWTF
87API (possibly with some extra keys), so the data inside can be
88obtained by simply dereferencing the object.
89
90The ArticleModel class in the TDWTF source code might be helpful in
91finding the available attributes and understanding their meaning. It
92can be found here:
93L<https://github.com/tdwtf/WtfWebApp/blob/master/TheDailyWtf/Models/ArticleModel.cs>
94
95Several accessors and convenience functions are provided for accessing
96the most common attributes. See the SYNOPSIS for usage examples.
97
98=over
99
100=item B<Id>
101
102The numerical ID of the article.
103
104=item B<Slug>
105
106The string ID of the article.
107
108=item B<Title>
109
110The title of the article
111
112=item B<Url>
113
114URL of the article itself.
115
116=item B<SummaryHtml>
117
118The summary (first 1-2 paragraphs) of the article.
119
120=item B<BodyHtml>
121
122The body of the article. If the object comes from a tdwtf_list_* function, this method returns "".
123
124=item B<Body>
125
126The body of the article. If the object comes from a tdwtf_list_* function, this method retreives the body from the server, saves it in the object and returns it.
127
128=item B<FooterAdHtml>
129
130The advertisment in the footer of the article. If the object comes from a list_ function, this method returns "".
131
132=item B<CoalescedCommentCount>
133
134The number of comments of the article.
135
136=item B<CommentsUrl>
137
138URL to the featured comments list. See DiscourseThreadUrl for the URL to the full comment thread.
139
140=item B<DiscourseThreadUrl>
141
142URL of the full comment thread on what.thedailywtf.com.
143
144=item B<PublishedDate>
145
146Date and time when the article was published in ISO 8601 format, with no timezone.
147
148=item B<DisplayDate>
149
150Date when the article was published in ISO 8601 format, with no timezone.
151
152=item B<AuthorName>
153
154Name of the article's author.
155
156=item B<AuthorShortDescription>
157
158A one-line description of the article's author.
159
160=item B<AuthorDescriptionHtml>
161
162A longer description of the article's author.
163
164=item B<AuthorSlug>
165
166The ID of the article's author, suitable for passing to the tdwtf_list_author function of L<WebService::TDWTF>.
167
168=item B<AuthorImageUrl>
169
170URL to an image of the article's author.
171
172=item B<SeriesSlug>
173
174The ID of the article's series, suitable for passing to the tdwtf_list_series function of L<WebService::TDWTF>
175
176=item B<SeriesTitle>
177
178The name of the article's series.
179
180=item B<SeriesDescription>
181
182A description of the article's series.
183
184=item B<PreviousArticleId>
185
186The numerical ID of the previous article.
187
188=item B<PreviousArticleUrl>
189
190URL of the previous article.
191
192=item B<PreviousArticle>
193
194Retrieves the previous article using L<WebService::TDWTF> and returns it as a WebService::TDWTF::Article object.
195
196=item B<NextArticleId>
197
198The numerical ID of the next article.
199
200=item B<NextArticleUrl>
201
202URL of the next article.
203
204=item B<NextArticle>
205
206Retrieves the next article using L<WebService::TDWTF> and returns it as a WebService::TDWTF::Article object.
207
208=back
209
210=head1 AUTHOR
211
212Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
213
214=head1 COPYRIGHT AND LICENSE
215
216Copyright (C) 2016 by Marius Gavrilescu
217
218This library is free software; you can redistribute it and/or modify
219it under the same terms as Perl itself, either Perl version 5.20.2 or,
220at your option, any later version of Perl 5 you may have available.
221
222
223=cut
This page took 0.021308 seconds and 4 git commands to generate.