Module: Mastodon::REST::Accounts

Includes:
Utils
Included in:
API
Defined in:
lib/mastodon/rest/accounts.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(id) ⇒ Mastodon::Account

Retrieve account

Parameters:

  • id (Integer)

Returns:


35
36
37
# File 'lib/mastodon/rest/accounts.rb', line 35

def (id)
  perform_request_with_object(:get, "/api/v1/accounts/#{id}", {}, Mastodon::Account)
end

#create_account(params = {}) ⇒ Mastodon::AccessToken

Sign up (requires authentication with client credentials)

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :username (String)
  • :email (String)
  • :password (String)
  • :agreement (Boolean)
  • :locale (String)

Returns:


71
72
73
# File 'lib/mastodon/rest/accounts.rb', line 71

def (params = {})
  perform_request_with_object(:post, '/api/v1/accounts', params, Mastodon::AccessToken)
end

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

Get a list of followers

Parameters:

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

Options Hash (options):

  • :max_id (Integer)
  • :since_id (Integer)
  • :min_id (Integer)
  • :limit (Integer)

Returns:


47
48
49
# File 'lib/mastodon/rest/accounts.rb', line 47

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

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

Get a list of followed accounts

Parameters:

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

Options Hash (options):

  • :max_id (Integer)
  • :since_id (Integer)
  • :min_id (Integer)
  • :limit (Integer)

Returns:


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

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

#search_accounts(query, params = {}) ⇒ Mastodon::Collection<Mastodon::Account>

Search accounts

Parameters:

  • query (String)
  • params (Hash) (defaults to: {})

Options Hash (params):

  • :limit (Integer)
  • :resolve (Boolean)

    Whether to attempt resolving unknown remote accounts

  • :following (Boolean)

    Only return matches the authenticated user follows

Returns:


82
83
84
# File 'lib/mastodon/rest/accounts.rb', line 82

def search_accounts(query, params = {})
  perform_request_with_collection(:get, '/api/v1/accounts/search', { q: query }.merge(params), Mastodon::Account)
end

#update_credentials(params = {}) ⇒ Mastodon::Account

Update authenticated account attributes

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :display_name (String)

    The name to display in the user's profile

  • :note (String)

    A new biography for the user

  • :avatar (File, StringIO, HTTP::FormData::File)
  • :header (File, StringIO, HTTP::FormData::File)

Returns:


23
24
25
26
27
28
29
30
# File 'lib/mastodon/rest/accounts.rb', line 23

def update_credentials(params = {})
  %i(avatar header).each do |key|
    next unless params.key?(key)
    params[key] = params[key].is_a?(HTTP::FormData::File) ? params[key] : HTTP::FormData::File.new(params[key])
  end

  perform_request_with_object(:patch, '/api/v1/accounts/update_credentials', params, Mastodon::Account)
end

#verify_credentialsMastodon::Account

Retrieve account of authenticated user

Returns:


12
13
14
# File 'lib/mastodon/rest/accounts.rb', line 12

def verify_credentials
  perform_request_with_object(:get, '/api/v1/accounts/verify_credentials', {}, Mastodon::Account)
end