Skip to content

convos-chat/linkembedder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

LinkEmbedder - Embed / expand oEmbed resources and other URL / links

SYNOPSIS

use LinkEmbedder;

my $embedder = LinkEmbedder->new(force_secure => 1);

# In some cases, you have to set a proper user_agent to get complete
# pages. This is done automatically by $embedder->serve()
$embedder->ua->transactor->name("Mozilla...");

$embedder->get_p("https://xkcd.com/927")->then(sub {
  my $link = shift;
  print $link->html;
})->wait;

DESCRIPTION

LinkEmbedder is a module that can expand an URL into a rich HTML snippet or simply to extract information about the URL.

This module replaces Mojolicious::Plugin::LinkEmbedder.

Go to https://thorsen.pm/linkembedder to see a demo of how it works.

These web pages are currently supported:

ATTRIBUTES

force_secure

$bool = $self->force_secure;
$self = $self->force_secure(1);

This attribute will translate any unknown http link to https.

This attribute is EXPERIMENTAL. Feeback appreciated.

ua

$ua = $self->ua;

Holds a Mojo::UserAgent object.

url_to_link

$hash_ref = $self->url_to_link;

Holds a mapping between host names and link class to use.

METHODS

get

$self = $self->get_p($url, sub { my ($self, $link) = @_ });

Same as "get_p", but takes a callback instead of returning a Mojo::Promise.

get_p

$promise = $self->get_p($url)->then(sub { my $link = shift });

Used to construct a new LinkEmbedder::Link object and retrieve information about the URL.

serve

$self = $self->serve(Mojolicious::Controller->new, $url);

Used as a helper for Mojolicious web applications to reply to an oEmbed request. Will also set "name" in Mojo::UserAgent::Transactor for "ua" if the incoming request contains a "User-Agent" header.

Note that in Mojolicious 9.11 and later, you must define the format for your route to serve with extension .html, .json or .jsonp.

AUTHOR

Jan Henning Thorsen

COPYRIGHT AND LICENSE

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

About

Embed / expand oEmbed resources and other URL / links

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published