Implemented favourite_by and reblogged_by from the API and added the type alias `status_id` to replace non_neg_integer
parent
8733c5cd99
commit
0f69f2fa6b
|
@ -53,6 +53,7 @@ defmodule Hunter.Api.HTTPClient do
|
|||
end
|
||||
|
||||
def create_app(%Hunter.Client{base_url: base_url} = conn, name, redirect_uri, scopes, website) do
|
||||
IO.puts redirect_uri
|
||||
payload = Poison.encode!(%{client_name: name, redirect_uris: redirect_uri, scopes: scopes, website: website})
|
||||
|
||||
%HTTPoison.Response{body: body, status_code: 200} = HTTPoison.post!(base_url <> "/api/v1/apps", payload, [{"Content-Type", "application/json"} | get_headers(conn)])
|
||||
|
@ -154,6 +155,11 @@ defmodule Hunter.Api.HTTPClient do
|
|||
to_status(body)
|
||||
end
|
||||
|
||||
def reblogged_by(%Hunter.Client{base_url: base_url} = conn, id) do
|
||||
%HTTPoison.Response{body: body, status_code: 200} = HTTPoison.get!(base_url <> "/api/v1/statuses/#{id}/reblogged_by", get_headers(conn))
|
||||
to_accounts(body)
|
||||
end
|
||||
|
||||
def favourite(%Hunter.Client{base_url: base_url} = conn, id) do
|
||||
payload = Poison.encode!(%{})
|
||||
|
||||
|
@ -173,6 +179,11 @@ defmodule Hunter.Api.HTTPClient do
|
|||
to_statuses(body)
|
||||
end
|
||||
|
||||
def favourited_by(%Hunter.Client{base_url: base_url} = conn, id) do
|
||||
%HTTPoison.Response{body: body, status_code: 200} = HTTPoison.get!(base_url <> "/api/v1/statuses/#{id}/favourited_by", get_headers(conn))
|
||||
to_accounts(body)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get an account's statuses
|
||||
|
||||
|
@ -264,6 +275,10 @@ defmodule Hunter.Api.HTTPClient do
|
|||
Poison.decode!(body, as: [status_nested_struct()])
|
||||
end
|
||||
|
||||
defp to_accounts(body) do
|
||||
Poison.decode!(body, as: [%Hunter.Account{}])
|
||||
end
|
||||
|
||||
defp status_nested_struct do
|
||||
%Hunter.Status{
|
||||
account: %Hunter.Account{},
|
||||
|
|
|
@ -49,6 +49,8 @@ defmodule Hunter.Status do
|
|||
application: Hunter.Application.t
|
||||
}
|
||||
|
||||
@type status_id :: non_neg_integer
|
||||
|
||||
@derive [Poison.Encoder]
|
||||
defstruct [:id,
|
||||
:uri,
|
||||
|
@ -82,7 +84,7 @@ defmodule Hunter.Status 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, status_id, [status_id]) :: Hunter.Status.t
|
||||
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
|
||||
|
@ -96,7 +98,7 @@ defmodule Hunter.Status do
|
|||
* `id` - status identifier
|
||||
|
||||
"""
|
||||
@spec status(Hunter.Client.t, non_neg_integer) :: Hunter.Status.t
|
||||
@spec status(Hunter.Client.t, status_id) :: Hunter.Status.t
|
||||
def status(conn, id) do
|
||||
@hunter_api.status(conn, id)
|
||||
end
|
||||
|
@ -110,7 +112,7 @@ defmodule Hunter.Status do
|
|||
* `id` - status identifier
|
||||
|
||||
"""
|
||||
@spec destroy_status(Hunter.Client.t, non_neg_integer) :: boolean
|
||||
@spec destroy_status(Hunter.Client.t, status_id) :: boolean
|
||||
def destroy_status(conn, id) do
|
||||
@hunter_api.destroy_status(conn, id)
|
||||
end
|
||||
|
@ -124,7 +126,7 @@ defmodule Hunter.Status do
|
|||
* `id` - status identifier
|
||||
|
||||
"""
|
||||
@spec reblog(Hunter.Client.t, non_neg_integer) :: Hunter.Status.t
|
||||
@spec reblog(Hunter.Client.t, status_id) :: Hunter.Status.t
|
||||
def reblog(conn, id) do
|
||||
@hunter_api.reblog(conn, id)
|
||||
end
|
||||
|
@ -138,11 +140,24 @@ defmodule Hunter.Status do
|
|||
* `id` - status identifier
|
||||
|
||||
"""
|
||||
@spec unreblog(Hunter.Client.t, non_neg_integer) :: Hunter.Status.t
|
||||
@spec unreblog(Hunter.Client.t, status_id) :: Hunter.Status.t
|
||||
def unreblog(conn, id) do
|
||||
@hunter_api.unreblog(conn, id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Fetch the list of users who reblogged the status.
|
||||
|
||||
## Parameters
|
||||
|
||||
* `conn` - connection credentials
|
||||
* `id` - status identifier
|
||||
"""
|
||||
@spec reblogged_by(Hunter.Client.t, non_neg_integer) :: Hunter.Status.t
|
||||
def reblogged_by(conn, id) do
|
||||
@hunter_api.reblogged_by(conn, id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Favorite a status
|
||||
|
||||
|
@ -152,7 +167,7 @@ defmodule Hunter.Status do
|
|||
* `id` - status identifier
|
||||
|
||||
"""
|
||||
@spec favourite(Hunter.Client.t, non_neg_integer) :: Hunter.Status.t
|
||||
@spec favourite(Hunter.Client.t, status_id) :: Hunter.Status.t
|
||||
def favourite(conn, id) do
|
||||
@hunter_api.favourite(conn, id)
|
||||
end
|
||||
|
@ -166,7 +181,7 @@ defmodule Hunter.Status do
|
|||
* `id` - status identifier
|
||||
|
||||
"""
|
||||
@spec unfavourite(Hunter.Client.t, non_neg_integer) :: Hunter.Status.t
|
||||
@spec unfavourite(Hunter.Client.t, status_id) :: Hunter.Status.t
|
||||
def unfavourite(conn, id) do
|
||||
@hunter_api.unfavourite(conn, id)
|
||||
end
|
||||
|
@ -184,6 +199,21 @@ defmodule Hunter.Status do
|
|||
@hunter_api.favourites(conn)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Fetch the list of users who favourited the status
|
||||
|
||||
## Parameters
|
||||
|
||||
* `conn` - connection credentials
|
||||
* `id` - status identifier
|
||||
|
||||
"""
|
||||
|
||||
@spec favourited_by(Hunter.Client.t, status_id) :: [Hunter.Status.t]
|
||||
def favourited_by(conn, id) do
|
||||
@hunter_api.favourited_by(conn, id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Get a list of statuses by a user
|
||||
|
||||
|
@ -200,7 +230,7 @@ defmodule Hunter.Status do
|
|||
* `limit` - [Integer]
|
||||
|
||||
"""
|
||||
@spec statuses(Hunter.Client.t, non_neg_integer, Keyword.t) :: [Hunter.Status.t]
|
||||
@spec statuses(Hunter.Client.t, status_id, Keyword.t) :: [Hunter.Status.t]
|
||||
def statuses(conn, account_id, options \\ []) do
|
||||
@hunter_api.statuses(conn, account_id, options)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue