Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial type specs #59

Merged
merged 9 commits into from Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/req.ex
Expand Up @@ -8,12 +8,15 @@ defmodule Req do
|> String.split("<!-- MDOC !-->")
|> Enum.fetch!(1)

@type method :: :get | :post | :put | :delete
wojtekmach marked this conversation as resolved.
Show resolved Hide resolved

@doc """
Makes a GET request.

See `request/3` for a list of supported options.
"""
@doc api: :high_level
@spec get!(String.t(), keyword()) :: Req.Response.t()
wojtekmach marked this conversation as resolved.
Show resolved Hide resolved
def get!(url, options \\ []) do
request!(:get, url, options)
end
Expand All @@ -24,6 +27,7 @@ defmodule Req do
See `request/3` for a list of supported options.
"""
@doc api: :high_level
@spec post!(String.t(), term(), keyword()) :: Req.Response.t()
wojtekmach marked this conversation as resolved.
Show resolved Hide resolved
def post!(url, body, options \\ []) do
options = Keyword.put(options, :body, body)
request!(:post, url, options)
Expand All @@ -35,6 +39,7 @@ defmodule Req do
See `request/3` for a list of supported options.
"""
@doc api: :high_level
@spec put!(String.t(), term(), keyword()) :: Req.Response.t()
wojtekmach marked this conversation as resolved.
Show resolved Hide resolved
def put!(url, body, options \\ []) do
options = Keyword.put(options, :body, body)
request!(:put, url, options)
Expand All @@ -46,6 +51,7 @@ defmodule Req do
See `request/3` for a list of supported options.
"""
@doc api: :high_level
@spec delete!(String.t(), keyword()) :: Req.Response.t()
wojtekmach marked this conversation as resolved.
Show resolved Hide resolved
def delete!(url, options \\ []) do
request!(:delete, url, options)
end
Expand All @@ -71,6 +77,7 @@ defmodule Req do
The `options` are merged with default options set with `default_options/1`.
"""
@doc api: :high_level
@spec request(method(), String.t(), keyword()) :: {:ok, Req.Response.t()} | {:error, Exception.t()}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@spec request(method(), String.t(), keyword()) :: {:ok, Req.Response.t()} | {:error, Exception.t()}
@spec request(method(), url(), keyword()) :: {:ok, Req.Response.t()} | {:error, Exception.t()}

def request(method, url, options \\ []) do
options = Keyword.merge(default_options(), options)

Expand All @@ -86,6 +93,7 @@ defmodule Req do
See `request/3` for more information.
"""
@doc api: :high_level
@spec request!(method(), String.t(), keyword()) :: Req.Response.t()
wojtekmach marked this conversation as resolved.
Show resolved Hide resolved
def request!(method, url, options \\ []) do
options = Keyword.merge(default_options(), options)

Expand All @@ -101,6 +109,7 @@ defmodule Req do
See `default_options/1` for more information.
"""
@doc api: :high_level
@spec default_options() :: keyword()
def default_options() do
Application.get_env(:req, :default_options, [])
end
Expand All @@ -114,6 +123,7 @@ defmodule Req do
Avoid setting default options in libraries as they are global.
"""
@doc api: :high_level
@spec default_options(keyword()) :: :ok
def default_options(options) do
Application.put_env(:req, :default_options, options)
end
Expand Down
6 changes: 6 additions & 0 deletions lib/req/response.ex
Expand Up @@ -15,6 +15,12 @@ defmodule Req.Response do
conflicts. Only accepts `t:atom/0` keys.
"""

@type t() :: %__MODULE__{
status: non_neg_integer(),
headers: [{binary(), binary()}],
body: binary()
wojtekmach marked this conversation as resolved.
Show resolved Hide resolved
}

defstruct [
:status,
headers: [],
Expand Down