-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes
- Loading branch information
Showing
13 changed files
with
125 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Change Log | ||
|
||
## [0.1.0] - 2017-02-25 | ||
|
||
Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,37 @@ | ||
defmodule OEmbed.Provider do | ||
@moduledoc """ | ||
oEmbed provider behaviour. | ||
""" | ||
|
||
defmacro __using__(_) do | ||
quote do | ||
import OEmbed.Provider | ||
|
||
@behaviour OEmbed.Provider | ||
end | ||
end | ||
alias OEmbed.Link | ||
alias OEmbed.Photo | ||
alias OEmbed.Rich | ||
alias OEmbed.Video | ||
|
||
alias OEmbed.{Link, Photo, Rich, Video} | ||
@behaviour OEmbed.Provider | ||
|
||
@callback provides?(String.t) :: boolean | ||
defp get_oembed(url) do | ||
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(url, [], [follow_redirect: true, ssl: [{:versions, [:'tlsv1.2']}]]), | ||
{:ok, struct} <- Poison.decode(body), | ||
resource <- get_resource(struct) do | ||
{:ok, resource} | ||
else | ||
_ -> {:error, "oEmbed url not found"} | ||
end | ||
end | ||
|
||
def get_oembed(url) do | ||
with {:ok, %HTTPoison.Response{body: body}} <- HTTPoison.get(url, [], [follow_redirect: true, ssl: [{:versions, [:'tlsv1.2']}]]), | ||
{:ok, struct} <- Poison.decode(body), | ||
resource <- get_resource(struct) do | ||
{:ok, resource} | ||
else | ||
_ -> {:error, "oEmbed url not found"} | ||
defp get_resource(%{"type" => "link"} = struct), do: Link.new(struct) | ||
defp get_resource(%{"type" => "photo"} = struct), do: Photo.new(struct) | ||
defp get_resource(%{"type" => "rich"} = struct), do: Rich.new(struct) | ||
defp get_resource(%{"type" => "video"} = struct), do: Video.new(struct) | ||
defp get_resource(struct), do: struct | ||
end | ||
end | ||
|
||
defp get_resource(%{"type" => "link"} = struct), do: Link.new(struct) | ||
defp get_resource(%{"type" => "photo"} = struct), do: Photo.new(struct) | ||
defp get_resource(%{"type" => "rich"} = struct), do: Rich.new(struct) | ||
defp get_resource(%{"type" => "video"} = struct), do: Video.new(struct) | ||
defp get_resource(struct), do: struct | ||
end | ||
@callback provides?(String.t) :: boolean | ||
@callback get(String.t) :: struct | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
defmodule OEmbed.Resource do | ||
@moduledoc """ | ||
oEmbed resource | ||
oEmbed resource. | ||
""" | ||
|
||
defmacro __using__(_) do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
defmodule OEmbed.Link do | ||
@moduledoc """ | ||
oEmbed Link resource. | ||
""" | ||
|
||
@keys [type: "link"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters