Class: Forem::Services::AdminUserService

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

Overview

Service for interacting with the Forem Admin Users API.

Provides administrative operations on user accounts. These endpoints require an API key with admin-level privileges. Access via Client#admin_users. All methods inject the client's requestor automatically so no additional configuration is required.

Examples:

client = Forem::Client.new("admin-api-key")
user = client.admin_users.create(
  email: "newuser@example.com",
  name: "New User"
)

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

Submit multiple external identity links in one request.

Parameters:

  • provider (String)

    the identity provider shared by the identities.

  • identities (Array<Hash>)

    identity hashes containing user_id and uid.

  • opts (Hash)

    per-request options.

Returns:

  • (Array<ForemObject>)

    per-item results containing user_id, status, and an error_code when that item fails.



67
68
69
70
71
72
73
# File 'lib/forem/services/admin_user_service.rb', line 67

def bulk_link_identities(provider:, identities:, **opts)
  AdminUser.bulk_link_identities(
    provider: provider,
    identities: identities,
    **opts_with_requestor(opts)
  )
end

#create(params = {}, opts = {}) ⇒ AdminUser

Invite a new user to the Forem instance.

Creates a user account and sends them an invitation email. Requires admin privileges.

Examples:

client.admin_users.create(
  email: "jane@example.com",
  name: "Jane Doe"
)

Parameters:

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

    user attributes

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

    per-request options

Options Hash (params):

  • :email (String)

    the new user's email address (required)

  • :name (String)

    display name for the new user

  • :username (String)

    desired username (generated if omitted)

Returns:

  • (AdminUser)

    the newly created user record

See Also:



39
40
41
# File 'lib/forem/services/admin_user_service.rb', line 39

def create(params = {}, opts = {})
  AdminUser.create(params, opts_with_requestor(opts))
end

#identities(user_id, **opts) ⇒ Array<ForemObject>

List a user's linked external identities.

Parameters:

  • user_id (Integer, String)

    the Forem user ID.

  • opts (Hash)

    per-request options.

Returns:

  • (Array<ForemObject>)

    the user's linked identities.



80
81
82
# File 'lib/forem/services/admin_user_service.rb', line 80

def identities(user_id, **opts)
  AdminUser.identities(user_id, **opts_with_requestor(opts))
end

Link an external identity to a user.

Parameters:

  • user_id (Integer, String)

    the Forem user ID.

  • provider (String)

    the identity provider name.

  • uid (String)

    the provider's stable user identifier.

  • opts (Hash)

    per-request options.

Returns:



50
51
52
53
54
55
56
57
# File 'lib/forem/services/admin_user_service.rb', line 50

def link_identity(user_id, provider:, uid:, **opts)
  AdminUser.link_identity(
    user_id,
    provider: provider,
    uid: uid,
    **opts_with_requestor(opts)
  )
end

Unlink an external identity from a user.

Parameters:

  • user_id (Integer, String)

    the Forem user ID.

  • identity_id (Integer, String)

    the linked identity ID.

  • opts (Hash)

    per-request options.

Returns:

  • (ForemObject, nil)

    the unlinked identity, or nil for an empty response.



91
92
93
94
95
96
97
# File 'lib/forem/services/admin_user_service.rb', line 91

def unlink_identity(user_id, identity_id, **opts)
  AdminUser.unlink_identity(
    user_id,
    identity_id,
    **opts_with_requestor(opts)
  )
end

#update_notification_settings(user_id, settings:, **opts) ⇒ ForemObject

Returns the updated notification setting.

Parameters:

  • user_id (Integer, String)

    the Forem user ID.

  • settings (Hash)

    notification setting columns to write.

  • opts (Hash)

    per-request options.

Returns:



104
105
106
107
108
109
110
# File 'lib/forem/services/admin_user_service.rb', line 104

def update_notification_settings(user_id, settings:, **opts)
  AdminUser.update_notification_settings(
    user_id,
    settings: settings,
    **opts_with_requestor(opts)
  )
end