Skip to content

Commit

Permalink
update floki and use explicit parsing of floki (r8#27)
Browse files Browse the repository at this point in the history
Since the update of Floki to version 0.24.0 other projects get warnings
in there tests when using Floki 0.24.0 and oembed together. With this
commit the warnings will disapear because it uses the new parse_*/1
functions instead of the old Floki.parse/1 that is now depricated.
  • Loading branch information
fatboypunk authored Feb 10, 2020
1 parent 31b0eb8 commit aef6cf0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/oembed/providers/discoverable_provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ defmodule OEmbed.DiscoverableProvider do
defp discover(url) do
with {:ok, %HTTPoison.Response{body: html}} <-
HTTPoison.get(url, [], follow_redirect: true, ssl: [{:versions, [:"tlsv1.2"]}]),
[_ | _] = tags <- Floki.find(html, "head link[type$='json+oembed']"),
[_ | _] = tags <-
html
|> Floki.parse_document()
|> elem(1)
|> Floki.find("head link[type$='json+oembed']"),
{"link", attributes, _} <- List.first(tags),
%{"href" => href} <- Enum.into(attributes, %{}),
oembed_url = %URI{} <- URI.merge(url, href) do
Expand Down
6 changes: 5 additions & 1 deletion lib/oembed/providers/pinterest_provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ defmodule OEmbed.PinterestProvider do
defp get_page_type(url) do
with {:ok, %HTTPoison.Response{body: html}} <-
HTTPoison.get(url, [], follow_redirect: true, ssl: [{:versions, [:"tlsv1.2"]}]),
[_ | _] = tags <- Floki.find(html, "head meta[property='og:type']"),
[_ | _] = tags <-
html
|> Floki.parse_document()
|> elem(1)
|> Floki.find("head meta[property='og:type']"),
{"meta", attributes, _} <- List.first(tags),
%{"content" => content} <- Enum.into(attributes, %{}),
%{"type" => type} <- Regex.named_captures(~r/^pinterestapp\:(?<type>.+)/, content) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule OEmbed.Mixfile do
defp deps do
[
{:httpoison, ">= 0.9.0"},
{:floki, ">= 0.9.0"},
{:floki, ">= 0.24.0"},
{:poison, ">= 1.5.0"},
{:exconstructor, ">= 1.0.0"},
{:exvcr, "~> 0.9", only: :test},
Expand Down

0 comments on commit aef6cf0

Please sign in to comment.