Module: Mastodon::REST::Utils

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)


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

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: {})


9
10
11
# File 'lib/mastodon/rest/utils.rb', line 9

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)


26
27
28
29
# File 'lib/mastodon/rest/utils.rb', line 26

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)


17
18
19
20
# File 'lib/mastodon/rest/utils.rb', line 17

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