Class: Forem::Follower

Inherits:
APIResource show all
Defined in:
lib/forem/resources/follower.rb

Overview

Represents a user who follows the authenticated user.

A Follower record describes a user that has subscribed to the authenticated user's content. Only listing is supported — you cannot create or delete follower relationships through this resource directly.

Requires authentication. Default: 80 per page.

Note: the list endpoint hits /api/followers/users (not /api/followers), and the default page size is 80 (larger than most other resources).

Examples:

List users who follow the authenticated user

followers = client.followers.list
followers.data.each { |f| puts f.name }

Iterate over all followers using auto-pagination

client.followers.list.auto_paging_each { |f| puts f.username }

See Also:

Constant Summary collapse

OBJECT_NAME =
"follower"
RESOURCE_PATH =
"/api/followers"

Instance Attribute Summary

Attributes inherited from ForemObject

#requestor

Class Method Summary collapse

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

included, #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

.list(params = {}, opts = {}) ⇒ Forem::ListObject<Forem::Follower>

Return a paginated list of users who follow the authenticated user.

Requires authentication. Default: 80 per page.

Sends a GET request to /api/followers/users.

Examples:

followers = client.followers.list(per_page: 25, sort: "name")
followers.data.each { |f| puts f.name }

Parameters:

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

    query parameters

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

    per-request options (e.g., :api_key)

Options Hash (params):

  • :page (Integer)

    page number (default: 1)

  • :per_page (Integer)

    number of results per page (default: 80)

  • :sort (String)

    sort order; default 'created_at'; use '-created_at' for newest first

Returns:

See Also:



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/forem/resources/follower.rb', line 42

def self.list(params = {}, opts = {})
  requestor = opts[:requestor]
  resp = request(:get, "/api/followers/users", params, opts)
  data = (resp.parsed_body || []).map { |item| construct_from(item) }
  per_page = params[:per_page] || params["per_page"] || 80
  page = params[:page] || params["page"] || 1
  ListObject.new(
    data: data, current_page: page.to_i, per_page: per_page.to_i,
    resource_class: self,
    filters: params.reject { |k, _| [:page, :per_page, "page", "per_page"].include?(k) },
    requestor: requestor
  )
end