Class: LearnWorlds::UserResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/learn_worlds/resources/user_resource.rb

Constant Summary collapse

ENDPOINT =
"/admin/api/v2/users".freeze

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#default_headers, #delete_request, #get_request, #handle_errors, #handle_response, #initialize, #patch_request, #post_request, #put_request

Constructor Details

This class inherits a constructor from LearnWorlds::Resource

Instance Method Details

#attach_tags(user_id:, tags:) ⇒ Object



33
34
35
36
# File 'lib/learn_worlds/resources/user_resource.rb', line 33

def attach_tags(user_id:, tags:)
  put_request("#{ENDPOINT}/#{user_id}/tags", tags: tags, action: 'attach')
  true
end

#create(**attributes) ⇒ Object



10
11
12
# File 'lib/learn_worlds/resources/user_resource.rb', line 10

def create(**attributes)
  UserObject.new(post_request(ENDPOINT, attributes).body)
end

#detach_tags(user_id:, tags:) ⇒ Object



38
39
40
41
# File 'lib/learn_worlds/resources/user_resource.rb', line 38

def detach_tags(user_id:, tags:)
  put_request("#{ENDPOINT}/#{user_id}/tags", tags: tags, action: 'detach')
  true
end

#enroll(user_id:, **attributes) ⇒ Object



28
29
30
31
# File 'lib/learn_worlds/resources/user_resource.rb', line 28

def enroll(user_id:, **attributes)
  post_request("#{ENDPOINT}/#{user_id}/enrollment", attributes)
  true
end

#enrollments(user_id:) ⇒ Object



18
19
20
21
# File 'lib/learn_worlds/resources/user_resource.rb', line 18

def enrollments(user_id:)
  response = get_request("#{ENDPOINT}/#{user_id}/courses")
  Collection.from_response(response, key: "data", type: EnrollmentObject)
end

#find(user_id:) ⇒ Object



14
15
16
# File 'lib/learn_worlds/resources/user_resource.rb', line 14

def find(user_id:)
  UserObject.new(get_request("#{ENDPOINT}/#{user_id}").body)
end

#list(**params) ⇒ Object



5
6
7
8
# File 'lib/learn_worlds/resources/user_resource.rb', line 5

def list(**params)
  response = get_request(ENDPOINT, params)
  Collection.from_response(response, key: "data", type: UserObject)
end

#update(user_id:, **params) ⇒ Object



23
24
25
26
# File 'lib/learn_worlds/resources/user_resource.rb', line 23

def update(user_id:, **params)
  put_request("#{ENDPOINT}/#{user_id}", params)
  true
end