Class: Forem::Article
- Inherits:
-
APIResource
- Object
- ForemObject
- APIResource
- Forem::Article
- Extended by:
- Forem::APIOperations::Create, Forem::APIOperations::List, Forem::APIOperations::Retrieve, Forem::APIOperations::Update
- Includes:
- Forem::APIOperations::Save
- Defined in:
- lib/forem/resources/article.rb
Overview
Represents a Forem article (blog post).
Articles are the core content type on Forem. They support full CRUD operations plus several custom endpoints for filtering by auth state, latest publication order, and full-text search.
Available operations (via mixins):
- +List+ — GET /api/articles
- +Create+ — POST /api/articles
- +Retrieve+ — GET /api/articles/:id
- +Update+ — PUT /api/articles/:id
- +Save+ — instance-level save (create or update)
List Parameters
When calling Article.list, the following query parameters are supported:
tag(String) — Filter by tag; can combine withtoptags(String) — Comma-separated tags; returns articles with ANY of thesetags_exclude(String) — Comma-separated tags to excludeusername(String) — Filter by user or organization usernamestate(String) — One of:"fresh","rising","all". Note:state=allonly works combined withusernameand returns up to 1000 itemstop(Integer) — Most popular articles in the last N days; can combine withtagcollection_id(Integer) — Articles in a specific collection, ordered by publication datepage(Integer) — Page number (default: 1)per_page(Integer) — Items per page (default: 30, max: 1000)
Create Parameters
When calling Article.create, wrap all fields under the :article key:
Constant Summary collapse
- OBJECT_NAME =
"article"- RESOURCE_PATH =
"/api/articles"
Instance Attribute Summary
Attributes inherited from ForemObject
Class Method Summary collapse
-
.latest(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return the most recently published articles ordered by publication date.
-
.me(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return articles authored by the authenticated user (all statuses).
-
.me_all(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return all articles authored by the authenticated user regardless of status.
-
.me_published(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return published articles authored by the authenticated user.
-
.me_unpublished(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return unpublished (draft) articles authored by the authenticated user.
-
.retrieve_by_path(username, slug, opts = {}) ⇒ Forem::Article
Retrieve a single article by the author's username and the article's slug.
-
.search(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Search published articles by keyword.
-
.semantic_search(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Semantically search published articles using Forem's embeddings-based search.
Instance Method Summary collapse
-
#unpublish(opts = {}) ⇒ ForemResponse
Unpublish this article, reverting it to draft status.
Methods included from Forem::APIOperations::Create
Methods included from Forem::APIOperations::List
Methods included from Forem::APIOperations::Retrieve
Methods included from Forem::APIOperations::Update
Methods included from Forem::APIOperations::Save
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 Forem::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
.latest(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return the most recently published articles ordered by publication date.
Sends a GET request to /api/articles/latest.
188 189 190 |
# File 'lib/forem/resources/article.rb', line 188 def self.latest(params = {}, opts = {}) paginated_list("/api/articles/latest", params, opts) end |
.me(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return articles authored by the authenticated user (all statuses).
Requires authentication. Returns articles in reverse chronological order, 30 per page.
Sends a GET request to /api/articles/me.
107 108 109 |
# File 'lib/forem/resources/article.rb', line 107 def self.me(params = {}, opts = {}) paginated_list("/api/articles/me", params, opts) end |
.me_all(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return all articles authored by the authenticated user regardless of status.
Requires authentication. Returns articles in reverse chronological order, 30 per page.
Sends a GET request to /api/articles/me/all.
170 171 172 |
# File 'lib/forem/resources/article.rb', line 170 def self.me_all(params = {}, opts = {}) paginated_list("/api/articles/me/all", params, opts) end |
.me_published(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return published articles authored by the authenticated user.
Requires authentication. Returns articles in reverse chronological order, 30 per page.
Sends a GET request to /api/articles/me/published.
128 129 130 |
# File 'lib/forem/resources/article.rb', line 128 def self.me_published(params = {}, opts = {}) paginated_list("/api/articles/me/published", params, opts) end |
.me_unpublished(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Return unpublished (draft) articles authored by the authenticated user.
Requires authentication. Returns articles in reverse chronological order, 30 per page.
Sends a GET request to /api/articles/me/unpublished.
149 150 151 |
# File 'lib/forem/resources/article.rb', line 149 def self.me_unpublished(params = {}, opts = {}) paginated_list("/api/articles/me/unpublished", params, opts) end |
.retrieve_by_path(username, slug, opts = {}) ⇒ Forem::Article
Retrieve a single article by the author's username and the article's slug.
Sends a GET request to /api/articles/:username/:slug.
250 251 252 253 254 |
# File 'lib/forem/resources/article.rb', line 250 def self.retrieve_by_path(username, slug, opts = {}) requestor = opts[:requestor] resp = request(:get, "/api/articles/#{CGI.escape(username)}/#{CGI.escape(slug)}", {}, opts) construct_from(resp.parsed_body, requestor: requestor) end |
.search(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Search published articles by keyword.
Sends a GET request to /api/articles/search.
207 208 209 |
# File 'lib/forem/resources/article.rb', line 207 def self.search(params = {}, opts = {}) paginated_list("/api/articles/search", params, opts) end |
.semantic_search(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Article>
Semantically search published articles using Forem's embeddings-based search.
Unlike search (keyword matching), this endpoint finds articles whose
meaning is close to the query text, using vector similarity. Requires
authentication.
Sends a GET request to /api/articles/semantic_search.
234 235 236 |
# File 'lib/forem/resources/article.rb', line 234 def self.semantic_search(params = {}, opts = {}) paginated_list("/api/articles/semantic_search", params, opts) end |
Instance Method Details
#unpublish(opts = {}) ⇒ ForemResponse
Unpublish this article, reverting it to draft status.
Marks the article as draft. Keeps content, deletes notifications, preserves comments. Requires admin or moderator role.
Sends a PUT request to /api/articles/:id/unpublish.
86 87 88 |
# File 'lib/forem/resources/article.rb', line 86 def unpublish(opts = {}) request(:put, "#{resource_url}/unpublish", {}, opts) end |