Class: Forem::Follow

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

Overview

Represents a follow relationship — a user, organization, or tag the authenticated user follows.

The list endpoint returns followed tags only (the route is /api/follows/tags). The create endpoint follows users and/or organizations in bulk.

Examples:

List the tags the authenticated user is following

follows = client.follows.list(per_page: 10)
follows.each { |f| puts f.name }

Follow users in bulk

client.follows.create(user_ids: [42, 99])
#=> #<Forem::Follow {"outcome" => "followed 2 users"}>

Follow organizations in bulk

client.follows.create(organization_ids: [7])

Combined call

client.follows.create(user_ids: [42], organization_ids: [7])

See Also:

Constant Summary collapse

OBJECT_NAME =
"follow"
RESOURCE_PATH =
"/api/follows"

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

.create(params = {}, opts = {}) ⇒ Forem::Follow

Follow one or more users and/or organizations on behalf of the authenticated user.

Sends a POST request to /api/follows. The Forem API does not follow tags through this endpoint (unlike what #list returns). It accepts:

  • user_ids: — Array of user IDs to follow
  • organization_ids: — Array of organization IDs to follow

The response is an outcome summary (e.g. {"outcome" => "followed 2 users"}), not a full follow record. If neither param is supplied, the API silently reports "followed 0 users" — pass user_ids or organization_ids explicitly.

Examples:

client.follows.create(user_ids: [42, 99])
#=> #<Forem::Follow {"outcome" => "followed 2 users"}>

Parameters:

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

    request body

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

    per-request options

Options Hash (params):

  • :user_ids (Array<Integer>)

    list of user IDs to follow

  • :organization_ids (Array<Integer>)

    list of org IDs to follow

Returns:

See Also:



72
73
74
75
76
# File 'lib/forem/resources/follow.rb', line 72

def self.create(params = {}, opts = {})
  requestor = opts[:requestor]
  resp = request(:post, resource_path, params, opts)
  construct_from(resp.parsed_body, requestor: requestor)
end

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

Return a paginated list of tags followed by the authenticated user.

Requires authentication. Sends a GET request to /api/follows/tags (the list verb is mapped to the tags collection rather than the base resource path on this endpoint).

Examples:

follows = client.follows.list(per_page: 10)
follows.each { |f| puts f.name }

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: 30)

Returns:

See Also:



43
44
45
# File 'lib/forem/resources/follow.rb', line 43

def self.list(params = {}, opts = {})
  paginated_list("/api/follows/tags", params, opts)
end