Module: Forem::APIOperations::Save
- Included in:
- Forem::Article, Billboard, Organization, Page, RecommendedArticlesList, RequestRedirect
- Defined in:
- lib/forem/api_operations/save.rb
Overview
Adds a save instance method to any resource that includes this module.
save is the instance-level complement to the class-level
Update#update. It persists the current resource to the
API by issuing a PUT request to the instance's own
Forem::APIResource#resource_url, and returns a new resource object reflecting
the server's response.
Instance Method Summary collapse
-
#save(params = {}, **opts) ⇒ ForemObject
Save (update) this resource instance via the Forem API.
Instance Method Details
#save(params = {}, **opts) ⇒ ForemObject
Save (update) this resource instance via the Forem API.
Sends a PUT request to Forem::APIResource#resource_url with params
serialised as a JSON body. The server response is used to construct
and return a new resource instance representing the updated state.
Unlike Forem::APIResource#refresh, which reloads in-place, save returns
a new instance and does not mutate the receiver.
46 47 48 49 50 |
# File 'lib/forem/api_operations/save.rb', line 46 def save(params = {}, **opts) requestor = opts[:requestor] || @requestor resp = request(:put, resource_url, params, opts) self.class.construct_from(resp.parsed_body, requestor: requestor) end |