File Coverage

blib/lib/Mojo/WebService/Twitter/Media.pm
Criterion Covered Total %
statement 14 14 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 2 2 100.0
pod 1 1 100.0
total 21 22 95.4


line stmt bran cond sub pod time code
1             package Mojo::WebService::Twitter::Media;
2 2     2   14 use Mojo::Base -base;
  2         4  
  2         13  
3              
4             our $VERSION = '1.001';
5              
6             has [qw(source display_url expanded_url id media_url source_status_id tweet type url)];
7             has variants => sub { [] };
8              
9             sub from_source {
10 2     2 1 20 my ($self, $source) = @_;
11 2         10 $self->display_url($source->{display_url});
12 2         25 $self->expanded_url($source->{expanded_url});
13 2         15 $self->id($source->{id_str});
14 2         15 $self->media_url($source->{media_url_https});
15 2         15 $self->source_status_id($source->{source_status_id_str});
16 2         17 $self->type($source->{type});
17 2         16 $self->url($source->{url});
18             $self->variants($source->{video_info}{variants})
19 2 100 66     28 if defined $source->{video_info} and defined $source->{video_info}{variants};
20 2         14 $self->source($source);
21 2         15 return $self;
22             }
23              
24             1;
25              
26             =head1 NAME
27              
28             Mojo::WebService::Twitter::Media - Media associated with a tweet
29              
30             =head1 SYNOPSIS
31              
32             use Mojo::WebService::Twitter;
33             my $twitter = Mojo::WebService::Twitter->new(api_key => $api_key, api_secret => $api_secret);
34             my $tweet = $twitter->get_tweet($tweet_id);
35              
36             my $media = $tweet->media;
37             foreach my $item (@$media) {
38             my $media_type = $item->type;
39             my $media_url = $item->media_url;
40             say "Media ($media_type): $media_url";
41             }
42              
43             =head1 DESCRIPTION
44              
45             L is an object representing native media
46             associated with a L tweet. See
47             L
48             for more information.
49              
50             =head1 ATTRIBUTES
51              
52             =head2 source
53              
54             my $href = $media->source;
55              
56             Source data hashref from Twitter API.
57              
58             =head2 display_url
59              
60             my $url = $media->display_url;
61              
62             URL of the media for display purposes.
63              
64             =head2 expanded_url
65              
66             my $url = $media->expanded_url;
67              
68             Expanded version of L.
69              
70             =head2 id
71              
72             my $media_id = $media->id;
73              
74             Media identifier. Note that media IDs are usually too large to be represented
75             as a number, so should always be treated as a string.
76              
77             =head2 media_url
78              
79             my $url = $media->media_url;
80              
81             Direct URL to media of L C, or a static thumbnail for media of
82             type C
83             found in L.
84              
85             =head2 source_status_id
86              
87             my $tweet_id = $media->source_status_id;
88              
89             Tweet ID which media was originally associated with, or C if media was
90             originally associated with the current tweet.
91              
92             =head2 type
93              
94             my $type = $media->type;
95              
96             Media type, one of C, C
97              
98             =head2 tweet
99              
100             my $tweet = $media->tweet;
101              
102             Tweet in which the media is contained, as a L
103             object.
104              
105             =head2 variants
106              
107             my $variants = $media->variants;
108              
109             Array reference of variant hashrefs for media of L C
110             C, with keys C, C, and possibly C,
111             representing direct access to the media if available.
112              
113             =head1 METHODS
114              
115             L inherits all methods from L,
116             and implements the following new ones.
117              
118             =head2 from_source
119              
120             $media = $media->from_source($hr);
121              
122             Populate attributes from hashref of Twitter API source data.
123              
124             =head1 BUGS
125              
126             Report any issues on the public bugtracker.
127              
128             =head1 AUTHOR
129              
130             Dan Book
131              
132             =head1 COPYRIGHT AND LICENSE
133              
134             This software is Copyright (c) 2015 by Dan Book.
135              
136             This is free software, licensed under:
137              
138             The Artistic License 2.0 (GPL Compatible)
139              
140             =head1 SEE ALSO
141              
142             L