]>
iEval git - webservice-tdwtf.git/blob - WebService/TDWTF/Article.pm
1 package WebService
:: TDWTF
:: Article
;
6 use parent qw
/Class::Accessor::Fast/ ;
8 our $VERSION = '0.001' ;
10 use WebService
:: TDWTF
();
12 sub _article
{ goto & WebService
:: TDWTF
:: article
}
14 __PACKAGE__
-> mk_ro_accessors ( qw
/Id Slug SummaryHtml BodyHtml FooterAdHtml Title CoalescedCommentCount DiscourseThreadUrl PublishedDate DisplayDate Url CommentsUrl PreviousArticleId PreviousArticleUrl NextArticleId NextArticleUrl/ );
16 sub AuthorName
{ shift ->{ Author
}->{ Name
} }
17 sub AuthorShortDescription
{ shift ->{ Author
}->{ ShortDescription
} }
18 sub AuthorDescriptionHtml
{ shift ->{ Author
}->{ DescriptionHtml
} }
19 sub AuthorSlug
{ shift ->{ Author
}->{ Slug
} }
20 sub AuthorImageUrl
{ shift ->{ Author
}->{ ImageUrl
} }
22 sub SeriesSlug
{ shift ->{ Series
}->{ Slug
} }
23 sub SeriesTitle
{ shift ->{ Series
}->{ Title
} }
24 sub SeriesDescription
{ shift ->{ Series
}->{ Description
} }
26 sub PreviousArticle
{ _article
shift -> PreviousArticleId // return }
27 sub NextArticle
{ _article
shift -> NextArticleId // return }
30 unless ( $_ [ 0 ]-> BodyHtml ) {
31 my $ret = _article
$_ [ 0 ]-> Id , 1 ;
32 $_ [ 0 ]->{ $_ } = $ret ->{ $_ } for qw
/BodyHtml FooterAdHtml/ ;
44 WebService::TDWTF::Article - Class representing information about a TDWTF article
48 use WebService::TDWTF;
49 my $article = tdwtf_article 8301;
51 say $article->Id; # 8301
52 say $article->Slug; # your-recommended-virus
53 say $article->SummaryHtml;
54 say $article->BodyHtml;
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
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
74 say $article->SeriesSlug; # feature-articles
75 say $article->SeriesTitle; # Feature Articles
76 say $article->SeriesDescription;
78 say $article->PreviousArticle->Title # Confession: rect.Contains(point)
79 say $article->NextArticle->Title # Who Stole the Search Box?!
83 A WebService::TDWTF::Article object represents an article on
84 L<http://thedailywtf.com>. Objects of this class are returned by the
85 functions in L<WebService::TDWTF>. Each such object is guaranteed to
86 be a blessed hashref corresponding to the JSON returned by the TDWTF
87 API (possibly with some extra keys), so the data inside can be
88 obtained by simply dereferencing the object.
90 The ArticleModel class in the TDWTF source code might be helpful in
91 finding the available attributes and understanding their meaning. It
93 L<https://github.com/tdwtf/WtfWebApp/blob/master/TheDailyWtf/Models/ArticleModel.cs>
95 Several accessors and convenience functions are provided for accessing
96 the most common attributes. See the SYNOPSIS for usage examples.
102 The numerical ID of the article.
106 The string ID of the article.
110 The title of the article
114 URL of the article itself.
118 The summary (first 1-2 paragraphs) of the article.
122 The body of the article. If the object comes from a tdwtf_list_* function, this method returns "".
126 The 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.
128 =item B<FooterAdHtml>
130 The advertisment in the footer of the article. If the object comes from a list_ function, this method returns "".
132 =item B<CoalescedCommentCount>
134 The number of comments of the article.
138 URL to the featured comments list. See DiscourseThreadUrl for the URL to the full comment thread.
140 =item B<DiscourseThreadUrl>
142 URL of the full comment thread on what.thedailywtf.com.
144 =item B<PublishedDate>
146 Date and time when the article was published in ISO 8601 format, with no timezone.
150 Date when the article was published in ISO 8601 format, with no timezone.
154 Name of the article's author.
156 =item B<AuthorShortDescription>
158 A one-line description of the article's author.
160 =item B<AuthorDescriptionHtml>
162 A longer description of the article's author.
166 The ID of the article's author, suitable for passing to the tdwtf_list_author function of L<WebService::TDWTF>.
168 =item B<AuthorImageUrl>
170 URL to an image of the article's author.
174 The ID of the article's series, suitable for passing to the tdwtf_list_series function of L<WebService::TDWTF>
178 The name of the article's series.
180 =item B<SeriesDescription>
182 A description of the article's series.
184 =item B<PreviousArticleId>
186 The numerical ID of the previous article.
188 =item B<PreviousArticleUrl>
190 URL of the previous article.
192 =item B<PreviousArticle>
194 Retrieves the previous article using L<WebService::TDWTF> and returns it as a WebService::TDWTF::Article object.
196 =item B<NextArticleId>
198 The numerical ID of the next article.
200 =item B<NextArticleUrl>
202 URL of the next article.
206 Retrieves the next article using L<WebService::TDWTF> and returns it as a WebService::TDWTF::Article object.
212 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
214 =head1 COPYRIGHT AND LICENSE
216 Copyright (C) 2016 by Marius Gavrilescu
218 This library is free software; you can redistribute it and/or modify
219 it under the same terms as Perl itself, either Perl version 5.20.2 or,
220 at your option, any later version of Perl 5 you may have available.
This page took 0.065886 seconds and 4 git commands to generate.