Module: Mastodon::REST::Utils

Included in:
Accounts, Apps, Filters, Instances, Lists, Media, Notifications, Relationships, Search, Statuses, Suggestions, Timelines
Defined in:
lib/mastodon/rest/utils.rb

Instance Method Summary collapse

Instance Method Details

#array_param(key, values) ⇒ Array

Format an array of values into a query param

Parameters:

  • key (Symbol)
  • values (Enumerable)

Returns:

  • (Array)


37
38
39
# File 'lib/mastodon/rest/utils.rb', line 37

def array_param(key, values)
  values.map.with_index { |value, _i| ["#{key}[]", value] }
end

#perform_request(request_method, path, options = {}) ⇒ Object

Parameters:

  • request_method (Symbol)
  • path (String)
  • options (Hash) (defaults to: {})


11
12
13
# File 'lib/mastodon/rest/utils.rb', line 11

def perform_request(request_method, path, options = {})
  Mastodon::REST::Request.new(self, request_method, path, options).perform
end

#perform_request_with_collection(request_method, path, options, klass) ⇒ Object

Parameters:

  • request_method (Symbol)
  • path (String)
  • options (Hash)
  • klass (Class)


28
29
30
31
# File 'lib/mastodon/rest/utils.rb', line 28

def perform_request_with_collection(request_method, path, options, klass)
  response = perform_request(request_method, path, options)
  Mastodon::Collection.new(response, klass)
end

#perform_request_with_object(request_method, path, options, klass) ⇒ Object

Parameters:

  • request_method (Symbol)
  • path (String)
  • options (Hash)
  • klass (Class)


19
20
21
22
# File 'lib/mastodon/rest/utils.rb', line 19

def perform_request_with_object(request_method, path, options, klass)
  response = perform_request(request_method, path, options)
  klass.new(response)
end