Fix some specs
parent
45bc4193ff
commit
bb041b8e50
|
@ -81,7 +81,7 @@ defmodule Hunter do
|
|||
* `uri` - URI of the remote user, in the format of `username@domain`
|
||||
|
||||
"""
|
||||
@spec follow_by_uri(Hunter.Client.t, URI.t) :: Hunter.Account.t
|
||||
@spec follow_by_uri(Hunter.Client.t, String.t) :: Hunter.Account.t
|
||||
defdelegate follow_by_uri(conn, uri), to: Hunter.Account
|
||||
|
||||
@doc """
|
||||
|
@ -188,7 +188,7 @@ defmodule Hunter do
|
|||
different instance. default: `https://mastodon.social`
|
||||
|
||||
"""
|
||||
@spec create_app(String.t, URI.t, [String.t], String.t, Keyword.t) :: Hunter.Application.t
|
||||
@spec create_app(String.t, String.t, [String.t], String.t, Keyword.t) :: Hunter.Application.t | no_return
|
||||
defdelegate create_app(name, redirect_uri \\ "urn:ietf:wg:oauth:2.0:oob", scopes \\ ["read"], website \\ nil, options \\ []), to: Hunter.Application
|
||||
|
||||
@doc """
|
||||
|
@ -342,7 +342,7 @@ defmodule Hunter do
|
|||
* `media_ids` - [Array<Integer>]
|
||||
|
||||
"""
|
||||
@spec create_status(Hunter.Client.t, String.t, non_neg_integer, [non_neg_integer]) :: Hunter.Status.t
|
||||
@spec create_status(Hunter.Client.t, String.t, non_neg_integer, [non_neg_integer]) :: Hunter.Status.t | no_return
|
||||
defdelegate create_status(conn, text, in_reply_to_id \\ nil, media_ids \\ []), to: Hunter.Status
|
||||
|
||||
@doc """
|
||||
|
@ -568,7 +568,7 @@ defmodule Hunter do
|
|||
* `conn` - connection credentials
|
||||
|
||||
"""
|
||||
@spec clear_notifications(Hunter.Client.t) :: map
|
||||
@spec clear_notifications(Hunter.Client.t) :: boolean
|
||||
defdelegate clear_notifications(conn), to: Hunter.Notification
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -30,9 +30,9 @@ defmodule Hunter.Account do
|
|||
acct: String.t,
|
||||
display_name: String.t,
|
||||
note: String.t,
|
||||
url: URI.t,
|
||||
avatar: URI.t,
|
||||
header: URI.t,
|
||||
url: String.t,
|
||||
avatar: String.t,
|
||||
header: String.t,
|
||||
locked: String.t,
|
||||
created_at: String.t,
|
||||
followers_count: non_neg_integer,
|
||||
|
@ -140,7 +140,7 @@ defmodule Hunter.Account do
|
|||
* `uri` - URI of the remote user, in the format of `username@domain`
|
||||
|
||||
"""
|
||||
@spec follow_by_uri(Hunter.Client.t, URI.t) :: Hunter.Account.t
|
||||
@spec follow_by_uri(Hunter.Client.t, String.t) :: Hunter.Account.t
|
||||
def follow_by_uri(conn, uri) do
|
||||
@hunter_api.follow_by_uri(conn, uri)
|
||||
end
|
||||
|
|
|
@ -163,7 +163,7 @@ defmodule Hunter.Api do
|
|||
Multiple scopes can be requested during the authorization phase with the `scope` query param
|
||||
|
||||
"""
|
||||
@callback create_app(name :: String.t, redirect_uri :: URI.t, scopes :: [String.t], website :: String.t, base_url :: String.t) :: Hunter.Application.t
|
||||
@callback create_app(name :: String.t, redirect_uri :: String.t, scopes :: [String.t], website :: String.t, base_url :: String.t) :: Hunter.Application.t | no_return
|
||||
|
||||
@doc """
|
||||
Upload a media file
|
||||
|
@ -284,7 +284,7 @@ defmodule Hunter.Api do
|
|||
* `media_ids` - [Array<Integer>]
|
||||
|
||||
"""
|
||||
@callback create_status(conn :: Hunter.Client.t, text :: String.t, in_reply_to_id :: non_neg_integer, media_ids :: [non_neg_integer]) :: Hunter.Status.t
|
||||
@callback create_status(conn :: Hunter.Client.t, text :: String.t, in_reply_to_id :: non_neg_integer, media_ids :: [non_neg_integer]) :: Hunter.Status.t | no_return
|
||||
|
||||
@doc """
|
||||
Retrieve status
|
||||
|
@ -492,7 +492,7 @@ defmodule Hunter.Api do
|
|||
* `conn` - connection credentials
|
||||
|
||||
"""
|
||||
@callback clear_notifications(conn :: Hunter.Client.t) :: map
|
||||
@callback clear_notifications(conn :: Hunter.Client.t) :: boolean
|
||||
|
||||
@doc """
|
||||
Retrieve a user's reports
|
||||
|
@ -550,5 +550,5 @@ defmodule Hunter.Api do
|
|||
* `base_url` - API base url, default: `https://mastodon.social`
|
||||
|
||||
"""
|
||||
@callback log_in(app :: Hunter.Application.t, username :: String.t, password :: String.t, base_url :: URI.t) :: Hunter.Client.t
|
||||
@callback log_in(app :: Hunter.Application.t, username :: String.t, password :: String.t, base_url :: String.t) :: Hunter.Client.t
|
||||
end
|
||||
|
|
|
@ -69,8 +69,12 @@ defmodule Hunter.Api.HTTPClient do
|
|||
def create_app(name, redirect_uri, scopes, website, base_url) do
|
||||
payload = Poison.encode!(%{client_name: name, redirect_uris: redirect_uri, scopes: Enum.join(scopes, " "), website: website})
|
||||
|
||||
%HTTPoison.Response{body: body, status_code: 200} = HTTPoison.post!(base_url <> "/api/v1/apps", payload, [{"Content-Type", "application/json"}])
|
||||
Poison.decode!(body, as: %Hunter.Application{})
|
||||
case HTTPoison.post(base_url <> "/api/v1/apps", payload, [{"Content-Type", "application/json"}]) do
|
||||
{:ok, %HTTPoison.Response{body: body, status_code: 200}} ->
|
||||
Poison.decode!(body, as: %Hunter.Application{})
|
||||
{:error, %HTTPoison.Error{reason: reason}} ->
|
||||
raise Hunter.Error, reason: reason
|
||||
end
|
||||
end
|
||||
|
||||
def upload_media(%Hunter.Client{base_url: base_url} = conn, file) do
|
||||
|
@ -136,13 +140,17 @@ defmodule Hunter.Api.HTTPClient do
|
|||
def create_status(%Hunter.Client{base_url: base_url} = conn, text, in_reply_to_id, _media_ids) do
|
||||
payload = Poison.encode!(%{status: text, in_reply_to_id: in_reply_to_id})
|
||||
|
||||
%HTTPoison.Response{body: body, status_code: 200} = HTTPoison.post!(base_url <> "/api/v1/statuses", payload, [{"Content-Type", "application/json"} | get_headers(conn)])
|
||||
to_status(body)
|
||||
case HTTPoison.post(base_url <> "/api/v1/statuses", payload, [{"Content-Type", "application/json"} | get_headers(conn)]) do
|
||||
{:ok, %HTTPoison.Response{body: body, status_code: 200}} ->
|
||||
to_status(body)
|
||||
{:error, %HTTPoison.Error{reason: reason}} ->
|
||||
raise Hunter.Error, reason: reason
|
||||
end
|
||||
end
|
||||
|
||||
def status(%Hunter.Client{base_url: base_url} = conn, id) do
|
||||
%HTTPoison.Response{body: body, status_code: 200} = HTTPoison.get!(base_url <> "/api/v1/statuses/#{id}", get_headers(conn))
|
||||
Poison.decode(body, as: %Hunter.Status{})
|
||||
to_status(body)
|
||||
end
|
||||
|
||||
def destroy_status(%Hunter.Client{base_url: base_url} = conn, id) do
|
||||
|
@ -245,8 +253,8 @@ defmodule Hunter.Api.HTTPClient do
|
|||
def clear_notifications(%Hunter.Client{base_url: base_url} = conn) do
|
||||
payload = Poison.encode!(%{})
|
||||
|
||||
%HTTPoison.Response{body: body, status_code: 200} = HTTPoison.post!(base_url <> "/api/v1/notifications/clear", payload, [{"Content-Type", "application/json"} | get_headers(conn)])
|
||||
body
|
||||
%HTTPoison.Response{status_code: 200} = HTTPoison.post!(base_url <> "/api/v1/notifications/clear", payload, [{"Content-Type", "application/json"} | get_headers(conn)])
|
||||
true
|
||||
end
|
||||
|
||||
def reports(%Hunter.Client{base_url: base_url} = conn) do
|
||||
|
|
|
@ -53,7 +53,7 @@ defmodule Hunter.Application do
|
|||
different instance. default: `https://mastodon.social`
|
||||
|
||||
"""
|
||||
@spec create_app(String.t, URI.t, [String.t], String.t, Keyword.t) :: Hunter.Application.t
|
||||
@spec create_app(String.t, String.t, [String.t], String.t, Keyword.t) :: Hunter.Application.t | no_return
|
||||
def create_app(name, redirect_uri \\ "urn:ietf:wg:oauth:2.0:oob", scopes \\ ["read"], website \\ nil, options \\ []) do
|
||||
save? = Keyword.get(options, :save?, false)
|
||||
base_url = Keyword.get(options, :api_base_url, "https://mastodon.social")
|
||||
|
|
|
@ -20,10 +20,10 @@ defmodule Hunter.Attachment do
|
|||
@type t :: %__MODULE__{
|
||||
id: non_neg_integer,
|
||||
type: String.t,
|
||||
url: URI.t,
|
||||
remote_url: URI.t,
|
||||
preview_url: URI.t,
|
||||
text_url: URI.t
|
||||
url: String.t,
|
||||
remote_url: String.t,
|
||||
preview_url: String.t,
|
||||
text_url: String.t
|
||||
}
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
|
|
|
@ -16,7 +16,7 @@ defmodule Hunter.Card do
|
|||
@hunter_api Hunter.Config.hunter_api()
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
url: URI.t,
|
||||
url: String.t,
|
||||
title: String.t,
|
||||
description: String.t,
|
||||
image: String.t
|
||||
|
|
|
@ -6,7 +6,7 @@ defmodule Hunter.Client do
|
|||
@hunter_api Hunter.Config.hunter_api()
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
base_url: URI.t,
|
||||
base_url: String.t,
|
||||
bearer_token: String.t
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ defmodule Hunter.Client do
|
|||
* `base_url` - API base url, default: `https://mastodon.social`
|
||||
|
||||
"""
|
||||
@spec log_in(Hunter.Application.t, String.t, String.t, URI.t) :: Hunter.Client.t
|
||||
@spec log_in(Hunter.Application.t, String.t, String.t, String.t) :: Hunter.Client.t
|
||||
def log_in(app, username, password, base_url \\ "https://mastodon.social") do
|
||||
@hunter_api.log_in(app, username, password, base_url)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
defmodule Hunter.Error do
|
||||
@type t :: %__MODULE__{reason: any}
|
||||
|
||||
defexception reason: nil
|
||||
|
||||
def message(%__MODULE__{reason: reason}), do: inspect(reason)
|
||||
end
|
|
@ -16,7 +16,7 @@ defmodule Hunter.Instance do
|
|||
@hunter_api Hunter.Config.hunter_api()
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
uri: URI.t,
|
||||
uri: String.t,
|
||||
title: String.t,
|
||||
description: String.t,
|
||||
email: String.t
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule Hunter.Mention do
|
|||
|
||||
"""
|
||||
@type t :: %__MODULE__{
|
||||
url: URI.t,
|
||||
url: String.t,
|
||||
username: String.t,
|
||||
acct: String.t,
|
||||
id: non_neg_integer
|
||||
|
|
|
@ -62,7 +62,7 @@ defmodule Hunter.Notification do
|
|||
* `conn` - connection credentials
|
||||
|
||||
"""
|
||||
@spec clear_notifications(Hunter.Client.t) :: map
|
||||
@spec clear_notifications(Hunter.Client.t) :: boolean
|
||||
def clear_notifications(conn) do
|
||||
@hunter_api.clear_notifications(conn)
|
||||
end
|
||||
|
|
|
@ -30,8 +30,8 @@ defmodule Hunter.Status do
|
|||
|
||||
@type t :: %__MODULE__{
|
||||
id: non_neg_integer,
|
||||
uri: URI.t,
|
||||
url: URI.t,
|
||||
uri: String.t,
|
||||
url: String.t,
|
||||
account: Hunter.Account.t,
|
||||
in_reply_to_id: non_neg_integer,
|
||||
reblog: Hunter.Status.t | nil,
|
||||
|
@ -84,7 +84,7 @@ defmodule Hunter.Status do
|
|||
* `media_ids` - [Array<Integer>]
|
||||
|
||||
"""
|
||||
@spec create_status(Hunter.Client.t, String.t, status_id, [non_neg_integer]) :: Hunter.Status.t
|
||||
@spec create_status(Hunter.Client.t, String.t, status_id, [non_neg_integer]) :: Hunter.Status.t | no_return
|
||||
def create_status(conn, text, in_reply_to_id \\ nil, media_ids \\ []) do
|
||||
@hunter_api.create_status(conn, text, in_reply_to_id, media_ids)
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule Hunter.Tag do
|
|||
|
||||
@type t :: %__MODULE__{
|
||||
name: String.t,
|
||||
url: URI.t
|
||||
url: String.t
|
||||
}
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
|
|
Loading…
Reference in New Issue