class BaseCRM::UsersService

Public Class Methods

new(client) click to toggle source
# File lib/basecrm/services/users_service.rb, line 5
def initialize(client)
  @client = client
end

Public Instance Methods

all() click to toggle source

Retrieve all users

get '/users'

If you want to use filtering or sorting (see where). @return [Enumerable] Paginated resource you can use to iterate over all the resources.

# File lib/basecrm/services/users_service.rb, line 15
def all
  PaginatedResource.new(self)
end
find(id) click to toggle source

Retrieve a single user

get '/users/{id}'

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

@param id [Integer] Unique identifier of a User @return [User] Searched resource object.

# File lib/basecrm/services/users_service.rb, line 52
def find(id)
  _, _, root = @client.get("/users/#{id}")

  User.new(root[:data])
end
self() click to toggle source

Retrieve an authenticating user

get '/users/self'

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

@return [User] Resource object.

# File lib/basecrm/services/users_service.rb, line 66
def self
  _, _, root = @client.get("/users/self")
  User.new(root[:data])
end
where(options = {}) click to toggle source

Retrieve all users

get '/users'

Returns all users, according to the parameters provided

@param options [Hash] Search options @option options [Boolean] :confirmed Indicator whether to return only confirmed user accounts or not. @option options [String] :email Email of the user. This parameter is used in a strict sense. @option options [String] :ids Comma-separated list of user IDs to be returned in a request. @option options [String] :name Name of the user. This parameter is used in a strict sense. @option options [Integer] :page (1) Page number to start from. Page numbering starts at 1, and omitting the `page` parameter will return the first page. @option options [Integer] :per_page (25) Number of records to return per page. The default limit is 25, and the maximum number that can be returned is 100. @option options [String] :role Role of user to search for. @option options [String] :sort_by (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`. @option options [String] :status Status of user accounts to search for. @return [Array<User>] The list of Users for the first page, unless otherwise specified.

# 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

Private Instance Methods

extract_params!(user, *args) click to toggle source
# File lib/basecrm/services/users_service.rb, line 77
def extract_params!(user, *args)
  params = user.to_h.select{ |k, _| args.include?(k) }
  raise ArgumentError, "one of required attributes is missing. Expected: #{args.join(',')}" if params.count != args.length
  params
end
validate_type!(user) click to toggle source
# File lib/basecrm/services/users_service.rb, line 73
def validate_type!(user)
  raise TypeError unless user.is_a?(User) || user.is_a?(Hash)
end