LinkEmbedder/Link/oEmbed.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 43 CC 3 SCAR 18.4
CC
3
Cov
0%
learn_p
12.0
_api_url
2.0
BEGIN
2.0
CRAP 6.3
1 package LinkEmbedder::Link::oEmbed;
2 use Mojo::Base 'LinkEmbedder::Link';
3  
4 use constant DEBUG => $ENV{LINK_EMBEDDER_DEBUG} || 0;
5  
6 require LinkEmbedder;
7  
8 # please report back if you add more urls to this hash
9 our %API = (
10 'ted.com' => 'https://www.ted.com/services/v1/oembed.json',
11 'vimeo.com' => 'https://vimeo.com/api/oembed.json',
12 'youtube.com' => 'https://www.youtube.com/oembed',
13 );
14  
15 has html => sub { shift->SUPER::html };
16  
17 sub learn_p {
18 my $self = shift;
19 return $self->SUPER::learn_p unless $self->url->path =~ /\w/;
20  
21 my $api_url = $self->_api_url;
22 return $self->_get_p($api_url)->then(sub { $self->_learn_from_json(shift) }) if $api_url;
23  
24 $self->error({message => "Unknown oEmbed provider for @{[$self->url]}", code => 400});
25 return $self;
26 }
27  
28 sub _api_url {
29 my $self = shift;
30 my $url = $self->url->clone;
31 my $api_url = LinkEmbedder::_host_in_hash($url->host, \%API) or return undef;
32  
33 $url->path->trailing_slash(0);
34 $api_url = Mojo::URL->new($api_url);
35 $api_url->query->param(url => $url->to_string);
36  
37 return $api_url;
38 }
39  
40 1;