Class: Forem::Organization

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List, APIOperations::Retrieve, APIOperations::Update
Includes:
APIOperations::Delete, APIOperations::Save
Defined in:
lib/forem/resources/organization.rb

Overview

Represents a Forem organization (a group account that can publish articles).

Organizations are team or company accounts on a Forem instance. They support full CRUD operations and expose sub-collection endpoints for listing their members and articles. Organizations can be retrieved by either numeric ID or username slug.

Available operations (via mixins):

- +List+     — GET /api/organizations  (default: 10 per page)
- +Create+   — POST /api/organizations
- +Retrieve+ — GET /api/organizations/:id_or_username
- +Update+   — PUT /api/organizations/:id
- +Delete+   — instance-level delete
- +Save+     — instance-level save (create or update)

Examples:

List all organizations

orgs = client.organizations.list(per_page: 20)
orgs.data.each { |o| puts o.name }

Create an organization

org = client.organizations.create(
  organization: { name: "Acme Corp", summary: "We make things." }
)

Retrieve an organization by username

org = client.organizations.retrieve("acme-corp")
puts org.name

See Also:

Constant Summary collapse

OBJECT_NAME =
"organization"
RESOURCE_PATH =
"/api/organizations"

Instance Attribute Summary

Attributes inherited from ForemObject

#requestor

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Retrieve

retrieve

Methods included from APIOperations::Update

update

Methods included from APIOperations::Save

#save

Methods included from APIOperations::Delete

#delete, included

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

Instance Method Details

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

Return articles published under this organization.

Sends a GET request to /api/organizations/:id/articles.

Examples:

org = client.organizations.retrieve("acme-corp")
org.articles.each { |a| puts a.title }

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

Returns:

See Also:



74
75
76
77
# File 'lib/forem/resources/organization.rb', line 74

def articles(params = {}, opts = {})
  resp = request(:get, "#{resource_url}/articles", params, opts)
  (resp.parsed_body || []).map { |item| Forem::Article.construct_from(item) }
end

#users(params = {}, opts = {}) ⇒ Array<Forem::User>

Return the members of this organization.

Sends a GET request to /api/organizations/:id/users.

Examples:

org = client.organizations.retrieve("acme-corp")
org.users.each { |u| puts u.username }

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

Returns:

See Also:



56
57
58
59
# File 'lib/forem/resources/organization.rb', line 56

def users(params = {}, opts = {})
  resp = request(:get, "#{resource_url}/users", params, opts)
  (resp.parsed_body || []).map { |item| Forem::User.construct_from(item) }
end