Class: Forem::Survey
- Inherits:
-
APIResource
- Object
- ForemObject
- APIResource
- Forem::Survey
- Extended by:
- APIOperations::List, APIOperations::Retrieve
- Defined in:
- lib/forem/resources/survey.rb
Overview
Represents a survey published on a Forem instance.
Surveys are structured questionnaires that can be presented to community members. They can be listed or retrieved individually. Survey responses are exposed through two endpoints — #poll_votes for multiple-choice poll selections and #poll_text_responses for free-text answers.
The /api/surveys/{id}/responses endpoint that earlier versions of
this gem hit no longer exists in the Forem API; it was replaced by
those two cursor-paginated endpoints.
Available operations (via mixins):
- +List+ — GET /api/surveys
- +Retrieve+ — GET /api/surveys/:id_or_slug (getSurveyByIdOrSlug)
Survey Fields
id(Integer)title(String)slug(String)survey_type_of(String) — Survey categoryactive(Boolean) — Whether the survey is currently active
Authentication
All survey endpoints require an admin API key.
Constant Summary collapse
- OBJECT_NAME =
"survey"- RESOURCE_PATH =
"/api/surveys"
Instance Attribute Summary
Attributes inherited from ForemObject
Instance Method Summary collapse
-
#poll_text_responses(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::ForemObject>
Return the free-text answers recorded for this survey.
-
#poll_votes(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::ForemObject>
Return the multiple-choice poll selections recorded for this survey.
Methods included from APIOperations::List
Methods included from APIOperations::Retrieve
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
Instance Method Details
#poll_text_responses(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::ForemObject>
Return the free-text answers recorded for this survey.
Sends a GET request to /api/surveys/:id_or_slug/poll_text_responses.
Cursor-paginated by :after on the last seen response id; see
#poll_votes for paging details.
90 91 92 93 94 |
# File 'lib/forem/resources/survey.rb', line 90 def poll_text_responses(params = {}, opts = {}) opts = opts.dup opts[:requestor] ||= @requestor Forem::ForemObject.cursor_list("#{resource_url}/poll_text_responses", params, opts) end |
#poll_votes(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::ForemObject>
Return the multiple-choice poll selections recorded for this survey.
Sends a GET request to /api/surveys/:id_or_slug/poll_votes.
Pagination is cursor-based — pass the last seen vote id as :after
(or use ListObject#auto_paging_each, which threads the
cursor automatically).
67 68 69 70 71 |
# File 'lib/forem/resources/survey.rb', line 67 def poll_votes(params = {}, opts = {}) opts = opts.dup opts[:requestor] ||= @requestor Forem::ForemObject.cursor_list("#{resource_url}/poll_votes", params, opts) end |