Skip to content

Commit

Permalink
add req_options to fetch!
Browse files Browse the repository at this point in the history
  • Loading branch information
goofansu committed Aug 24, 2024
1 parent 512a619 commit efc59b0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/open_graph.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule OpenGraph do
:video
]

@type url() :: URI.t() | String.t()
@type value() :: String.t() | nil

@type t() :: %__MODULE__{
Expand All @@ -35,7 +36,8 @@ defmodule OpenGraph do
Returns `{:ok, %OpenGraph{}}` for succussful request, otherwise, returns `{:error, %OpenGraph.Error{}}`.
"""

@spec fetch(String.t()) :: {:ok, OpenGraph.t()} | {:error, OpenGraph.Error.t()}
@spec fetch(url(), req_options :: keyword()) ::
{:ok, OpenGraph.t()} | {:error, OpenGraph.Error.t()}
def fetch(url, req_options \\ []) do
options = Keyword.merge(req_options, Application.get_env(:ogp, :req_options, []))

Expand Down Expand Up @@ -64,13 +66,13 @@ defmodule OpenGraph do
end

@doc """
Similar to `fetch/1` but raises a `OpenGraph.Error` exception if request failed.
Similar to `fetch/2` but raises an `OpenGraph.Error` if request failed.
Returns `%OpenGraph{}`.
"""
@spec fetch!(String.t()) :: OpenGraph.t()
def fetch!(url) do
case fetch(url) do
@spec fetch!(url(), req_options :: keyword()) :: OpenGraph.t()
def fetch!(url, req_options \\ []) do
case fetch(url, req_options) do
{:ok, result} ->
result

Expand Down

0 comments on commit efc59b0

Please sign in to comment.