Module: Forem::APIOperations::Request::ClassMethods

Defined in:
lib/forem/api_operations/request.rb

Overview

Class-level request helpers mixed into every class that includes Forem::APIOperations::Request.

Instance Method Summary collapse

Instance Method Details

#request(method, path, params = {}, opts = {}) ⇒ ForemResponse

Issue an authenticated HTTP request using the supplied requestor.

The :requestor key in opts is required — there is no global default. In normal use this is supplied automatically by a Client via its service objects.

Parameters:

  • method (Symbol)

    the HTTP verb (+:get+, :post, :put, :delete).

  • path (String)

    the API path (e.g. "/api/articles").

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

    query parameters or JSON body payload.

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

    per-request options.

Options Hash (opts):

  • :requestor (APIRequestor) — default: required

    the requestor that issues this call. Normally injected by a Client.

  • :api_key (String)

    override the API key for this request.

  • :api_base (String)

    override the base URL for this request.

Returns:

Raises:

  • (ArgumentError)

    if no :requestor is supplied.

  • (ForemError)

    on any API or network error.



47
48
49
50
51
52
53
54
55
# File 'lib/forem/api_operations/request.rb', line 47

def request(method, path, params = {}, opts = {})
  requestor = opts.delete(:requestor)
  unless requestor
    raise ArgumentError,
          "Forem requires an explicit requestor — call this method " \
          "through a Forem::Client (e.g. client.articles.list)."
  end
  requestor.request(method, path, params, opts)
end