Class: Forem::Trend
- Inherits:
-
APIResource
- Object
- ForemObject
- APIResource
- Forem::Trend
- Extended by:
- APIOperations::List, APIOperations::Retrieve
- Defined in:
- lib/forem/resources/trend.rb
Overview
Represents a trend detected across a Forem instance's content.
Trends are algorithmically-derived topic clusters ("hot and recent" subject areas) made up of related articles. They are read-only via the public API — there is no create/update/delete surface, only listing, retrieval, and a nested endpoint for the articles that make up a trend.
Available operations (via mixins):
- +List+ — GET /api/trends
- +Retrieve+ — GET /api/trends/:id_or_slug
Trend Fields
id(Integer)name(String)slug(String)description(String)key_questions(Array) — Questions the trend's content clusters around score(Float) — Relative trend strength/ranking scorearticles_count(Integer) — Number of articles associated with the trendcover_image(String) — URL of the trend's cover imagefirst_observed_at(String) — ISO 8601 timestamplast_observed_at(String) — ISO 8601 timestampcreated_at(String) — ISO 8601 timestampupdated_at(String) — ISO 8601 timestamptype_of(String) — Always"trend"
The show response additionally includes top_articles, an array of up
to three of the trend's highest-scoring published articles, each with
id, title, slug, score, and published_at.
Constant Summary collapse
- OBJECT_NAME =
"trend"- RESOURCE_PATH =
"/api/trends"
Instance Attribute Summary
Attributes inherited from ForemObject
Class Method Summary collapse
-
.articles(id_or_slug, params = {}, opts = {}) ⇒ Array<Forem::Article>
Return the articles belonging to a trend.
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
Class Method Details
.articles(id_or_slug, params = {}, opts = {}) ⇒ Array<Forem::Article>
Return the articles belonging to a trend.
Sends a GET request to /api/trends/:id_or_slug/articles. Unlike
list and retrieve, this is a class method that takes the trend's
ID or slug directly, so it can be called without first retrieving the
trend itself.
74 75 76 77 78 |
# File 'lib/forem/resources/trend.rb', line 74 def self.articles(id_or_slug, params = {}, opts = {}) requestor = opts[:requestor] resp = request(:get, "#{resource_path}/#{id_or_slug}/articles", params, opts) (resp.parsed_body || []).map { |item| Forem::Article.construct_from(item, requestor: requestor) } end |