File Coverage

blib/lib/Mojolicious/Plugin/LinkEmbedder/Link/Image/Instagram.pm
Criterion Covered Total %
statement 3 22 13.6
branch 0 4 0.0
condition n/a
subroutine 1 5 20.0
pod 0 2 0.0
total 4 33 12.1


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::LinkEmbedder::Link::Image::Instagram;
2 1     1   2371 use Mojo::Base 'Mojolicious::Plugin::LinkEmbedder::Link::Image';
  1         3  
  1         5  
3              
4             sub learn {
5 0     0 0   my ($self, $c, $cb) = @_;
6 0           my $ua = $self->{ua};
7 0           my $url = Mojo::URL->new('https://api.instagram.com/oembed');
8              
9 0           $url->query(url => $self->url);
10              
11             my $delay = Mojo::IOLoop->delay(
12             sub {
13 0     0     my $delay = shift;
14 0           $ua->get($url, $delay->begin);
15             },
16             sub {
17 0     0     my ($ua, $tx) = @_;
18 0           my $json = $tx->res->json;
19              
20 0           $self->author_name($json->{author_name});
21 0           $self->author_url($json->{author_url});
22 0           $self->media_id($json->{media_id});
23 0           $self->provider_url($json->{provider_url});
24 0           $self->provider_name($json->{provider_name});
25 0           $self->title($json->{title});
26 0           $self->{html} = $json->{html};
27 0           $self->$cb;
28             },
29 0           );
30 0 0         $delay->wait unless $delay->ioloop->is_running;
31             }
32              
33 0 0   0 0   sub to_embed { shift->{html} || '' }
34              
35             1;