Module: Forem::APIOperations::Create
- Included in:
- Forem::AdminUser, Forem::AgentSession, Forem::Article, Billboard, Organization, Page, Reaction, RecommendedArticlesList, RequestRedirect, Segment
- Defined in:
- lib/forem/api_operations/create.rb
Overview
Adds a create class method to any resource that extends this module.
Sends a POST request to the resource's collection path with the supplied parameters as a JSON body, and returns a new resource instance populated from the API response.
Instance Method Summary collapse
-
#create(params = {}, opts = {}) ⇒ ForemObject
Create a new resource via the Forem API.
Instance Method Details
#create(params = {}, opts = {}) ⇒ ForemObject
Create a new resource via the Forem API.
Sends a POST request to Forem::APIResource.resource_path with params
serialised as a JSON body. The server response is used to construct
and return a new resource instance.
40 41 42 43 44 |
# File 'lib/forem/api_operations/create.rb', line 40 def create(params = {}, opts = {}) requestor = opts[:requestor] resp = request(:post, resource_path, params, opts) construct_from(resp.parsed_body, requestor: requestor) end |