LinkEmbedder

 view release on metacpan or  search on metacpan

.travis.yml  view on Meta::CPAN

language: perl
perl:
  - "5.22"
  - "5.16"
  - "5.12"
  - "5.10"
env:
  - "HARNESS_OPTIONS=j9 TEST_ONLINE=1"
install:
  - "cpanm -n IO::Socket::SSL"
  - "cpanm -n --installdeps ."
notifications:
  email: false

lib/LinkEmbedder.pm  view on Meta::CPAN

package LinkEmbedder;
use Mojo::Base -base;

use LinkEmbedder::Link;
use Mojo::JSON;
use Mojo::Loader 'load_class';
use Mojo::Promise;
use Mojo::UserAgent;

use constant TLS => eval { require IO::Socket::SSL; IO::Socket::SSL->VERSION('2.009'); 1 };

use constant DEBUG => $ENV{LINK_EMBEDDER_DEBUG} || 0;

our $VERSION = '1.20';

my $PROTOCOL_RE = qr!^(\w+):\w+!i;    # Examples: mail:, spotify:, ...

has force_secure => sub { $ENV{LINK_EMBEDDER_FORCE_SECURE} || 0 };

has ua => sub { Mojo::UserAgent->new->max_redirects(3); };

t/basic.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://www.fortunecowsay.com/' => {
    isa  => 'LinkEmbedder::Link::Basic',
    html => qr{div class="le-paste le-provider-fortunecowsay le-rich".*pre.*\|\|-+w\s*\|}s,
  }
);

LinkEmbedder->new->test_ok(
  'https://catoverflow.com/cats/r4cIt4z.gif' => {

t/bitbucket.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://bitbucket.org/snippets/bpmedley/895ne' => {
    cache_age     => 0,
    html          => qr{<pre>use Mojolicious::Lite;},
    isa           => 'LinkEmbedder::Link::Basic',
    provider_name => 'Bitbucket',
    provider_url  => 'https://bitbucket.org/',
    title         => qr{ Bitbucket$},
    thumbnail_url => qr{apple-touch-icon},

t/centos-paste.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_CENTOS_ID=89d81534' unless $ENV{TEST_CENTOS_ID};
plan skip_all => 'cpanm IO::Socket::SSL'   unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  "https://paste.centos.org/view/$ENV{TEST_CENTOS_ID}" => {
    cache_age     => 0,
    html          => qr{<pre>sub foo},
    isa           => 'LinkEmbedder::Link::Basic',
    provider_name => 'Centos',
    provider_url  => 'https://paste.centos.org/',
    title         => qr{- Pastebin Service},
    type          => 'rich',

t/gist.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://gist.github.com/9604bd5f3c9c4f3620d0daedbdab975d' => {
    html => qr{le-paste le-rich le-provider-github.*Mojo::Server::Morbo::Backend::Inotify}s,
    isa  => 'LinkEmbedder::Link::Github',
    type => 'rich',
  }
);

LinkEmbedder->new->test_ok(

t/github.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

my %expected = (
  cache_age     => '0',
  provider_name => 'GitHub',
  provider_url  => 'https://github.com',
  type          => 'rich',
  version       => '1.0',
);

LinkEmbedder->new->test_ok(

t/google-meet.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;
plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};

LinkEmbedder->new->test_ok(
  'https://meet.google.com/cqd-myxw-phs' => {
    cache_age     => 0,
    class         => 'le-rich le-video-chat le-provider-google',
    html          => qr{src="https://meet\.google\.com/cqd-myxw-phs"},
    isa           => 'LinkEmbedder::Link::Google',
    provider_name => 'Google',
    provider_url  => 'https://meet.google.com/',

t/google.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

my $embedder = LinkEmbedder->new;
is $embedder->ua->max_redirects, 3, 'max_redirects';

# cheating to force google to serve complete page
$embedder->ua->transactor->name(
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'
);

$embedder->test_ok(

t/greatcirclemapper.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://www.greatcirclemapper.net/en/great-circle-mapper.html?route=KJFK-VHHH&aircraft=&speed=' => {
    isa           => 'LinkEmbedder::Link::Basic',
    class         => 'le-rich le-card le-image-card le-provider-greatcirclemapper',
    provider_name => 'Greatcirclemapper',
    html          => qr{<h3>Great Circle Mapper},
  }
);

t/ix.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'http://ix.io/fpW' => {
    isa           => 'LinkEmbedder::Link::Ix',
    cache_age     => 0,
    html          => paste_html(),
    provider_name => 'Ix',
    provider_url  => 'http://ix.io',
    type          => 'rich',
    url           => 'http://ix.io/fpW',

t/jitsi.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;
plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};

$ENV{TEST_JITSI_URL} ||= 'https://meet.jit.si/convostest';
my $provider_url = Mojo::URL->new($ENV{TEST_JITSI_URL})->path('')->to_string;

LinkEmbedder->new->test_ok(
  $ENV{TEST_JITSI_URL} => {
    html          => qr{allow="camera;microphone".*src="$provider_url[^"]+"},
    class         => 'le-rich le-video-chat le-provider-jitsi',
    isa           => 'LinkEmbedder::Link::Jitsi',

t/metacpan.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

my $embedder = LinkEmbedder->new;

my @tests = (
  {
    html          => qr{<h3>Search the CPAN},
    thumbnail_url => '//metacpan.org/static/icons/apple-touch-icon.png',
    title         => 'Search the CPAN - metacpan.org',
    url           => 'https://metacpan.org/',
  },

t/mojopaste.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://p.thorsen.pm/3808406ec6f6' => {
    cache_age     => 0,
    html          => qr{<pre>&lt;test&gt;paste!&lt;/test&gt;</pre>},
    isa           => 'LinkEmbedder::Link::Basic',
    provider_name => 'Thorsen',
    provider_url  => 'https://p.thorsen.pm/',
    title         => qr{ - Mojopaste},
    type          => 'rich',

t/nhl.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://www.nhl.com/video/edlers-blistering-one-timer/t-277752844/c-69511103' => {
    isa       => 'LinkEmbedder::Link::NHL',
    cache_age => 0,
    height    => 360,
    html =>
      qr{src="https://www\.nhl\.com/video/embed/edlers-blistering-one-timer/t-277752844/c-69511103\?autostart=false"},
    provider_name => 'NHL',
    provider_url  => 'https://www.nhl.com',

t/opensuse.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

my @urls = (
  'https://paste.opensuse.org/2931429',
  'https://paste.opensuse.org/view/raw/2931429',
  'https://paste.opensuse.org/view/simple/2931429',
);

for my $url (@urls) {
  LinkEmbedder->new->test_ok(
    $url => {

t/paste-debian.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
    'https://paste.debian.net/?show=1186554' => {
        cache_age        => 0,
        class            => 'le-paste le-provider-debian le-rich',
        html             => paste_debian_html(),
        isa              => 'LinkEmbedder::Link::Basic',
        provider_name    => 'Debian',
        provider_url     => 'https://paste.debian.net/?show=1186554',
        title            => 'debian Pastezone',

t/pastebin.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://pastebin.com/V5gZTzhy' => {
    isa           => 'LinkEmbedder::Link::Pastebin',
    cache_age     => 0,
    html          => qr{<pre>x=\$\(too cool\);</pre>},
    provider_name => 'Pastebin',
    provider_url  => 'https://pastebin.com',
    thumbnail_url => 'https://pastebin.com/i/facebook.png',
    title         => 'too cool paste - Pastebin.com',

t/perlbot.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_PERLBOT=xogtbq'   unless $ENV{TEST_PERLBOT};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  "https://perlbot.pl/p/$ENV{TEST_PERLBOT}" => {
    isa           => 'LinkEmbedder::Link::Basic',
    cache_age     => 0,
    html          => qr{<pre>use Mojo::Base},
    provider_name => 'Perlbot',
    provider_url  => 'https://perlbot.pl/',
    title         => qr{Perlbot Pastebin},
    type          => 'rich',

t/spotify.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'spotify:track:5tv77MoS0TzE0sJ7RwTj34' => {
    isa       => 'LinkEmbedder::Link::Spotify',
    cache_age => 0,
    html =>
      qr{<iframe.*src="https://embed\.spotify\.com\?theme=white&amp;uri=spotify%3Atrack%3A5tv77MoS0TzE0sJ7RwTj34&amp;view="},
    provider_name => 'Spotify',
    provider_url  => 'https://spotify.com',
    type          => 'rich',

t/ted.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://www.ted.com/talks/jill_bolte_taylor_s_powerful_stroke_of_insight' => {
    isa           => 'LinkEmbedder::Link::oEmbed',
    author_name   => 'Jill Bolte Taylor',
    cache_age     => 300,
    html          => qr{iframe.*src="},
    provider_name => 'TED',
    provider_url  => 'https://www.ted.com',
    title         => "Jill Bolte Taylor: My stroke of insight",

t/travis.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://travis-ci.org/Nordaaker/convos/builds/47421379' => {
    isa              => 'LinkEmbedder::Link::Travis',
    cache_age        => 0,
    class            => 'le-rich le-card le-image-card le-provider-travis',
    html             => qr{Build has},
    provider_name    => 'Travis',
    provider_url     => 'https://travis-ci.org',
    thumbnail_height => 501,

t/twitter.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

my @urls = (
  'https://twitter.com/jhthorsen/status/434045220116643843',
  'https://twitter.com/mulligan/status/555050159189413888/',
  'https://twitter.com/mulligan/status/555050159189413888/photo/1',
);

for my $src_url (@urls) {
  my $url = Mojo::URL->new($src_url);
  $url->path->trailing_slash(0);

t/vimeo.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://vimeo.com/154038415' => {
    isa           => 'LinkEmbedder::Link::oEmbed',
    author_name   => 'The Mill',
    cache_age     => 0,
    html          => qr{iframe.*src="},
    provider_name => 'Vimeo',
    provider_url  => 'https://vimeo.com/',
    title         => "Behind the Scenes: The Chemical Brothers 'Wide Open'",

t/webex.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;
plan skip_all => 'TEST_WEBEX_URL='       unless $ENV{TEST_WEBEX_URL};

LinkEmbedder->new->test_ok(
  $ENV{TEST_WEBEX_URL} => {
    cache_age     => 0,
    class         => 'le-rich le-video-chat le-provider-webex',
    html          => qr{src="$ENV{TEST_WEBEX_URL}"},
    isa           => 'LinkEmbedder::Link::Webex',
    provider_name => 'Webex',
    provider_url  => 'https://webex.com',

t/whereby.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;
plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};

LinkEmbedder->new->test_ok(
  'https://whereby.com/your-room-name' => {
    cache_age     => 0,
    class         => 'le-rich le-video-chat le-provider-whereby',
    height        => 390,
    html          => qr{src="https://whereby\.com/your-room-name\?embed"},
    isa           => 'LinkEmbedder::Link::Whereby',
    provider_name => 'Whereby',

t/xkcd.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://xkcd.com/927' => {
    isa           => 'LinkEmbedder::Link::Xkcd',
    cache_age     => 0,
    height        => 0,
    html          => photo_html(),
    provider_name => 'Xkcd',
    provider_url  => 'https://xkcd.com',
    thumbnail_url => '//imgs.xkcd.com/comics/standards.png',

t/youtube.t  view on Meta::CPAN

use Mojo::Base -strict;
use Test::More;
use LinkEmbedder;

plan skip_all => 'TEST_ONLINE=1'         unless $ENV{TEST_ONLINE};
plan skip_all => 'cpanm IO::Socket::SSL' unless LinkEmbedder::TLS;

LinkEmbedder->new->test_ok(
  'https://www.youtube.com/watch?v=OspRE1xnLjE' => {
    isa           => 'LinkEmbedder::Link::oEmbed',
    author_name   => qr{Mojoconf},
    author_url    => 'https://www.youtube.com/channel/UCgk2wCZr5Rk-cewLTtQA_Fg',
    cache_age     => 0,
    html          => qr{iframe.*src="},
    provider_name => 'YouTube',
    provider_url  => 'https://www.youtube.com/',



( run in 0.855 second using v1.01-cache-2.11-cpan-4d50c553e7e )