Module: Forem::APIOperations::Request
- Included in:
- ForemObject
- Defined in:
- lib/forem/api_operations/request.rb
Overview
Provides request as both a class method and an instance method on any
class that includes this module.
Including Request is the only prerequisite for a class to issue authenticated HTTP requests. It is included in Forem::APIResource and therefore inherited by every concrete resource class.
The module uses a self.included hook to also extend the including
class with ClassMethods, making the class-level request available
for module methods such as Create#create and
List#list.
The :requestor key in opts is consumed here and never forwarded to
Forem::APIRequestor#request.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ void
Hook called when Request is included in a class.
Instance Method Summary collapse
-
#request(method, path, params = {}, opts = {}) ⇒ ForemResponse
Issue an authenticated HTTP request on behalf of this resource instance.
Class Method Details
.included(base) ⇒ void
This method returns an undefined value.
Hook called when Forem::APIOperations::Request is included in a class.
22 23 24 |
# File 'lib/forem/api_operations/request.rb', line 22 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#request(method, path, params = {}, opts = {}) ⇒ ForemResponse
Issue an authenticated HTTP request on behalf of this resource instance.
Falls back to the requestor stored on the instance (set when the
object was constructed by a service call) if no explicit
:requestor is supplied in opts. Delegates to the class-level
Forem::APIOperations::Request::ClassMethods#request for the actual transport.
76 77 78 79 80 |
# File 'lib/forem/api_operations/request.rb', line 76 def request(method, path, params = {}, opts = {}) opts = opts.dup opts[:requestor] ||= @requestor if instance_variable_defined?(:@requestor) self.class.request(method, path, params, opts) end |