Class: Forem::Reaction
- Inherits:
-
APIResource
- Object
- ForemObject
- APIResource
- Forem::Reaction
- Extended by:
- APIOperations::Create
- Defined in:
- lib/forem/resources/reaction.rb
Overview
Represents a reaction (like, unicorn, exploding head, etc.) on a Forem article or comment.
Toggle user's reaction to a reactable (Article, Comment, or User). First call creates the reaction; second call removes it.
Reactions are emoji-style responses that authenticated users can add to articles or comments. The create endpoint adds a reaction, and the toggle endpoint adds it if it does not exist or removes it if it already does.
Available operations (via mixins):
- +Create+ — POST /api/reactions
Constant Summary collapse
- OBJECT_NAME =
"reaction"- RESOURCE_PATH =
"/api/reactions"
Instance Attribute Summary
Attributes inherited from ForemObject
Class Method Summary collapse
-
.toggle(params = {}, opts = {}) ⇒ Forem::Reaction
Toggle a reaction on a reactable object.
Methods included from APIOperations::Create
Methods inherited from APIResource
#refresh, resource_path, #resource_url
Methods inherited from ForemObject
#==, #[], #[]=, construct_from, cursor_list, #initialize, #inspect, #method_missing, paginated_list, #respond_to_missing?, #to_hash
Methods included from APIOperations::Request
Constructor Details
This class inherits a constructor from Forem::ForemObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Forem::ForemObject
Class Method Details
.toggle(params = {}, opts = {}) ⇒ Forem::Reaction
Toggle a reaction on a reactable object.
If the authenticated user has not yet reacted with the given category,
the reaction is created. If they have already reacted, it is removed.
Sends a POST request to /api/reactions/toggle.
56 57 58 59 |
# File 'lib/forem/resources/reaction.rb', line 56 def self.toggle(params = {}, opts = {}) resp = request(:post, "/api/reactions/toggle", params, opts) construct_from(resp.parsed_body) end |