Class: Forem::Services::TrendService

Inherits:
BaseService show all
Defined in:
lib/forem/services/trend_service.rb

Overview

Service for interacting with the Forem Trends API.

Trends are algorithmically-derived, "hot and recent" topic clusters made up of related articles. Access via Client#trends. All methods inject the client's requestor automatically so no additional configuration is required. Trends are read-only via the public API.

Examples:

client = Forem::Client.new("your-api-key")
trends = client.trends.list
trend  = client.trends.retrieve("ai-agents")
articles = client.trends.articles("ai-agents")

See Also:

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from Forem::Services::BaseService

Instance Method Details

#articles(id_or_slug, params = {}, opts = {}) ⇒ Array<Forem::Article>

List the articles belonging to a trend.

Examples:

client.trends.articles("ai-agents", per_page: 5, sort: "score")

Parameters:

  • id_or_slug (Integer, String)

    the trend's ID or slug

  • params (Hash) (defaults to: {})

    query parameters

  • opts (Hash) (defaults to: {})

    per-request options

Options Hash (params):

  • :page (Integer)

    page number (default: 1)

  • :per_page (Integer)

    number of results per page (default: 10)

  • :sort (String)

    "score" to sort purely by article score; omit for the default ordering (trend membership distance, then score)

Returns:

See Also:



65
66
67
# File 'lib/forem/services/trend_service.rb', line 65

def articles(id_or_slug, params = {}, opts = {})
  Trend.articles(id_or_slug, params, opts_with_requestor(opts))
end

#list(params = {}, opts = {}) ⇒ Forem::ListObject<Trend>

List hot and recent trends.

Examples:

client.trends.list(per_page: 20)

Parameters:

  • params (Hash) (defaults to: {})

    query parameters

  • opts (Hash) (defaults to: {})

    per-request options

Options Hash (params):

  • :page (Integer)

    page number (default: 1)

  • :per_page (Integer)

    number of results per page (default: 10)

Returns:

See Also:



31
32
33
# File 'lib/forem/services/trend_service.rb', line 31

def list(params = {}, opts = {})
  Trend.list(params, opts_with_requestor(opts))
end

#retrieve(id_or_slug, opts = {}) ⇒ Trend

Retrieve a single trend by its numeric ID or slug.

Examples:

client.trends.retrieve("ai-agents")
client.trends.retrieve(3)

Parameters:

  • id_or_slug (Integer, String)

    the trend's ID or slug

  • opts (Hash) (defaults to: {})

    per-request options

Returns:

  • (Trend)

    the trend matching the given ID or slug

See Also:



46
47
48
# File 'lib/forem/services/trend_service.rb', line 46

def retrieve(id_or_slug, opts = {})
  Trend.retrieve(id_or_slug, opts_with_requestor(opts))
end