-
Notifications
You must be signed in to change notification settings - Fork 8
/
account.ex
360 lines (274 loc) · 10.2 KB
/
account.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
defmodule Hunter.Account do
@moduledoc """
Account entity
This module defines a `Hunter.Account` struct and the main functions
for working with Accounts.
## Fields
* `id` - the id of the account
* `username` - the username of the account
* `acct` - equals `username` for local users, includes `@domain` for remote ones
* `display_name` - the account's display name
* `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
* `following_count` - the number of accounts the given account is following
* `statuses_count` - the number of statuses the account has made
* `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)
* `emojis` - list of emojis
* `moved` - moved from account
* `bot` - whether this account is a bot or not
"""
alias Hunter.Config
@type t :: %__MODULE__{
id: non_neg_integer,
username: String.t(),
acct: String.t(),
display_name: String.t(),
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,
following_count: non_neg_integer,
statuses_count: non_neg_integer,
emojis: [Hunter.Emoji.t()],
moved: t(),
fields: [any()],
bot: boolean
}
@derive [Poison.Encoder]
defstruct [
:id,
:username,
:acct,
:display_name,
:note,
:url,
:avatar,
:avatar_static,
:header,
:header_static,
:locked,
:created_at,
:followers_count,
:following_count,
:statuses_count,
:emojis,
:moved,
:fields,
:bot
]
@doc """
Retrieve account of authenticated user
## Parameters
* `conn` - connection credentials
## Examples
iex> conn = Hunter.new([base_url: "https://social.lou.lt", bearer_token: "123456"])
%Hunter.Client{base_url: "https://social.lou.lt", bearer_token: "123456"}
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"}
"""
@spec verify_credentials(Hunter.Client.t()) :: Hunter.Account.t()
def verify_credentials(conn) do
Config.hunter_api().verify_credentials(conn)
end
@doc """
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...`)
"""
@spec update_credentials(Hunter.Client.t(), map) :: Hunter.Account.t()
def update_credentials(conn, data) do
Config.hunter_api().update_credentials(conn, data)
end
@doc """
Retrieve account
## Parameters
* `conn` - connection credentials
* `id` - account id
"""
@spec account(Hunter.Client.t(), non_neg_integer) :: Hunter.Account.t()
def account(conn, id) do
Config.hunter_api().account(conn, id)
end
@doc """
Get a list of followers
## Parameters
* `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
**Note:** `max_id` and `since_id` for next and previous pages are provided in
the `Link` header. It is **not** possible to use the `id` of the returned
objects to construct your own URLs, because the results are sorted by an
internal key.
"""
@spec followers(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Account.t()]
def followers(conn, id, options \\ []) do
Config.hunter_api().followers(conn, id, options)
end
@doc """
Get a list of followed accounts
## Parameters
* `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
**Note:** `max_id` and `since_id` for next and previous pages are provided in
the `Link` header. It is **not** possible to use the `id` of the returned
objects to construct your own URLs, because the results are sorted by an
internal key.
"""
@spec following(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Account.t()]
def following(conn, id, options \\ []) do
Config.hunter_api().following(conn, id, options)
end
@doc """
Follow a remote user
## Parameters
* `conn` - connection credentials
* `uri` - URI of the remote user, in the format of `username@domain`
"""
@spec follow_by_uri(Hunter.Client.t(), String.t()) :: Hunter.Account.t()
def follow_by_uri(conn, uri) do
Config.hunter_api().follow_by_uri(conn, uri)
end
@doc """
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
"""
@spec search_account(Hunter.Client.t(), Keyword.t()) :: [Hunter.Account.t()]
def search_account(conn, options) do
opts = %{
q: Keyword.fetch!(options, :q),
limit: Keyword.get(options, :limit, 40)
}
Config.hunter_api().search_account(conn, opts)
end
@doc """
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
"""
@spec blocks(Hunter.Client.t(), Keyword.t()) :: [Hunter.Account.t()]
def blocks(conn, options \\ []) do
Config.hunter_api().blocks(conn, options)
end
@doc """
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
"""
@spec follow_requests(Hunter.Client.t(), Keyword.t()) :: [Hunter.Account.t()]
def follow_requests(conn, options \\ []) do
Config.hunter_api().follow_requests(conn, options)
end
@doc """
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
"""
@spec mutes(Hunter.Client.t(), Keyword.t()) :: [Hunter.Account.t()]
def mutes(conn, options \\ []) do
Config.hunter_api().mutes(conn, options)
end
@doc """
Accepts a follow request
## Parameters
* `conn` - connection credentials
* `id` - follow request id
"""
@spec accept_follow_request(Hunter.Client.t(), non_neg_integer) :: boolean
def accept_follow_request(conn, id) do
Config.hunter_api().follow_request_action(conn, id, :authorize)
end
@doc """
Rejects a follow request
## Parameters
* `conn` - connection credentials
* `id` - follow request id
"""
@spec reject_follow_request(Hunter.Client.t(), non_neg_integer) :: boolean
def reject_follow_request(conn, id) do
Config.hunter_api().follow_request_action(conn, id, :reject)
end
@doc """
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
"""
@spec reblogged_by(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Account.t()]
def reblogged_by(conn, id, options \\ []) do
Config.hunter_api().reblogged_by(conn, id, options)
end
@doc """
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
"""
@spec favourited_by(Hunter.Client.t(), non_neg_integer, Keyword.t()) :: [Hunter.Account.t()]
def favourited_by(conn, id, options \\ []) do
Config.hunter_api().favourited_by(conn, id, options)
end
end