| 1 | package WebService::TDWTF::Article; |
| 2 | |
| 3 | use 5.014000; |
| 4 | use strict; |
| 5 | use warnings; |
| 6 | use parent qw/Class::Accessor::Fast/; |
| 7 | |
| 8 | our $VERSION = '0.003'; |
| 9 | |
| 10 | use WebService::TDWTF (); |
| 11 | |
| 12 | sub _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 | |
| 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} } |
| 21 | |
| 22 | sub SeriesSlug { shift->{Series}->{Slug} } |
| 23 | sub SeriesTitle { shift->{Series}->{Title} } |
| 24 | sub SeriesDescription { shift->{Series}->{Description} } |
| 25 | |
| 26 | sub PreviousArticle { _article shift->PreviousArticleId // return } |
| 27 | sub NextArticle { _article shift->NextArticleId // return } |
| 28 | |
| 29 | sub 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 | |
| 37 | 1; |
| 38 | __END__ |
| 39 | |
| 40 | =encoding utf-8 |
| 41 | |
| 42 | =head1 NAME |
| 43 | |
| 44 | WebService::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 | |
| 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. |
| 89 | |
| 90 | The ArticleModel class in the TDWTF source code might be helpful in |
| 91 | finding the available attributes and understanding their meaning. It |
| 92 | can be found here: |
| 93 | L<https://github.com/tdwtf/WtfWebApp/blob/master/TheDailyWtf/Models/ArticleModel.cs> |
| 94 | |
| 95 | Several accessors and convenience functions are provided for accessing |
| 96 | the most common attributes. See the SYNOPSIS for usage examples. |
| 97 | |
| 98 | =over |
| 99 | |
| 100 | =item B<Id> |
| 101 | |
| 102 | The numerical ID of the article. |
| 103 | |
| 104 | =item B<Slug> |
| 105 | |
| 106 | The string ID of the article. |
| 107 | |
| 108 | =item B<Title> |
| 109 | |
| 110 | The title of the article |
| 111 | |
| 112 | =item B<Url> |
| 113 | |
| 114 | URL of the article itself. |
| 115 | |
| 116 | =item B<SummaryHtml> |
| 117 | |
| 118 | The summary (first 1-2 paragraphs) of the article. |
| 119 | |
| 120 | =item B<BodyHtml> |
| 121 | |
| 122 | The body of the article. If the object comes from a tdwtf_list_* function, this method returns "". |
| 123 | |
| 124 | =item B<Body> |
| 125 | |
| 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. |
| 127 | |
| 128 | =item B<FooterAdHtml> |
| 129 | |
| 130 | The advertisment in the footer of the article. If the object comes from a list_ function, this method returns "". |
| 131 | |
| 132 | =item B<CoalescedCommentCount> |
| 133 | |
| 134 | The number of comments of the article. |
| 135 | |
| 136 | =item B<CommentsUrl> |
| 137 | |
| 138 | URL to the featured comments list. See DiscourseThreadUrl for the URL to the full comment thread. |
| 139 | |
| 140 | =item B<DiscourseThreadUrl> |
| 141 | |
| 142 | URL of the full comment thread on what.thedailywtf.com. |
| 143 | |
| 144 | =item B<PublishedDate> |
| 145 | |
| 146 | Date and time when the article was published in ISO 8601 format, with no timezone. |
| 147 | |
| 148 | =item B<DisplayDate> |
| 149 | |
| 150 | Date when the article was published in ISO 8601 format, with no timezone. |
| 151 | |
| 152 | =item B<AuthorName> |
| 153 | |
| 154 | Name of the article's author. |
| 155 | |
| 156 | =item B<AuthorShortDescription> |
| 157 | |
| 158 | A one-line description of the article's author. |
| 159 | |
| 160 | =item B<AuthorDescriptionHtml> |
| 161 | |
| 162 | A longer description of the article's author. |
| 163 | |
| 164 | =item B<AuthorSlug> |
| 165 | |
| 166 | The 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 | |
| 170 | URL to an image of the article's author. |
| 171 | |
| 172 | =item B<SeriesSlug> |
| 173 | |
| 174 | The 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 | |
| 178 | The name of the article's series. |
| 179 | |
| 180 | =item B<SeriesDescription> |
| 181 | |
| 182 | A description of the article's series. |
| 183 | |
| 184 | =item B<PreviousArticleId> |
| 185 | |
| 186 | The numerical ID of the previous article. |
| 187 | |
| 188 | =item B<PreviousArticleUrl> |
| 189 | |
| 190 | URL of the previous article. |
| 191 | |
| 192 | =item B<PreviousArticle> |
| 193 | |
| 194 | Retrieves the previous article using L<WebService::TDWTF> and returns it as a WebService::TDWTF::Article object. |
| 195 | |
| 196 | =item B<NextArticleId> |
| 197 | |
| 198 | The numerical ID of the next article. |
| 199 | |
| 200 | =item B<NextArticleUrl> |
| 201 | |
| 202 | URL of the next article. |
| 203 | |
| 204 | =item B<NextArticle> |
| 205 | |
| 206 | Retrieves the next article using L<WebService::TDWTF> and returns it as a WebService::TDWTF::Article object. |
| 207 | |
| 208 | =back |
| 209 | |
| 210 | =head1 AUTHOR |
| 211 | |
| 212 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> |
| 213 | |
| 214 | =head1 COPYRIGHT AND LICENSE |
| 215 | |
| 216 | Copyright (C) 2016 by Marius Gavrilescu |
| 217 | |
| 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. |
| 221 | |
| 222 | |
| 223 | =cut |