Class: BaseCRM::UsersService

Inherits:
Object
  • Object
show all
Defined in:
lib/basecrm/services/users_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ UsersService

Returns a new instance of UsersService.



5
6
7
# File 'lib/basecrm/services/users_service.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#allEnumerable

Retrieve all users

get ‘/users’

If you want to use filtering or sorting (see #where).

Returns:

  • (Enumerable)

    Paginated resource you can use to iterate over all the resources.



15
16
17
# File 'lib/basecrm/services/users_service.rb', line 15

def all
  PaginatedResource.new(self)
end

#find(id) ⇒ User

Retrieve a single user

get ‘/users/BaseCRM#id

Returns a single user according to the unique user ID provided If the specified user does not exist, this query returns an error

Parameters:

  • id (Integer)

    Unique identifier of a User

Returns:

  • (User)

    Searched resource object.



52
53
54
55
56
# File 'lib/basecrm/services/users_service.rb', line 52

def find(id)
  _, _, root = @client.get("/users/#{id}")

  User.new(root[:data])
end

#selfUser

Retrieve an authenticating user

get ‘/users/self’

Returns a single authenticating user, according to the authentication credentials provided

Returns:

  • (User)

    Resource object.



66
67
68
69
# File 'lib/basecrm/services/users_service.rb', line 66

def self
  _, _, root = @client.get("/users/self")
  User.new(root[:data])
end

#where(options = {}) ⇒ Array<User>

Retrieve all users

get ‘/users’

Returns all users, according to the parameters provided

Parameters:

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

    Search options

Options Hash (options):

  • :confirmed (Boolean)

    Indicator whether to return only confirmed user accounts or not.

  • :email (String)

    Email of the user. This parameter is used in a strict sense.

  • :ids (String)

    Comma-separated list of user IDs to be returned in a request.

  • :name (String)

    Name of the user. This parameter is used in a strict sense.

  • :page (Integer) — default: 1

    Page number to start from. Page numbering starts at 1, and omitting the ‘page` parameter will return the first page.

  • :per_page (Integer) — default: 25

    Number of records to return per page. The default limit is 25, and the maximum number that can be returned is 100.

  • :role (String)

    Role of user to search for.

  • :sort_by (String) — default: id:asc

    A field to sort by. The default order is ascending. If you want to change the sort order to descending, append ‘:desc` to the field e.g. `sort_by=name:desc`.

  • :status (String)

    Status of user accounts to search for.

Returns:

  • (Array<User>)

    The list of Users for the first page, unless otherwise specified.



36
37
38
39
40
# File 'lib/basecrm/services/users_service.rb', line 36

def where(options = {})
  _, _, root = @client.get("/users", options)

  root[:items].map{ |item| User.new(item[:data]) }
end