Class: LessonlyApi::Users

Inherits:
Request show all
Defined in:
lib/lessonly_api/users.rb

Overview

The collection of methods to fetch users’ data.

Class Method Summary collapse

Methods inherited from Request

client

Methods inherited from ResourceType::Base

#attributes, dump, fields, from_json, #initialize, load

Constructor Details

This class inherits a constructor from LessonlyApi::ResourceType::Base

Class Method Details

.archive(id) ⇒ ResourceType::User

Parameters:

  • id (Integer)

    ID of a user to archive

Returns:



53
54
55
56
# File 'lib/lessonly_api/users.rb', line 53

def archive(id)
  raw_result = send_put("/users/#{id}/archive")
  ResourceType::User.new(raw_result)
end

.create(attributes = {}) ⇒ ResourceType::User

Parameters:

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

    hash with user’s attributes

Returns:



32
33
34
35
# File 'lib/lessonly_api/users.rb', line 32

def create(attributes = {})
  raw_result = send_post('/users', attributes)
  ResourceType::User.new(raw_result)
end

.create_user_assignments(id, assignments = []) ⇒ ResourceType::UserAssignments

Create assignments for a user docs.lessonly.com/#create-user-assignments

Parameters:

  • id (Integer)

    ID of a user

  • assignments (Array) (defaults to: [])

    array with assignments’ attributes to create

Returns:



118
119
120
121
# File 'lib/lessonly_api/users.rb', line 118

def create_user_assignments(id, assignments = [])
  raw_result = send_post("/users/#{id}/assignments", assignments: assignments)
  ResourceType::UserAssignments.new(raw_result)
end

.delete(id) ⇒ ResourceType::User

Parameters:

  • id (Integer)

    ID of a user to delete

Returns:



73
74
75
76
77
# File 'lib/lessonly_api/users.rb', line 73

def delete(id)
  raw_result = send_delete("/users/#{id}")
  # TODO: there should be other type, possibly
  ResourceType::User.new(raw_result)
end

.list(page: 1, per_page: 50, **filters) ⇒ ResourceType::Users

Retrieve all users docs.lessonly.com/#list-users

Parameters:

  • page (Integer) (defaults to: 1)

    the number of the page

  • per_page (Integer) (defaults to: 50)

    the numer of records per page

  • filters (Hash)

    additional filters

Returns:



12
13
14
15
# File 'lib/lessonly_api/users.rb', line 12

def list(page: 1, per_page: 50, **filters)
  raw_result = send_get('/users', page: page, per_page: per_page, filter: filters)
  ResourceType::Users.new(raw_result)
end

.restore(id) ⇒ ResourceType::User

Restore an archived user docs.lessonly.com/#restore-user

Parameters:

  • id (Integer)

    ID of a user to restore

Returns:



63
64
65
66
# File 'lib/lessonly_api/users.rb', line 63

def restore(id)
  raw_result = send_put("/users/#{id}/restore")
  ResourceType::User.new(raw_result)
end

.show(id) ⇒ ResourceType::User

Retrieve all the user’s details including their custom field data docs.lessonly.com/#show-user-details

Parameters:

  • id (Integer)

    ID of the user

Returns:



22
23
24
25
# File 'lib/lessonly_api/users.rb', line 22

def show(id)
  raw_result = send_get("/users/#{id}")
  LessonlyApi::ResourceType::User.new(raw_result)
end

.update(id, attributes = {}) ⇒ ResourceType::User

Parameters:

  • id (Integer)

    ID of a user to update

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

    hash with user’s attributes to update

Returns:



43
44
45
46
# File 'lib/lessonly_api/users.rb', line 43

def update(id, attributes = {})
  raw_result = send_put("/users/#{id}", attributes)
  ResourceType::User.new(raw_result)
end

.update_user_groups(id, attributes = {}) ⇒ ResourceType::UserGroup

Update a user’s involvement in various groups docs.lessonly.com/#update-user-groups

Parameters:

  • id (Integer)

    ID of a user

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

    hash with user’s groups attributes to update

Returns:



96
97
98
99
100
# File 'lib/lessonly_api/users.rb', line 96

def update_user_groups(id, attributes = {})
  raw_result = send_put("/users/#{id}/groups", attributes)
  # TODO: there should be other type, possibly
  ResourceType::UserGroup.new(raw_result)
end

.user_assignments(id) ⇒ ResourceType::UserAssignments

Return a list of assignments for a given user docs.lessonly.com/#user-assignments

Parameters:

  • id (Integer)

    ID of a user

Returns:



107
108
109
110
# File 'lib/lessonly_api/users.rb', line 107

def user_assignments(id)
  raw_result = send_get("/users/#{id}/assignments")
  ResourceType::UserAssignments.new(raw_result)
end

.user_groups(id) ⇒ ResourceType::UserGroup

Return the list of a user’s group memberships and groups they are managing docs.lessonly.com/#user-groups

Parameters:

  • id (Integer)

    ID of a user

Returns:



84
85
86
87
88
# File 'lib/lessonly_api/users.rb', line 84

def user_groups(id)
  raw_result = send_get("/users/#{id}/groups")
  # TODO: there should be other type, possibly
  ResourceType::UserGroup.new(raw_result)
end