| 1 | package URL::Social::StumbleUpon; | ||||||||||
| 2 | 6 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 6 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 6 | extends 'URL::Social::BASE'; | |||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | URL::Social::StumbleUpon - Interface to the StumbleUpon API. | ||||||||||
| 10 | |||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||
| 12 | |||||||||||
| 13 | Do not use this module directly. Access it from L<URL::Social> instead; | ||||||||||
| 14 | |||||||||||
| 15 | use URL::Social; | ||||||||||
| 16 | |||||||||||
| 17 | my $social = URL::Social->new( | ||||||||||
| 18 | url => '...', | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | print $social->stumbleupon->view_count . "\n"; | ||||||||||
| 22 | |||||||||||
| 23 | =head1 METHODS | ||||||||||
| 24 | |||||||||||
| 25 | =cut | ||||||||||
| 26 | |||||||||||
| 27 | 6 | has 'data' => ( isa => 'Maybe[HashRef]', is => 'ro', lazy_build => 1 ); | |||||||||
| 28 | 6 | has 'view_count' => ( isa => 'Maybe[Int]', is => 'ro', lazy_build => 1 ); | |||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | sub _build_data { | ||||||||
|
Subroutine
_build_data: called CC=3 SCAR=12.3
| |||||||||||
| 31 | 1 | my $self = shift; | |||||||||
| 32 | |||||||||||
| 33 | 1 | my $url = 'http://www.stumbleupon.com/services/1.01/badge.getinfo?url=' . $self->url; | |||||||||
| 34 | |||||||||||
| 35 | 1 | ▶ | if ( my $json = $self->get_url_json($url) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 1 | ▶ | if ( my $data = $json->{result} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | return $data; | |||||||||
| 38 | } | ||||||||||
| 39 | else { | ||||||||||
| 40 | 0 | return undef; | |||||||||
| 41 | } | ||||||||||
| 42 | } | ||||||||||
| 43 | else { | ||||||||||
| 44 | 0 | return undef; | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | =head2 view_count | ||||||||||
| 49 | |||||||||||
| 50 | Returns the number of times the URL in question has been view among StumbleUpon | ||||||||||
| 51 | users. | ||||||||||
| 52 | |||||||||||
| 53 | Returns undef if it fails to retrieve the data from StumbleUpon. | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 1 | ▶ | sub _build_view_count { | ||||||||
|
Subroutine
_build_view_count: called CC=1 SCAR=0.0
| |||||||||||
| 58 | 1 | my $self = shift; | |||||||||
| 59 | |||||||||||
| 60 | 1 | return $self->data->{views}; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | # | ||||||||||
| 64 | # The End | ||||||||||
| 65 | # | ||||||||||
| 66 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||
| 67 | |||||||||||
| 68 | 6 | 1; | |||||||||
| 69 | |||||||||||
| 70 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 71 | |||||||||||
| 72 | Copyright 2013-2014 Tore Aursand. | ||||||||||
| 73 | |||||||||||
| 74 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 75 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||
| 76 | copy of the full license at: | ||||||||||
| 77 | |||||||||||
| 78 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||
| 79 | |||||||||||
| 80 | Any use, modification, and distribution of the Standard or Modified | ||||||||||
| 81 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||
| 82 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||
| 83 | or distribute the Package, if you do not accept this license. | ||||||||||
| 84 | |||||||||||
| 85 | If your Modified Version has been derived from a Modified Version made | ||||||||||
| 86 | by someone other than you, you are nevertheless required to ensure that | ||||||||||
| 87 | your Modified Version complies with the requirements of this license. | ||||||||||
| 88 | |||||||||||
| 89 | This license does not grant you the right to use any trademark, service | ||||||||||
| 90 | mark, tradename, or logo of the Copyright Holder. | ||||||||||
| 91 | |||||||||||
| 92 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||
| 93 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||
| 94 | otherwise transfer the Package with respect to any patent claims | ||||||||||
| 95 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||
| 96 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||
| 97 | counterclaim) against any party alleging that the Package constitutes | ||||||||||
| 98 | direct or contributory patent infringement, then this Artistic License | ||||||||||
| 99 | to you shall terminate on the date that such litigation is filed. | ||||||||||
| 100 | |||||||||||
| 101 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||
| 102 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||
| 103 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||
| 104 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||
| 105 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||
| 106 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||
| 107 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||
| 108 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||