Class: Forem::Services::UserService

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

Overview

Service for interacting with the Forem Users API.

Access via Client#users. All methods inject the client's requestor automatically so no additional configuration is required.

Examples:

client = Forem::Client.new("your-api-key")
me = client.users.me
user = client.users.retrieve(42)

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

#me(opts = {}) ⇒ User

Retrieve the profile of the currently authenticated user.

Examples:

me = client.users.me
puts me.username

Parameters:

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

    per-request options

Returns:

  • (User)

    the authenticated user's profile

See Also:



41
42
43
# File 'lib/forem/services/user_service.rb', line 41

def me(opts = {})
  User.me(opts_with_requestor(opts))
end

#retrieve(id, opts = {}) ⇒ User

Retrieve a single user by their numeric ID.

Examples:

client.users.retrieve(42)

Parameters:

  • id (Integer, String)

    the user ID, or the string "by_username" combined with the :username param

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

    per-request options

Returns:

  • (User)

    the user with the given ID

See Also:



27
28
29
# File 'lib/forem/services/user_service.rb', line 27

def retrieve(id, opts = {})
  User.retrieve(id, opts_with_requestor(opts))
end

#search(params = {}, opts = {}) ⇒ Array<User>

Search for users by name or username.

Examples:

client.users.search(term: "jane")

Parameters:

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

    query parameters

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

    per-request options

Options Hash (params):

  • :term (String)

    the search term

Returns:

  • (Array<User>)

    users matching the search query

See Also:



56
57
58
# File 'lib/forem/services/user_service.rb', line 56

def search(params = {}, opts = {})
  User.search(params, opts_with_requestor(opts))
end