Update endpoints according to recent docs

master
Milton Mazzarri 2017-06-02 17:43:09 -05:00
parent 1514c96a2e
commit ac9c143bd7
No known key found for this signature in database
GPG Key ID: 9F4193F2B5A558FE
15 changed files with 569 additions and 141 deletions

View File

@ -55,10 +55,17 @@ defmodule Hunter do
* `conn` - connection credentials
* `id` - account identifier
* `options` - options list
## Options
* `max_id` - get a list of followers with id less than or equal this value
* `since_id` - get a list of followers with id greater than this value
* `limit` - maximum number of followers to get, default: 40, maximum: 80
"""
@spec followers(Hunter.Client.t, non_neg_integer) :: [Hunter.Account.t]
defdelegate followers(conn, id), to: Hunter.Account
@spec followers(Hunter.Client.t, non_neg_integer, Keyword.t) :: [Hunter.Account.t]
defdelegate followers(conn, id, options \\ []), to: Hunter.Account
@doc """
Get a list of followed accounts
@ -67,10 +74,17 @@ defmodule Hunter do
* `conn` - connection credentials
* `id` - account identifier
* `options` - options list
## Options
* `max_id` - get a list of followings with id less than or equal this value
* `since_id` - get a list of followings with id greater than this value
* `limit` - maximum number of followings to get, default: 40, maximum: 80
"""
@spec following(Hunter.Client.t, non_neg_integer) :: [Hunter.Account.t]
defdelegate following(conn, id), to: Hunter.Account
@spec following(Hunter.Client.t, non_neg_integer, Keyword.t) :: [Hunter.Account.t]
defdelegate following(conn, id, options \\ []), to: Hunter.Account
@doc """
Follow a remote user
@ -108,9 +122,15 @@ defmodule Hunter do
* `conn` - connection credentials
## Options
* `max_id` - get a list of blocks with id less than or equal this value
* `since_id` - get a list of blocks with id greater than this value
* `limit` - maximum number of blocks to get, default: 40, max: 80
"""
@spec blocks(Hunter.Client.t) :: [Hunter.Account.t]
defdelegate blocks(conn), to: Hunter.Account
@spec blocks(Hunter.Client.t, Keyword.t) :: [Hunter.Account.t]
defdelegate blocks(conn, options \\ []), to: Hunter.Account
@doc """
Retrieve a list of follow requests
@ -118,10 +138,17 @@ defmodule Hunter do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of follow requests with id less than or equal this value
* `since_id` - get a list of follow requests with id greater than this value
* `limit` - maximum number of requests to get, default: 40, max: 80
"""
@spec follow_requests(Hunter.Client.t) :: [Hunter.Account.t]
defdelegate follow_requests(conn), to: Hunter.Account
@spec follow_requests(Hunter.Client.t, Keyword.t) :: [Hunter.Account.t]
defdelegate follow_requests(conn, options \\ []), to: Hunter.Account
@doc """
Retrieve user's mutes
@ -129,10 +156,17 @@ defmodule Hunter do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of mutes with id less than or equal this value
* `since_id` - get a list of mutes with id greater than this value
* `limit` - maximum number of mutes to get, default: 40, max: 80
"""
@spec mutes(Hunter.Client.t) :: [Hunter.Account.t]
defdelegate mutes(conn), to: Hunter.Account
@spec mutes(Hunter.Client.t, Keyword.t) :: [Hunter.Account.t]
defdelegate mutes(conn, options \\ []), to: Hunter.Account
@doc """
Accepts a follow request
@ -407,10 +441,17 @@ defmodule Hunter do
* `conn` - connection credentials
* `id` - status identifier
* `options` - option list
## Options
* `max_id` - get a list of *reblogged by* ids less than or equal this value
* `since_id` - get a list of *reblogged by* ids greater than this value
* `limit` - maximum number of *reblogged by* to get, default: 40, max: 80
"""
@spec reblogged_by(Hunter.Client.t, non_neg_integer) :: [Hunter.Account.t]
defdelegate reblogged_by(conn, id), to: Hunter.Status
@spec reblogged_by(Hunter.Client.t, non_neg_integer, Keyword.t) :: [Hunter.Account.t]
defdelegate reblogged_by(conn, id, options \\ []), to: Hunter.Status
@doc """
Favorite a status
@ -442,10 +483,17 @@ defmodule Hunter do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of favourites with id less than or equal this value
* `since_id` - get a list of favourites with id greater than this value
* `limit` - maximum of favourites to get, default: 20, max: 40
"""
@spec favourites(Hunter.Client.t) :: [Hunter.Status.t]
defdelegate favourites(conn), to: Hunter.Status
@spec favourites(Hunter.Client.t, Keyword.t) :: [Hunter.Status.t]
defdelegate favourites(conn, options \\ []), to: Hunter.Status
@doc """
Fetch the list of users who favourited the status
@ -454,11 +502,18 @@ defmodule Hunter do
* `conn` - connection credentials
* `id` - status identifier
* `options` - option list
## Options
* `max_id` - get a list of *favourited by* ids less than or equal this value
* `since_id` - get a list of *favourited by* ids greater than this value
* `limit` - maximum number of *favourited by* to get, default: 40, max: 80
"""
@spec favourited_by(Hunter.Client.t, non_neg_integer) :: [Hunter.Account.t]
defdelegate favourited_by(conn, id), to: Hunter.Status
@spec favourited_by(Hunter.Client.t, non_neg_integer, Keyword.t) :: [Hunter.Account.t]
defdelegate favourited_by(conn, id, options \\ []), to: Hunter.Status
@doc """
Get a list of statuses by a user
@ -473,9 +528,9 @@ defmodule Hunter do
* `only_media` - only return `Hunter.Status.t` that have media attachments
* `exclude_replies` - skip statuses that reply to other statuses
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `max_id` - get a list of statuses with id less than or equal this value
* `since_id` - get a list of statuses with id greater than this value
* `limit` - maximum number of statuses to get, default: 20, max: 40
"""
@spec statuses(Hunter.Client.t, non_neg_integer, Keyword.t) :: [Hunter.Status.t]
@ -491,9 +546,9 @@ defmodule Hunter do
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec home_timeline(Hunter.Client.t, Keyword.t) :: [Hunter.Status.t]
@ -509,9 +564,10 @@ defmodule Hunter do
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `local` - only return statuses originating from this instance
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec public_timeline(Hunter.Client.t, Keyword.t) :: [Hunter.Status.t]
@ -524,12 +580,14 @@ defmodule Hunter do
* `conn` - connection credentials
* `hashtag` - string list
* `options` - option list
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `local` - only return statuses originating from this instance
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec hashtag_timeline(Hunter.Client.t, [String.t], Keyword.t) :: [Hunter.Status.t]
@ -552,10 +610,17 @@ defmodule Hunter do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of notifications with id less than or equal this value
* `since_id` - get a list of notifications with id greater than this value
* `limit` - maximum number of notifications to get, default: 15, max: 30
"""
@spec notifications(Hunter.Client.t) :: [Hunter.Notification.t]
defdelegate notifications(conn), to: Hunter.Notification
@spec notifications(Hunter.Client.t, Keyword.t) :: [Hunter.Notification.t]
defdelegate notifications(conn, options \\ []), to: Hunter.Notification
@doc """
Retrieve single notification
@ -580,6 +645,18 @@ defmodule Hunter do
@spec clear_notifications(Hunter.Client.t) :: boolean
defdelegate clear_notifications(conn), to: Hunter.Notification
@doc """
Dismiss a single notification
## Parameters
* `conn` - connection credentials
* `id` - notification id
"""
@spec clear_notification(Hunter.Client.t, non_neg_integer) :: boolean
defdelegate clear_notification(conn, id), to: Hunter.Notification
@doc """
Retrieve a user's reports
@ -642,6 +719,45 @@ defmodule Hunter do
"""
defdelegate log_in(app, username, password, base_url \\ nil), to: Hunter.Client
@doc """
Fetch user's blocked domains
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of blocks with id less than or equal this value
* `since_id` - get a list of blocks with id greater than this value
* `limit` - maximum number of blocks to get, default: 40, max: 80
"""
defdelegate blocked_domains(conn, options \\ []), to: Hunter.Domain
@doc """
Block a domain
## Parameters
* `conn` - connection credentials
* `domain` - domain to block
"""
defdelegate block_domain(conn, domain), to: Hunter.Domain
@doc """
Unblock a domain
## Parameters
* `conn` - connection credentials
* `domain` - domain to unblock
"""
defdelegate unblock_domain(conn, domain), to: Hunter.Domain
@doc """
Returns Hunter version
"""

View File

@ -14,7 +14,9 @@ defmodule Hunter.Account do
* `note` - biography of user
* `url` - URL of the user's profile page (can be remote)
* `avatar` - URL to the avatar image
* `avatar_static` - URL to the avatar static image (gif)
* `header` - URL to the header image
* `header_static` - URL to the header static image (gif)
* `locked` - boolean for when the account cannot be followed without waiting for approval first
* `created_at` - the time the account was created
* `followers_count` - the number of followers for the account
@ -32,7 +34,9 @@ defmodule Hunter.Account do
note: String.t,
url: String.t,
avatar: String.t,
avatar_static: String.t,
header: String.t,
header_static: String.t,
locked: String.t,
created_at: String.t,
followers_count: non_neg_integer,
@ -48,7 +52,9 @@ defmodule Hunter.Account do
:note,
:url,
:avatar,
:avatar_static,
:header,
:header_static,
:locked,
:created_at,
:followers_count,
@ -69,10 +75,12 @@ defmodule Hunter.Account do
iex> Hunter.Account.verify_credentials(conn)
%Hunter.Account{acct: "milmazz",
avatar: "https://social.lou.lt/avatars/original/missing.png",
avatar_static: "https://social.lou.lt/avatars/original/missing.png",
created_at: "2017-04-06T17:43:55.325Z",
display_name: "Milton Mazzarri", followers_count: 4,
following_count: 4,
header: "https://social.lou.lt/headers/original/missing.png",
header_static: "https://social.lou.lt/headers/original/missing.png",
id: 8039, locked: false, note: "", statuses_count: 3,
url: "https://social.lou.lt/@milmazz", username: "milmazz"}
@ -124,11 +132,18 @@ defmodule Hunter.Account do
* `conn` - connection credentials
* `id` - account id
* `options` - options list
## Options
* `max_id` - get a list of followers with id less than or equal this value
* `since_id` - get a list of followers with id greater than this value
* `limit` - maximum number of followers to get, default: 40, maximum: 80
"""
@spec followers(Hunter.Client.t, non_neg_integer) :: [Hunter.Account.t]
def followers(conn, id) do
@hunter_api.followers(conn, id)
@spec followers(Hunter.Client.t, non_neg_integer, Keyword.t) :: [Hunter.Account.t]
def followers(conn, id, options \\ []) do
@hunter_api.followers(conn, id, options)
end
@doc """
@ -138,11 +153,18 @@ defmodule Hunter.Account do
* `conn` - connection credentials
* `id` - account id
* `options` - options list
## Options
* `max_id` - get a list of followings with id less than or equal this value
* `since_id` - get a list of followings with id greater than this value
* `limit` - maximum number of followings to get, default: 40, maximum: 80
"""
@spec following(Hunter.Client.t, non_neg_integer) :: [Hunter.Account.t]
def following(conn, id) do
@hunter_api.following(conn, id)
@spec following(Hunter.Client.t, non_neg_integer, Keyword.t) :: [Hunter.Account.t]
def following(conn, id, options \\ []) do
@hunter_api.following(conn, id, options)
end
@doc """
@ -176,7 +198,7 @@ defmodule Hunter.Account do
@spec search_account(Hunter.Client.t, Keyword.t) :: [Hunter.Account.t]
def search_account(conn, options) do
opts = %{
q: Keyword.get(options, :q),
q: Keyword.fetch!(options, :q),
limit: Keyword.get(options, :limit, 40)
}
@ -190,10 +212,16 @@ defmodule Hunter.Account do
* `conn` - connection credentials
## Options
* `max_id` - get a list of blocks with id less than or equal this value
* `since_id` - get a list of blocks with id greater than this value
* `limit` - maximum number of blocks to get, default: 40, max: 80
"""
@spec blocks(Hunter.Client.t) :: [Hunter.Account.t]
def blocks(conn) do
@hunter_api.blocks(conn)
@spec blocks(Hunter.Client.t, Keyword.t) :: [Hunter.Account.t]
def blocks(conn, options \\ []) do
@hunter_api.blocks(conn, options)
end
@doc """
@ -202,11 +230,18 @@ defmodule Hunter.Account do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of follow requests with id less than or equal this value
* `since_id` - get a list of follow requests with id greater than this value
* `limit` - maximum number of requests to get, default: 40, max: 80
"""
@spec follow_requests(Hunter.Client.t) :: [Hunter.Account.t]
def follow_requests(conn) do
@hunter_api.follow_requests(conn)
@spec follow_requests(Hunter.Client.t, Keyword.t) :: [Hunter.Account.t]
def follow_requests(conn, options \\ []) do
@hunter_api.follow_requests(conn, options)
end
@doc """
@ -215,11 +250,18 @@ defmodule Hunter.Account do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of mutes with id less than or equal this value
* `since_id` - get a list of mutes with id greater than this value
* `limit` - maximum number of mutes to get, default: 40, max: 80
"""
@spec mutes(Hunter.Client.t) :: [Hunter.Account.t]
def mutes(conn) do
@hunter_api.mutes(conn)
@spec mutes(Hunter.Client.t, Keyword.t) :: [Hunter.Account.t]
def mutes(conn, options \\ []) do
@hunter_api.mutes(conn, options)
end
@doc """

View File

@ -51,9 +51,16 @@ defmodule Hunter.Api do
* `conn` - connection credentials
* `id` - account identifier
* `options` - options list
## Options
* `max_id` - get a list of followings with id less than or equal this value
* `since_id` - get a list of followings with id greater than this value
* `limit` - maximum number of followings to get, default: 40, maximum: 80
"""
@callback followers(conn :: Hunter.Client.t, id :: non_neg_integer) :: Hunter.Account.t
@callback followers(conn :: Hunter.Client.t, id :: non_neg_integer, options :: Keyword.t) :: Hunter.Account.t
@doc """
Get a list of followed accounts
@ -62,9 +69,16 @@ defmodule Hunter.Api do
* `conn` - connection credentials
* `id` - account identifier
* `options` - options list
## Options
* `max_id` - get a list of followings with id less than or equal this value
* `since_id` - get a list of followings with id greater than this value
* `limit` - maximum number of followings to get, default: 40, maximum: 80
"""
@callback following(conn :: Hunter.Client.t, id :: non_neg_integer) :: Hunter.Account.t
@callback following(conn :: Hunter.Client.t, id :: non_neg_integer, options :: Keyword.t) :: Hunter.Account.t
@doc """
Follow a remote user
@ -100,8 +114,14 @@ defmodule Hunter.Api do
* `conn` - connection credentials
## Options
* `max_id` - get a list of blocks with id less than or equal this value
* `since_id` - get a list of blocks with id greater than this value
* `limit` - maximum number of blocks to get, default: 40, max: 80
"""
@callback blocks(conn :: Hunter.Client.t) :: [Hunter.Account.t]
@callback blocks(conn :: Hunter.Client.t, options :: Keyword.t) :: [Hunter.Account.t]
@doc """
Retrieve a list of follow requests
@ -109,9 +129,16 @@ defmodule Hunter.Api do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of follow requests with id less than or equal this value
* `since_id` - get a list of follow requests with id greater than this value
* `limit` - maximum number of requests to get, default: 40, max: 80
"""
@callback follow_requests(conn :: Hunter.Client.t) :: [Hunter.Account.t]
@callback follow_requests(conn :: Hunter.Client.t, options :: Keyword.t) :: [Hunter.Account.t]
@doc """
Retrieve user's mutes
@ -119,9 +146,16 @@ defmodule Hunter.Api do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of mutes with id less than or equal this value
* `since_id` - get a list of mutes with id greater than this value
* `limit` - maximum number of mutes to get, default: 40, max: 80
"""
@callback mutes(conn :: Hunter.Client.t) :: [Hunter.Account.t]
@callback mutes(conn :: Hunter.Client.t, options :: Keyword.t) :: [Hunter.Account.t]
@doc """
Accepts or Rejects a follow request
@ -344,9 +378,16 @@ defmodule Hunter.Api do
* `conn` - connection credentials
* `id` - status identifier
* `options` - option list
## Options
* `max_id` - get a list of *reblogged by* ids less than or equal this value
* `since_id` - get a list of *reblogged by* ids greater than this value
* `limit` - maximum number of *reblogged by* to get, default: 40, max: 80
"""
@callback reblogged_by(conn :: Hunter.Client.t, id :: non_neg_integer) :: [Hunter.Account.t]
@callback reblogged_by(conn :: Hunter.Client.t, id :: non_neg_integer, options :: Keyword.t) :: [Hunter.Account.t]
@doc """
Favorite a status
@ -376,9 +417,16 @@ defmodule Hunter.Api do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of favourites with id less than or equal this value
* `since_id` - get a list of favourites with id greater than this value
* `limit` - maximum of favourites to get, default: 20, max: 40
"""
@callback favourites(conn :: Hunter.Client.t) :: [Hunter.Status.t]
@callback favourites(conn :: Hunter.Client.t, options :: Keyword.t) :: [Hunter.Status.t]
@doc """
Fetch the list of users who favourited the status.
@ -387,9 +435,16 @@ defmodule Hunter.Api do
* `conn` - connection credentials
* `id` - status identifier
* `options` - option list
## Options
* `max_id` - get a list of *favourited by* ids less than or equal this value
* `since_id` - get a list of *favourited by* ids greater than this value
* `limit` - maximum number of *favourited by* to get, default: 40, max: 80
"""
@callback favourited_by(conn :: Hunter.Client.t, id :: non_neg_integer) :: [Hunter.Account.t]
@callback favourited_by(conn :: Hunter.Client.t, id :: non_neg_integer, options :: Keyword.t) :: [Hunter.Account.t]
@doc """
Get a list of statuses by a user
@ -404,9 +459,9 @@ defmodule Hunter.Api do
* `only_media` - only return `Hunter.Status.t` that have media attachments
* `exclude_replies` - skip statuses that reply to other statuses
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `max_id` - get a list of statuses with id less than or equal this value
* `since_id` - get a list of statuses with id greater than this value
* `limit` - maximum number of statuses to get, default: 20, max: 40
"""
@callback statuses(conn :: Hunter.Client.t, account_id :: non_neg_integer, options :: map) :: [Hunter.Status.t]
@ -421,9 +476,9 @@ defmodule Hunter.Api do
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@callback home_timeline(conn :: Hunter.Client.t, options :: map) :: [Hunter.Status.t]
@ -438,9 +493,10 @@ defmodule Hunter.Api do
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `local` - only return statuses originating from this instance
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@callback public_timeline(conn :: Hunter.Client.t, options :: map) :: [Hunter.Status.t]
@ -452,12 +508,14 @@ defmodule Hunter.Api do
* `conn` - connection credentials
* `hashtag` - list of strings
* `options` - option list
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `local` - only return statuses originating from this instance
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@callback hashtag_timeline(conn :: Hunter.Client.t, hashtag :: [String.t], options :: map) :: [Hunter.Status]
@ -478,9 +536,16 @@ defmodule Hunter.Api do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of notifications with id less than or equal this value
* `since_id` - get a list of notifications with id greater than this value
* `limit` - maximum number of notifications to get, default: 15, max: 30
"""
@callback notifications(conn :: Hunter.Client.t) :: [Hunter.Notification.t]
@callback notifications(conn :: Hunter.Client.t, options :: Keyword.t) :: [Hunter.Notification.t]
@doc """
Retrieve single notification
@ -503,6 +568,17 @@ defmodule Hunter.Api do
"""
@callback clear_notifications(conn :: Hunter.Client.t) :: boolean
@doc """
Dismiss a single notification
## Parameters
* `conn` - connection credentials
* `id` - notification id
"""
@callback clear_notification(conn :: Hunter.Client.t, id :: non_neg_integer) :: boolean
@doc """
Retrieve a user's reports
@ -560,4 +636,43 @@ defmodule Hunter.Api do
"""
@callback log_in(app :: Hunter.Application.t, username :: String.t, password :: String.t, base_url :: String.t) :: Hunter.Client.t
@doc """
Fetch user's blocked domains
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of blocks with id less than or equal this value
* `since_id` - get a list of blocks with id greater than this value
* `limit` - maximum number of blocks to get, default: 40, max: 80
"""
@callback blocked_domains(conn :: Hunter.Client.t, options :: Keyword.t) :: list
@doc """
Block a domain
## Parameters
* `conn` - connection credentials
* `domain` - domain to block
"""
@callback block_domain(conn :: Hunter.Client.t, domain :: String.t) :: boolean
@doc """
Unblock a domain
## Parameters
* `conn` - connection credentials
* `domain` - domain to unblock
"""
@callback unblock_domain(conn :: Hunter.Client.t, domain :: String.t) :: boolean
end

View File

@ -25,15 +25,15 @@ defmodule Hunter.Api.HTTPClient do
|> transform(:account)
end
def followers(conn, id) do
def followers(conn, id, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/accounts/#{id}/followers"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/accounts/#{id}/followers"), options, get_headers(conn))
|> transform(:accounts)
end
def following(conn, id) do
def following(conn, id, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/accounts/#{id}/following"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/accounts/#{id}/following"), options, get_headers(conn))
|> transform(:accounts)
end
@ -49,21 +49,21 @@ defmodule Hunter.Api.HTTPClient do
|> transform(:accounts)
end
def blocks(conn) do
def blocks(conn, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/blocks"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/blocks"), options, get_headers(conn))
|> transform(:accounts)
end
def follow_requests(conn) do
def follow_requests(conn, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/follow_requests"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/follow_requests"), options, get_headers(conn))
|> transform(:accounts)
end
def mutes(conn) do
def mutes(conn, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/mutes"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/mutes"), options, get_headers(conn))
|> transform(:accounts)
end
@ -174,9 +174,9 @@ defmodule Hunter.Api.HTTPClient do
|> transform(:status)
end
def reblogged_by(conn, id) do
def reblogged_by(conn, id, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/statuses/#{id}/reblogged_by"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/statuses/#{id}/reblogged_by"), options, get_headers(conn))
|> transform(:accounts)
end
@ -192,15 +192,15 @@ defmodule Hunter.Api.HTTPClient do
|> transform(:status)
end
def favourites(conn) do
def favourites(conn, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/favourites"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/favourites"), options, get_headers(conn))
|> transform(:statuses)
end
def favourited_by(conn, id) do
def favourited_by(conn, id, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/statuses/#{id}/favourited_by"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/statuses/#{id}/favourited_by"), options, get_headers(conn))
|> transform(:accounts)
end
@ -234,9 +234,9 @@ defmodule Hunter.Api.HTTPClient do
|> transform(:instance)
end
def notifications(conn) do
def notifications(conn, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/notifications"), [], get_headers(conn))
|> Request.request!(process_url(conn, "/api/v1/notifications"), options, get_headers(conn))
|> transform(:notifications)
end
@ -251,6 +251,12 @@ defmodule Hunter.Api.HTTPClient do
true
end
def clear_notification(conn, id) do
Request.request!(:post, process_url(conn, "/api/v1/notifications/dismiss/#{id}"), [], get_headers(conn))
true
end
def reports(conn) do
:get
|> Request.request!(process_url(conn, "/api/v1/reports"), [], get_headers(conn))
@ -298,6 +304,24 @@ defmodule Hunter.Api.HTTPClient do
%Hunter.Client{base_url: base_url, bearer_token: response["access_token"]}
end
def blocked_domains(conn, options) do
:get
|> Request.request!(process_url(conn, "/api/v1/domain_blocks"), options, get_headers(conn))
|> Poison.decode!()
end
def block_domain(conn, domain) do
:post
|> Request.request!(process_url(conn, "/api/v1/domain_blocks"), %{domain: domain})
|> Poison.decode!()
end
def unblock_domain(conn, domain) do
:delete
|> Request.request!(process_url(conn, "/api/v1/domain_blocks"), %{domain: domain})
|> Poison.decode!()
end
## Helpers
defp get_headers(%Hunter.Client{bearer_token: token}) do
["Authorization": "Bearer #{token}"]

View File

@ -28,8 +28,8 @@ defmodule Hunter.Application do
## Parameters
* `name` - name of your application
* `redirect_uri` - where the user should be redirected after authorization,
* `client_name` - name of your application
* `redirect_uris` - where the user should be redirected after authorization,
default: `urn:ietf:wg:oauth:2.0:oob` (no redirect)
* `scopes` - scope list, see the scope section for more details,
default: `read`
@ -61,13 +61,13 @@ defmodule Hunter.Application do
"""
@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
def create_app(client_name, redirect_uris \\ "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, Hunter.Config.api_base_url())
app = @hunter_api.create_app(name, redirect_uri, scopes, website, base_url)
app = @hunter_api.create_app(client_name, redirect_uris, scopes, website, base_url)
if save?, do: save_credentials(name, app)
if save?, do: save_credentials(client_name, app)
app
end

View File

@ -13,6 +13,7 @@ defmodule Hunter.Attachment do
* `remote_url` - For remote images, the remote URL of the original image
* `preview_url` - URL of the preview image
* `text_url` - Shorter URL for the image, for insertion into text (only present on local images)
* `meta` - Specifies `width`, `height`, `size` (width x height), `aspect`
"""
@hunter_api Hunter.Config.hunter_api()
@ -23,11 +24,12 @@ defmodule Hunter.Attachment do
url: String.t,
remote_url: String.t,
preview_url: String.t,
text_url: String.t
text_url: String.t,
meta: String.t
}
@derive [Poison.Encoder]
defstruct [:id, :type, :url, :remote_url, :preview_url, :text_url]
defstruct [:id, :type, :url, :remote_url, :preview_url, :text_url, :meta]
@doc """
Upload a media attachment

View File

@ -11,6 +11,14 @@ defmodule Hunter.Card do
* `title` - The title of the card
* `description` - The card description
* `image` - The image associated with the card, if any
* `type` - `link`, `photo`, `video`, or `rich`
* `author_name` - name of the author/owner of the resource
* `author_url` - URL for the author/owner of the resource
* `provider_name` - name of the resource provider
* `provider_url` - url of the resource provider
* `html` - HTML required to display the resource
* `width` - width in pixels
* `height` - height in pixels
"""
@hunter_api Hunter.Config.hunter_api()
@ -19,11 +27,20 @@ defmodule Hunter.Card do
url: String.t,
title: String.t,
description: String.t,
image: String.t
image: String.t,
type: String.t,
author_name: String.t,
author_url: String.t,
provider_name: String.t,
provider_url: String.t,
html: String.t,
width: non_neg_integer,
height: non_neg_integer
}
@derive [Poison.Encoder]
defstruct [:url, :title, :description, :image]
defstruct [:url, :title, :description, :image, :type, :author_name, :author_url, :provider_name, :provider_url,
:html, :width, :height]
@doc """
Retrieve a card associated with a status

55
lib/hunter/domain.ex Normal file
View File

@ -0,0 +1,55 @@
defmodule Hunter.Domain do
@moduledoc """
Domain blocks
"""
@hunter_api Hunter.Config.hunter_api()
@doc """
Fetch user's blocked domains
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of blocks with id less than or equal this value
* `since_id` - get a list of blocks with id greater than this value
* `limit` - maximum number of blocks to get, default: 40, max: 80
"""
@spec blocked_domains(Hunter.Client.t, Keyword.t) :: list
def blocked_domains(conn, options \\ []) do
@hunter_api.blocked_domains(conn, options)
end
@doc """
Block a domain
## Parameters
* `conn` - connection credentials
* `domain` - domain to block
"""
@spec block_domain(Hunter.Client.t, String.t) :: boolean
def block_domain(conn, domain) do
@hunter_api.block_domain(conn, domain)
end
@doc """
Unblock a domain
## Parameters
* `conn` - connection credentials
* `domain` - domain to unblock
"""
@spec unblock_domain(Hunter.Client.t, String.t) :: boolean
def unblock_domain(conn, domain) do
@hunter_api.unblock_domain(conn, domain)
end
end

View File

@ -11,6 +11,7 @@ defmodule Hunter.Instance do
* `title` - The instance's title
* `description` - A description for the instance
* `email` - An email address which can be used to contact the instance administrator
* `version` - The Mastodon version used by instance.
"""
@hunter_api Hunter.Config.hunter_api()
@ -19,11 +20,12 @@ defmodule Hunter.Instance do
uri: String.t,
title: String.t,
description: String.t,
email: String.t
email: String.t,
version: String.t
}
@derive [Poison.Encoder]
defstruct [:uri, :title, :description, :email]
defstruct [:uri, :title, :description, :email, :version]
@doc """
Retrieve instance information

View File

@ -33,6 +33,13 @@ defmodule Hunter.Notification do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of notifications with id less than or equal this value
* `since_id` - get a list of notifications with id greater than this value
* `limit` - maximum number of notifications to get, default: 15, max: 30
## Examples
@ -40,9 +47,9 @@ defmodule Hunter.Notification do
#=> [%Hunter.Notification{account: %{"acct" => "paperswelove@mstdn.io", ...}]
"""
@spec notifications(Hunter.Client.t) :: [Hunter.Notification.t]
def notifications(conn) do
@hunter_api.notifications(conn)
@spec notifications(Hunter.Client.t, Keyword.t) :: [Hunter.Notification.t]
def notifications(conn, options \\ []) do
@hunter_api.notifications(conn, options)
end
@doc """
@ -76,4 +83,18 @@ defmodule Hunter.Notification do
def clear_notifications(conn) do
@hunter_api.clear_notifications(conn)
end
@doc """
Dismiss a single notification
## Parameters
* `conn` - connection credentials
* `id` - notification id
"""
@spec clear_notification(Hunter.Client.t, non_neg_integer) :: boolean
def clear_notification(conn, id) do
@hunter_api.clear_notification(conn, id)
end
end

View File

@ -7,25 +7,29 @@ defmodule Hunter.Relationship do
## Fields
* `following` - Whether the user is currently following the account
* `followed_by` - Whether the user is currently being followed by the account
* `blocking` - Whether the user is currently blocking the account
* `muting` - Whether the user is currently muting the account
* `requested` - Whether the user has requested to follow the account
* `id` - target account id
* `following` - whether the user is currently following the account
* `followed_by` - whether the user is currently being followed by the account
* `blocking` - whether the user is currently blocking the account
* `muting` - whether the user is currently muting the account
* `requested` - whether the user has requested to follow the account
* `domain_blocking` - whether the user is currently blocking the user's domain
"""
@hunter_api Hunter.Config.hunter_api()
@type t :: %__MODULE__{
id: non_neg_integer,
following: boolean,
followed_by: boolean,
blocking: boolean,
muting: boolean,
requested: boolean
requested: boolean,
domain_blocking: boolean
}
@derive [Poison.Encoder]
defstruct [:following, :followed_by, :blocking, :muting, :requested]
defstruct [:id, :following, :followed_by, :blocking, :muting, :requested, :domain_blocking]
@doc """
Get the relationships of authenticated user towards given other users

View File

@ -7,8 +7,8 @@ defmodule Hunter.Report do
## Fields
* `id` - The ID of the report
* `action_taken` - The action taken in response to the report
* `id` - id of the report
* `action_taken` - action taken in response to the report
"""
@hunter_api Hunter.Config.hunter_api()

View File

@ -28,7 +28,9 @@ defmodule Hunter.Result do
## Parameters
* `conn` - Connection credentials
* `q` - the search query
* `q` - the search query, if `q` is a URL Mastodon will attempt to fetch
the provided account or status, it will do a local account and hashtag
search
* `options` - option list
## Options

View File

@ -24,6 +24,7 @@ defmodule Hunter.Status do
* `mentions` - list of `Hunter.Mention`
* `tags` - list of `Hunter.Tag`
* `application` - `Hunter.Application` from which the status was posted
* `language` - detected language for the status, default: en
"""
@hunter_api Hunter.Config.hunter_api()
@ -46,7 +47,8 @@ defmodule Hunter.Status do
media_attachments: [Hunter.Attachment.t],
mentions: [Hunter.Mention.t],
tags: [Hunter.Tag.t],
application: Hunter.Application.t
application: Hunter.Application.t,
language: String.t
}
@type status_id :: non_neg_integer
@ -71,7 +73,8 @@ defmodule Hunter.Status do
:media_attachments,
:mentions,
:tags,
:application]
:application,
:language]
@doc """
Create new status
@ -159,11 +162,18 @@ defmodule Hunter.Status do
* `conn` - connection credentials
* `id` - status identifier
* `options` - option list
## Options
* `max_id` - get a list of *reblogged by* ids less than or equal this value
* `since_id` - get a list of *reblogged by* ids greater than this value
* `limit` - maximum number of *reblogged by* to get, default: 40, max: 80
"""
@spec reblogged_by(Hunter.Client.t, status_id) :: [Hunter.Account.t]
def reblogged_by(conn, id) do
@hunter_api.reblogged_by(conn, id)
@spec reblogged_by(Hunter.Client.t, status_id, Keyword.t) :: [Hunter.Account.t]
def reblogged_by(conn, id, options \\ []) do
@hunter_api.reblogged_by(conn, id, options)
end
@doc """
@ -200,11 +210,18 @@ defmodule Hunter.Status do
## Parameters
* `conn` - connection credentials
* `options` - option list
## Options
* `max_id` - get a list of favourites with id less than or equal this value
* `since_id` - get a list of favourites with id greater than this value
* `limit` - maximum of favourites to get, default: 20, max: 40
"""
@spec favourites(Hunter.Client.t) :: [Hunter.Status.t]
def favourites(conn) do
@hunter_api.favourites(conn)
@spec favourites(Hunter.Client.t, Keyword.t) :: [Hunter.Status.t]
def favourites(conn, options \\ []) do
@hunter_api.favourites(conn, options)
end
@doc """
@ -214,12 +231,19 @@ defmodule Hunter.Status do
* `conn` - connection credentials
* `id` - status identifier
* `options` - option list
## Options
* `max_id` - get a list of *favourited by* ids less than or equal this value
* `since_id` - get a list of *favourited by* ids greater than this value
* `limit` - maximum number of *favourited by* to get, default: 40, max: 80
"""
@spec favourited_by(Hunter.Client.t, status_id) :: [Hunter.Account.t]
def favourited_by(conn, id) do
@hunter_api.favourited_by(conn, id)
@spec favourited_by(Hunter.Client.t, status_id, Keyword.t) :: [Hunter.Account.t]
def favourited_by(conn, id, options \\ []) do
@hunter_api.favourited_by(conn, id, options)
end
@doc """
@ -235,9 +259,9 @@ defmodule Hunter.Status do
* `only_media` - only return `Hunter.Status.t` that have media attachments
* `exclude_replies` - skip statuses that reply to other statuses
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `max_id` - get a list of statuses with id less than or equal this value
* `since_id` - get a list of statuses with id greater than this value
* `limit` - maximum number of statuses to get, default: 20, max: 40
"""
@spec statuses(Hunter.Client.t, status_id, Keyword.t) :: [Hunter.Status.t]
@ -255,9 +279,9 @@ defmodule Hunter.Status do
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec home_timeline(Hunter.Client.t, Keyword.t) :: [Hunter.Status.t]
@ -275,10 +299,10 @@ defmodule Hunter.Status do
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `local` - only return statuses originating from this instance
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec public_timeline(Hunter.Client.t, Keyword.t) :: [Hunter.Status.t]
@ -297,10 +321,10 @@ defmodule Hunter.Status do
## Options
* `max_id` - [Integer]
* `since_id` - [Integer]
* `limit` - [Integer]
* `local` - only return statuses originating from this instance
* `max_id` - get a list of timelines with id less than or equal this value
* `since_id` - get a list of timelines with id greater than this value
* `limit` - maximum number of statuses on the requested timeline to get, default: 20, max: 40
"""
@spec hashtag_timeline(Hunter.Client.t, [String.t], Keyword.t) :: [Hunter.Status.t]

View File

@ -8,30 +8,30 @@ defmodule Hunter.Api.InMemory do
[
%{name: :account, arity: 2, as: %Hunter.Account{}},
%{name: :block, arity: 2, as: %Hunter.Relationship{}},
%{name: :blocks, arity: 1, as: [%Hunter.Account{}]},
%{name: :blocks, arity: 2, as: [%Hunter.Account{}]},
%{name: :card_by_status, arity: 2, as: %Hunter.Card{}},
%{name: :clear_notifications, arity: 1, as: %{}},
%{name: :create_app, arity: 5, as: %Hunter.Application{}},
%{name: :create_status, arity: 3, as: %Hunter.Status{}},
%{name: :favourite, arity: 2, as: %Hunter.Status{}},
%{name: :favourited_by, arity: 2, as: [%Hunter.Account{}]},
%{name: :favourites, arity: 1, as: [%Hunter.Status{}]},
%{name: :favourited_by, arity: 3, as: [%Hunter.Account{}]},
%{name: :favourites, arity: 2, as: [%Hunter.Status{}]},
%{name: :follow, arity: 2, as: %Hunter.Relationship{}},
%{name: :follow_by_uri, arity: 2, as: %Hunter.Account{}},
%{name: :follow_requests, arity: 1, as: [%Hunter.Account{}]},
%{name: :followers, arity: 2, as: [%Hunter.Account{}]},
%{name: :following, arity: 2, as: [%Hunter.Account{}]},
%{name: :follow_requests, arity: 2, as: [%Hunter.Account{}]},
%{name: :followers, arity: 3, as: [%Hunter.Account{}]},
%{name: :following, arity: 3, as: [%Hunter.Account{}]},
%{name: :hashtag_timeline, arity: 3, as: [%Hunter.Status{}]},
%{name: :home_timeline, arity: 2, as: [%Hunter.Status{}]},
%{name: :instance_info, arity: 1, as: %Hunter.Instance{}},
%{name: :log_in, arity: 4, as: %Hunter.Client{}},
%{name: :mute, arity: 2, as: %Hunter.Relationship{}},
%{name: :mutes, arity: 1, as: [%Hunter.Account{}]},
%{name: :mutes, arity: 2, as: [%Hunter.Account{}]},
%{name: :notification, arity: 2, as: %Hunter.Notification{}},
%{name: :notifications, arity: 1, as: [%Hunter.Notification{}]},
%{name: :notifications, arity: 2, as: [%Hunter.Notification{}]},
%{name: :public_timeline, arity: 2, as: [%Hunter.Status{}]},
%{name: :reblog, arity: 2, as: %Hunter.Status{}},
%{name: :reblogged_by, arity: 2, as: [%Hunter.Account{}]},
%{name: :reblogged_by, arity: 3, as: [%Hunter.Account{}]},
%{name: :relationships, arity: 2, as: [%Hunter.Relationship{}]},
%{name: :report, arity: 4, as: %Hunter.Report{}},
%{name: :reports, arity: 1, as: [%Hunter.Report{}]},
@ -65,4 +65,8 @@ defmodule Hunter.Api.InMemory do
def destroy_status(_, _), do: true
def follow_request_action(_, _, _), do: true
def blocked_domains(_, _), do: ["example.com"]
def block_domain(_, _), do: true
def unblock_domain(_, _), do: true
def clear_notification(_, _), do: true
end