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

#accept_follow_request(id) ⇒ Boolean

Accept a follow request

Parameters:

  • id (Integer)

Returns:

  • (Boolean)


137
138
139
# File 'lib/mastodon/rest/accounts.rb', line 137

def accept_follow_request(id)
  !perform_request(:post, "/api/v1/follow_requests/#{id}/authorize").nil?
end

#account(id) ⇒ Mastodon::Account

Retrieve account

Parameters:

  • id (Integer)

Returns:



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

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

#add_endorsement(id) ⇒ Mastodon::Relationship

Add an endorsement

Parameters:

  • id (Integer)

Returns:



89
90
91
92
# File 'lib/mastodon/rest/accounts.rb', line 89

def add_endorsement(id)
  perform_request_with_object(:post, "/api/v1/accounts/#{id}/pin",
                              {}, Mastodon::Relationship)
end

#blocks(options = {}) ⇒ Mastodon::Collection<Mastodon::Account>

Get user blocks

Parameters:

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

Options Hash (options):

  • :limit (Integer)

Returns:



112
113
114
115
# File 'lib/mastodon/rest/accounts.rb', line 112

def blocks(options = {})
  perform_request_with_collection(:get, '/api/v1/blocks',
                                  options, Mastodon::Account)
end

#endorsementsMastodon::Collection<Mastodon::Account>

Get account endorsements



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

def endorsements
  perform_request_with_collection(:get, '/api/v1/endorsements',
                                  {}, Mastodon::Account)
end

#follow_by_uri(uri) ⇒ Mastodon::Account

Follow a remote user

Parameters:

  • uri (String)

    The URI of the remote user, in the format of username@domain

Returns:



72
73
74
75
76
# File 'lib/mastodon/rest/accounts.rb', line 72

def follow_by_uri(uri)
  perform_request_with_object(:post,
                              '/api/v1/follows', { uri: uri },
                              Mastodon::Account)
end

#follow_requests(options = {}) ⇒ Mastodon::Collection<Mastodon::Account>

Gets follow requests

Parameters:

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

Options Hash (options):

  • :limit (Integer)

Returns:



129
130
131
132
# File 'lib/mastodon/rest/accounts.rb', line 129

def follow_requests(options = {})
  perform_request_with_collection(:get, '/api/v1/follow_requests',
                                  options, Mastodon::Account)
end

#followers(id) ⇒ Mastodon::Collection<Mastodon::Account>

Get a list of followers

Parameters:

  • id (Integer)

Returns:



53
54
55
56
57
# File 'lib/mastodon/rest/accounts.rb', line 53

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

#following(id) ⇒ Mastodon::Collection<Mastodon::Account>

Get a list of followed accounts

Parameters:

  • id (Integer)

Returns:



62
63
64
65
66
# File 'lib/mastodon/rest/accounts.rb', line 62

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

#mutesMastodon::Collection<Mastodon::Account>

Get user mutes



103
104
105
106
# File 'lib/mastodon/rest/accounts.rb', line 103

def mutes
  perform_request_with_collection(:get, '/api/v1/mutes',
                                  {}, Mastodon::Account)
end

#reject_follow_request(id) ⇒ Boolean

Reject follow request

Parameters:

  • id (Integer)

Returns:

  • (Boolean)


144
145
146
# File 'lib/mastodon/rest/accounts.rb', line 144

def reject_follow_request(id)
  !perform_request(:post, "/api/v1/follow_requests/#{id}/reject").nil?
end

#remove_endorsement(id) ⇒ Mastodon::Relationship

Remove an endorsement

Parameters:

  • id (Integer)

Returns:



97
98
99
100
# File 'lib/mastodon/rest/accounts.rb', line 97

def remove_endorsement(id)
  perform_request_with_object(:post, "/api/v1/accounts/#{id}/unpin",
                              {}, Mastodon::Relationship)
end

#report(id, options = {}) ⇒ Object

Report an account

Parameters:

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

Options Hash (options):

  • :status_ids (Array<Integer>)
  • :comment (String)


121
122
123
124
# File 'lib/mastodon/rest/accounts.rb', line 121

def report(id, options = {})
  options[:account_id] = id
  !perform_request(:post, '/api/v1/reports', options).nil?
end

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

Returns:



32
33
34
35
36
37
38
39
40
# File 'lib/mastodon/rest/accounts.rb', line 32

def update_credentials(opts = {})
  opts[:fields] and opts.delete(:fields).each_with_index { |f, i|
    opts["fields_attributes[#{i}][name]"] = f[:name]
    opts["fields_attributes[#{i}][value]"] = f[:value]
  }
  perform_request_with_object(:patch,
                              '/api/v1/accounts/update_credentials',
                              opts, Mastodon::Account)
end

#verify_credentialsMastodon::Account

Retrieve account of authenticated user

Returns:



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

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