hunter/lib/hunter/notification.ex

101 lines
2.6 KiB
Elixir
Raw Permalink Normal View History

2017-04-08 01:30:17 -04:00
defmodule Hunter.Notification do
@moduledoc """
Notification entity
This module defines a `Hunter.Notification` struct and the main functions
for working with Notifications.
## Fields
* `id` - The notification ID
* `type` - One of: "mention", "reblog", "favourite", "follow"
* `created_at` - The time the notification was created
* `account` - The `Hunter.Account` sending the notification to the user
* `status` - The `Hunter.Status` associated with the notification, if applicable
"""
2019-03-19 13:18:34 -04:00
alias Hunter.Config
2017-04-10 22:44:58 -04:00
2017-04-08 01:30:17 -04:00
@type t :: %__MODULE__{
2017-10-26 15:16:42 -04:00
id: String.t(),
type: String.t(),
created_at: String.t(),
account: Hunter.Account.t(),
status: Hunter.Status.t()
}
2017-04-08 01:30:17 -04:00
@derive [Poison.Encoder]
defstruct [:id, :type, :created_at, :account, :status]
2017-04-10 22:44:58 -04:00
@doc """
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
2017-04-10 22:44:58 -04:00
2017-04-28 16:17:21 -04:00
## Examples
Hunter.Notification.notifications(conn)
#=> [%Hunter.Notification{account: %{"acct" => "paperswelove@mstdn.io", ...}]
2017-04-10 22:44:58 -04:00
"""
2017-10-26 15:16:42 -04:00
@spec notifications(Hunter.Client.t(), Keyword.t()) :: [Hunter.Notification.t()]
def notifications(conn, options \\ []) do
2019-03-19 13:18:34 -04:00
Config.hunter_api().notifications(conn, options)
2017-04-10 22:44:58 -04:00
end
@doc """
Retrieve single notification
## Parameters
* `conn` - connection credentials
* `id` - notification identifier
2017-04-28 16:17:21 -04:00
## Examples
Hunter.Notification.notification(conn, 17_476)
#=> %Hunter.Notification{account: %{"acct" => "paperswelove@mstdn.io", ...}
2017-04-10 22:44:58 -04:00
"""
2017-10-26 15:16:42 -04:00
@spec notification(Hunter.Client.t(), non_neg_integer) :: Hunter.Notification.t()
2017-04-10 22:44:58 -04:00
def notification(conn, id) do
2019-03-19 13:18:34 -04:00
Config.hunter_api().notification(conn, id)
2017-04-10 22:44:58 -04:00
end
@doc """
Deletes all notifications from the Mastodon server for the authenticated user
## Parameters
* `conn` - connection credentials
"""
2017-10-26 15:16:42 -04:00
@spec clear_notifications(Hunter.Client.t()) :: boolean
2017-04-10 22:44:58 -04:00
def clear_notifications(conn) do
2019-03-19 13:18:34 -04:00
Config.hunter_api().clear_notifications(conn)
2017-04-10 22:44:58 -04:00
end
@doc """
Dismiss a single notification
## Parameters
* `conn` - connection credentials
* `id` - notification id
"""
2017-10-26 15:16:42 -04:00
@spec clear_notification(Hunter.Client.t(), non_neg_integer) :: boolean
def clear_notification(conn, id) do
2019-03-19 13:18:34 -04:00
Config.hunter_api().clear_notification(conn, id)
end
2017-04-08 01:30:17 -04:00
end