Hunter.Api behaviour (hunter v0.6.0)

Copy Markdown View Source

Hunter API contract

Summary

Callbacks

Retrieve account

Block a user

Fetch user's blocked domains

Retrieve user's blocks

Dismiss a single notification

Deletes all notifications from the Mastodon server for the authenticated user

Register a new OAuth client app on the target instance

Destroy status

Favorite a status

Fetch the list of users who favourited the status.

Fetch a user's favourites

Follow a user

Accepts or Rejects a follow request

Retrieve a list of follow requests

Get a list of followers

Get a list of followed accounts

Retrieve statuses from a hashtag

Retrieve statuses from the home timeline

Retrieve instance information

Retrieve access token using OAuth access code

Mute a user

Retrieve user's mutes

Retrieve single notification

Retrieve user's notifications

Retrieve statuses from the public timeline

Reblog a status

Fetch the list of users who reblogged the status.

Get the relationships of authenticated user towards given other users

Search for content

Search for accounts

Retrieve status

Retrieve status context

Get a list of statuses by a user

Unblock a user

Unblock a domain

Undo a favorite of a status

Unfollow a user

Unmute a user

Undo a reblog of a status

Make changes to the authenticated user

Upload a media file

Retrieve account of authenticated user

Callbacks

account(conn, id)

@callback account(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Account.t()

Retrieve account

Parameters

  • conn - connection credentials
  • id - account identifier

block(conn, id)

@callback block(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Relationship.t()

Block a user

Parameters

  • conn - connection credentials
  • id - user identifier

block_domain(conn, domain)

@callback block_domain(conn :: Hunter.Client.t(), domain :: String.t()) :: boolean()

Block a domain

Parameters

  • conn - connection credentials
  • domain - domain to block

blocked_domains(conn, options)

@callback blocked_domains(conn :: Hunter.Client.t(), options :: Keyword.t()) :: list()

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

blocks(conn, options)

@callback blocks(conn :: Hunter.Client.t(), options :: Keyword.t()) :: [
  Hunter.Account.t()
]

Retrieve user's blocks

Parameters

  • 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

clear_notification(conn, id)

@callback clear_notification(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  boolean()

Dismiss a single notification

Parameters

  • conn - connection credentials
  • id - notification id

clear_notifications(conn)

@callback clear_notifications(conn :: Hunter.Client.t()) :: boolean()

Deletes all notifications from the Mastodon server for the authenticated user

Parameters

  • conn - connection credentials

create_app(name, redirect_uri, scopes, website, base_url)

@callback create_app(
  name :: String.t(),
  redirect_uri :: String.t(),
  scopes :: [String.t()],
  website :: nil | String.t(),
  base_url :: String.t()
) :: Hunter.Application.t()

Register a new OAuth client app on the target instance

Parameters

  • name - name of your application
  • redirect_uri - where the user should be redirected after authorization, for no redirect, use urn:ietf:wg:oauth:2.0:oob
  • scopes - scope list, see the scope section for more details
  • website - URL to the homepage of your app
  • base_url - base url

Scopes

  • read - read data
  • write - post statuses and upload media for statuses
  • follow - follow, unfollow, block, unblock

Multiple scopes can be requested during the authorization phase with the scope query param

create_status(conn, status, options)

@callback create_status(
  conn :: Hunter.Client.t(),
  status :: String.t(),
  options :: Keyword.t()
) ::
  Hunter.Status.t() | no_return()

Create new status

Parameters

  • conn - connection credentials
  • status - text of the status
  • options - option list

Options

  • in_reply_to_id - local ID of the status you want to reply to
  • media_ids - list of media IDs to attach to the status (maximum: 4)
  • sensitive - whether the media of the status is NSFW
  • spoiler_text - text to be shown as a warning before the actual content
  • visibility - either direct, private, unlisted or public

destroy_status(conn, id)

@callback destroy_status(conn :: Hunter.Client.t(), id :: non_neg_integer()) :: boolean()

Destroy status

Parameters

  • conn - connection credentials
  • id - status identifier

favourite(conn, id)

@callback favourite(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Status.t()

Favorite a status

Parameters

  • conn - connection credentials
  • id - status identifier

favourited_by(conn, id, options)

@callback favourited_by(
  conn :: Hunter.Client.t(),
  id :: non_neg_integer(),
  options :: Keyword.t()
) :: [Hunter.Account.t()]

Fetch the list of users who favourited the status.

Parameters

  • 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

favourites(conn, options)

@callback favourites(conn :: Hunter.Client.t(), options :: Keyword.t()) :: [
  Hunter.Status.t()
]

Fetch a user's favourites

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

follow(conn, id)

@callback follow(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Relationship.t()

Follow a user

Parameters

  • conn - connection credentials
  • id - user id

follow_request_action(conn, id, action)

@callback follow_request_action(
  conn :: Hunter.Client.t(),
  id :: non_neg_integer(),
  action :: atom()
) :: Hunter.Relationship.t()

Accepts or Rejects a follow request

Parameters

  • conn - connection credentials
  • id - follow request id
  • action - action to take

Actions

  • :authorize - authorize a follow request
  • :reject - reject a follow request

follow_requests(conn, options)

@callback follow_requests(conn :: Hunter.Client.t(), options :: Keyword.t()) :: [
  Hunter.Account.t()
]

Retrieve a list of follow requests

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

followers(conn, id, options)

@callback followers(
  conn :: Hunter.Client.t(),
  id :: non_neg_integer(),
  options :: Keyword.t()
) ::
  Hunter.Account.t()

Get a list of followers

Parameters

  • 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

following(conn, id, options)

@callback following(
  conn :: Hunter.Client.t(),
  id :: non_neg_integer(),
  options :: Keyword.t()
) ::
  Hunter.Account.t()

Get a list of followed accounts

Parameters

  • 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

hashtag_timeline(conn, hashtag, options)

@callback hashtag_timeline(
  conn :: Hunter.Client.t(),
  hashtag :: [String.t()],
  options :: map()
) :: [
  Hunter.Status
]

Retrieve statuses from a hashtag

Parameters

  • conn - connection credentials
  • hashtag - list of strings
  • options - option list

Options

  • 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

home_timeline(conn, options)

@callback home_timeline(conn :: Hunter.Client.t(), options :: map()) :: [
  Hunter.Status.t()
]

Retrieve statuses from the home timeline

Parameters

  • conn - connection credentials
  • options - option list

Options

  • 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

instance_info(conn)

@callback instance_info(conn :: Hunter.Client.t()) :: Hunter.Instance.t()

Retrieve instance information

Parameters

  • conn - connection credentials

log_in(app, username, password, base_url)

@callback log_in(
  app :: Hunter.Application.t(),
  username :: String.t(),
  password :: String.t(),
  base_url :: String.t()
) :: Hunter.Client.t()

Retrieve access token

Parameters

  • app - application details, see: Hunter.Application.create_app/5 for more details.
  • username - your account's email
  • password - your password
  • base_url - API base url, default: https://mastodon.social

log_in_oauth(app, oauth_code, base_url)

@callback log_in_oauth(
  app :: Hunter.Application.t(),
  oauth_code :: String.t(),
  base_url :: String.t()
) :: Hunter.Client.t()

Retrieve access token using OAuth access code

Parameters

  • app - application details, see: Hunter.Application.create_app/5 for more details.
  • oauth_code - oauth authentication code
  • base_url - API base url, default: https://mastodon.social

mute(conn, id)

@callback mute(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Relationship.t()

Mute a user

Parameters

  • conn - connection credentials
  • id - user identifier

mutes(conn, options)

@callback mutes(conn :: Hunter.Client.t(), options :: Keyword.t()) :: [Hunter.Account.t()]

Retrieve user's mutes

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

notification(conn, non_neg_integer)

@callback notification(conn :: Hunter.Client.t(), non_neg_integer()) ::
  Hunter.Notification.t()

Retrieve single notification

Parameters

  • conn - connection credentials
  • id - notification identifier

notifications(conn, options)

@callback notifications(conn :: Hunter.Client.t(), options :: Keyword.t()) :: [
  Hunter.Notification.t()
]

Retrieve user's notifications

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

public_timeline(conn, options)

@callback public_timeline(conn :: Hunter.Client.t(), options :: map()) :: [
  Hunter.Status.t()
]

Retrieve statuses from the public timeline

Parameters

  • conn - connection credentials
  • options - option list

Options

  • 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

reblog(conn, id)

@callback reblog(conn :: Hunter.Client.t(), id :: non_neg_integer()) :: Hunter.Status.t()

Reblog a status

Parameters

  • conn - connection credentials
  • id - status identifier

reblogged_by(conn, id, options)

@callback reblogged_by(
  conn :: Hunter.Client.t(),
  id :: non_neg_integer(),
  options :: Keyword.t()
) :: [
  Hunter.Account.t()
]

Fetch the list of users who reblogged the status.

Parameters

  • 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

relationships(conn, ids)

@callback relationships(conn :: Hunter.Client.t(), ids :: [non_neg_integer()]) :: [
  Hunter.Relationship.t()
]

Get the relationships of authenticated user towards given other users

Parameters

  • conn - connection credentials
  • id - list of relationship IDs

report(conn, account_id, status_ids, comment)

@callback report(
  conn :: Hunter.Client.t(),
  account_id :: non_neg_integer(),
  status_ids :: [non_neg_integer()],
  comment :: String.t()
) :: Hunter.Report.t()

Report a user

Parameters

  • conn - connection credentials
  • account_id - the ID of the account to report
  • status_ids - the IDs of statuses to report
  • comment - a comment to associate with the report

search(conn, query, options)

@callback search(conn :: Hunter.Client.t(), query :: String.t(), options :: Keyword.t()) ::
  Hunter.Result.t()

Search for content

Parameters

  • conn - connection credentials
  • q - the search query
  • options - option list

Options

  • resolve - whether to resolve non-local accounts

search_account(conn, options)

@callback search_account(conn :: Hunter.Client.t(), options :: map()) :: [
  Hunter.Account.t()
]

Search for accounts

Parameters

  • conn - connection credentials
  • options - option list

Options

  • q: what to search for
  • limit: maximum number of matching accounts to return, default: 40

status(conn, id)

@callback status(conn :: Hunter.Client.t(), id :: non_neg_integer()) :: Hunter.Status.t()

Retrieve status

Parameters

  • conn - connection credentials
  • id - status identifier

status_context(conn, id)

@callback status_context(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Context.t()

Retrieve status context

Parameters

  • conn - connection credentials
  • id - status identifier

statuses(conn, account_id, options)

@callback statuses(
  conn :: Hunter.Client.t(),
  account_id :: non_neg_integer(),
  options :: map()
) :: [
  Hunter.Status.t()
]

Get a list of statuses by a user

Parameters

  • conn - connection credentials
  • account_id - account identifier
  • options - option list

Options

  • only_media - only return Hunter.Status.t that have media attachments
  • exclude_replies - skip statuses that reply to other statuses
  • 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

unblock(conn, id)

@callback unblock(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Relationship.t()

Unblock a user

  • conn - connection credentials
  • id - user identifier

unblock_domain(conn, domain)

@callback unblock_domain(conn :: Hunter.Client.t(), domain :: String.t()) :: boolean()

Unblock a domain

Parameters

  • conn - connection credentials
  • domain - domain to unblock

unfavourite(conn, id)

@callback unfavourite(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Status.t()

Undo a favorite of a status

Parameters

  • conn - connection credentials
  • id - status identifier

unfollow(conn, id)

@callback unfollow(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Relationship.t()

Unfollow a user

Parameters

  • conn - connection credentials
  • id - user identifier

unmute(conn, id)

@callback unmute(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Relationship.t()

Unmute a user

Parameters

  • conn - connection credentials
  • id - user identifier

unreblog(conn, id)

@callback unreblog(conn :: Hunter.Client.t(), id :: non_neg_integer()) ::
  Hunter.Status.t()

Undo a reblog of a status

Parameters

  • conn - connection credentials
  • id - status identifier

update_credentials(t, map)

@callback update_credentials(Hunter.Client.t(), map()) :: Hunter.Account.t()

Make changes to the authenticated user

Parameters

  • conn - connection credentials
  • data - data payload

Possible keys for payload

  • display_name - name to display in the user's profile
  • note - new biography for the user
  • avatar - base64 encoded image to display as the user's avatar (e.g. data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAADrCAYAAAA...)
  • header - base64 encoded image to display as the user's header image (e.g. data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUoAAADrCAYAAAA...)

upload_media(conn, file, options)

@callback upload_media(
  conn :: Hunter.Client.t(),
  file :: Path.t(),
  options :: Keyword.t()
) ::
  Hunter.Attachment.t()

Upload a media file

Parameters

  • conn - connection credentials
  • file - media to be uploaded
  • options - option list

Options

  • description - plain-text description of the media for accessibility (max 420 chars)
  • focus - two floating points, comma-delimited.

verify_credentials(conn)

@callback verify_credentials(conn :: Hunter.Client.t()) :: Hunter.Account.t()

Retrieve account of authenticated user

Parameters

  • conn - connection credentials