Module: Mastodon::REST::Lists

Includes:
Utils
Included in:
API
Defined in:
lib/mastodon/rest/lists.rb

Instance Method Summary collapse

Methods included from Utils

#array_param, #perform_request, #perform_request_with_collection, #perform_request_with_object

Instance Method Details

#account_lists(id) ⇒ Mastodon::Collection<Mastodon::List>

Gets the lists this account is a part of

Parameters:

  • id (Integer)

Returns:



59
60
61
62
# File 'lib/mastodon/rest/lists.rb', line 59

def (id)
  perform_request_with_collection(:get, "/api/v1/accounts/#{id}/lists",
                                  {}, Mastodon::List)
end

#create_list(title) ⇒ Mastodon::List

Create a new list

Parameters:

  • title (String)

Returns:



30
31
32
33
34
# File 'lib/mastodon/rest/lists.rb', line 30

def create_list(title)
  options = { title: title }
  perform_request_with_object(:post, '/api/v1/lists',
                              options, Mastodon::List)
end

#delete_list(id) ⇒ Boolean

Delete a list

Parameters:

  • id (Integer)

Returns:

  • (Boolean)


67
68
69
# File 'lib/mastodon/rest/lists.rb', line 67

def delete_list(id)
  !perform_request(:delete, "/api/v1/lists/#{id}").nil?
end

#list(id) ⇒ Mastodon::List

Retrieve list

Parameters:

  • id (Integer)

Returns:



14
15
16
17
# File 'lib/mastodon/rest/lists.rb', line 14

def list(id)
  perform_request_with_object(:get, "/api/v1/lists/#{id}",
                              {}, Mastodon::List)
end

#list_accounts(id, options = {}) ⇒ Mastodon::Collection<Mastodon::Account>

Gets the accounts that are in a list

Parameters:

  • id (Integer)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :limit (Integer)

Returns:



51
52
53
54
# File 'lib/mastodon/rest/lists.rb', line 51

def list_accounts(id, options = {})
  perform_request_with_collection(:get, "/api/v1/lists/#{id}/accounts",
                                  options, Mastodon::List)
end

#list_add_accounts(id, *accounts) ⇒ Object

Add accounts to a list

Parameters:

  • id (Integer)
  • accounts (Array<Integer>)


74
75
76
77
78
79
# File 'lib/mastodon/rest/lists.rb', line 74

def list_add_accounts(id, *accounts)
  options = {}
  options['account_ids[]'] = accounts
  perform_request(:post, "/api/v1/lists/#{id}/accounts",
                  options)
end

#list_remove_accounts(id, *accounts) ⇒ Object

Add accounts to a list

Parameters:

  • id (Integer)
  • accounts (Array<Integer>)


84
85
86
87
88
89
# File 'lib/mastodon/rest/lists.rb', line 84

def list_remove_accounts(id, *accounts)
  options = {}
  options['account_ids[]'] = accounts
  perform_request(:delete, "/api/v1/lists/#{id}/accounts",
                  options)
end

#listsMastodon::Collections<Mastodon::List>

Retrieve all lists

Parameters:

  • id (Integer)

Returns:



22
23
24
25
# File 'lib/mastodon/rest/lists.rb', line 22

def lists
  perform_request_with_collection(:get, '/api/v1/lists',
                                  {}, Mastodon::List)
end

#update_list(id, options = {}) ⇒ Mastodon::List

Update a list

Parameters:

  • id (Integer)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :title (String)

Returns:



41
42
43
44
# File 'lib/mastodon/rest/lists.rb', line 41

def update_list(id, options = {})
  perform_request_with_object(:put, "/api/v1/lists/#{id}",
                              options, Mastodon::List)
end