Method: Chatrix::Matrix#make_request

Defined in:
lib/chatrix/matrix.rb

#make_request(method, path, opts = {}) {|fragment| ... } ⇒ HTTParty::Response

Helper method for performing requests to the homeserver.

Parameters:

  • method (Symbol)

    HTTP request method to use. Use only symbols available as keys in METHODS.

  • path (String)

    The API path to query, relative to the base API path, eg. /login.

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

    Additional request options.

Options Hash (opts):

  • :params (Hash)

    Additional parameters to include in the query string (part of the URL, not put in the request body).

  • :content (Hash, #read)

    Content to put in the request body. If set, must be a Hash or a stream object.

  • :headers (Hash{String => String})

    Additional headers to include in the request.

  • :base (String, nil)

    If this is set, it will be used as the base URI for the request instead of the default (@base_uri).

Yields:

  • (fragment)

    HTTParty will call the block during the request.

Returns:

  • (HTTParty::Response)

    The HTTParty response object.



201
202
203
204
205
206
# File 'lib/chatrix/matrix.rb', line 201

def make_request(method, path, opts = {}, &block)
  path = (opts[:base] || @base_uri) + URI.encode(path)
  options = make_options opts[:params], opts[:content], opts[:headers]

  parse_response METHODS[method].call(path, options, &block)
end