Class: Mastodon::REST::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/mastodon/rest/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, request_method, path, options = {}) ⇒ Request


10
11
12
13
14
15
16
17
18
# File 'lib/mastodon/rest/request.rb', line 10

def initialize(client, request_method, path, options = {})
  @client         = client
  @request_method = request_method
  @uri            = Addressable::URI.parse(@client.base_url + path)
  @headers        = Mastodon::Headers.new(@client).request_headers
  @path           = @uri.path
  @options        = options
  @headers        = @options.delete(:headers).merge @headers if @options.is_a?(Hash) && @options[:headers]
end

Instance Method Details

#performObject


20
21
22
23
24
25
26
27
# File 'lib/mastodon/rest/request.rb', line 20

def perform
  options_key = @request_method == :get ? :params : :form
  response    = http_client.headers(@headers).public_send(@request_method, @uri.to_s, options_key => @options)

  STDERR.puts response.body if ENV['DEBUG'] == 'true'

  fail_or_return(response.code, response.body.empty? ? '' : Oj.load(response.to_s, mode: :null))
end