Class: Smarteru::Resources::Users

Inherits:
Base
  • Object
show all
Defined in:
lib/smarteru/resources/users.rb

Instance Attribute Summary

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Smarteru::Resources::Base

Instance Method Details

#create(info = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/smarteru/resources/users.rb', line 14

def create(info = {})
  validate!(info, :email, :employee_i_d, :given_name, :surname, :group)

  params = create_params(info)

  client.request('createUser', params)
end

#enroll(id_or_email, group, module_id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/smarteru/resources/users.rb', line 42

def enroll(id_or_email, group, module_id)
  params = {
    learning_module_enrollment: {
      enrollment: {
        user:                normalize_id_param(id_or_email),
        group_name:          group,
        learning_module_i_d: module_id } } }

  client.request('enrollLearningModules', params)
end

#enrolled?(id_or_email, group, course_name) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/smarteru/resources/users.rb', line 75

def enrolled?(id_or_email, group, course_name)
  enrollments = learner_report(id_or_email, group)
  enrollments.any? { |e| e[:course_name] == course_name }
end

#get(id_or_email) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/smarteru/resources/users.rb', line 4

def get(id_or_email)
  params = { user: normalize_id_param(id_or_email) }

  response = client.request('getUser', params)
  response.success? ? response.result[:user] : response
rescue Error => e
  return nil if e.code == 'GU:03'
  fail e
end

#learner_report(id_or_email, group) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/smarteru/resources/users.rb', line 53

def learner_report(id_or_email, group)
  params = {
    report: {
      filters: {
        groups: {
          group_names: {
            group_name: group } },
        learning_modules: nil,
        users: {
          user_identifier: normalize_id_param(id_or_email, :email_address) } },
      columns: [
        { column_name: 'ENROLLED_DATE' },
        { column_name: 'COMPLETED_DATE' },
        { column_name: 'DUE_DATE' },
        { column_name: 'LAST_ACCESSED_DATE' },
        { column_name: 'STARTED_DATE' } ],
      custom_fields: nil } }

  response = client.request('getLearnerReport', params)
  [ response.result[:learner_report][:learner] ].flatten.compact
end

#signin(id_or_email) ⇒ Object



36
37
38
39
40
# File 'lib/smarteru/resources/users.rb', line 36

def (id_or_email)
  params = { security: normalize_id_param(id_or_email) }

  client.request('requestExternalAuthorization', params)
end

#update(id_or_email, info = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/smarteru/resources/users.rb', line 22

def update(id_or_email, info = {})
  params = { user:
    { identifier: normalize_id_param(id_or_email),
      info:       info,
      profile:    nil,
      groups:     nil } }

  client.request('updateUser', params)
end

#update_employee_id(id_or_email, new_employee_id) ⇒ Object



32
33
34
# File 'lib/smarteru/resources/users.rb', line 32

def update_employee_id(id_or_email, new_employee_id)
  update(id_or_email, employee_i_d: new_employee_id)
end