Class: CanvasUser

Inherits:
CanvasObject show all
Defined in:
lib/models/canvas_user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CanvasObject

push_csv_to_canvas

Constructor Details

#initialize(opts = {}) ⇒ CanvasUser

Returns a new instance of CanvasUser.



13
14
15
16
17
18
19
# File 'lib/models/canvas_user.rb', line 13

def initialize (opts = {})
  @name = opts[:name] if opts[:name]
  @sis_id = opts[:sis] if opts[:sis]
  @login_id = opts[:login] if opts[:login]
  @email = opts[:email] if opts[:email]
  @time_zone = opts[:time_zone] if opts[:time_zone]
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



2
3
4
# File 'lib/models/canvas_user.rb', line 2

def email
  @email
end

#login_idObject (readonly)

Returns the value of attribute login_id.



2
3
4
# File 'lib/models/canvas_user.rb', line 2

def 
  @login_id
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/models/canvas_user.rb', line 2

def name
  @name
end

#sis_idObject (readonly)

Returns the value of attribute sis_id.



2
3
4
# File 'lib/models/canvas_user.rb', line 2

def sis_id
  @sis_id
end

#time_zoneObject (readonly)

Returns the value of attribute time_zone.



2
3
4
# File 'lib/models/canvas_user.rb', line 2

def time_zone
  @time_zone
end

Class Method Details

.gen_file(opts = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/models/canvas_user.rb', line 42

def self.gen_file(opts = {})
  opts[:rows] ? rows = opts[:rows] : rows = 0
  opts[:settings] ? settings = opts[:settings] : settings = nil
  users = []
  if(opts[:rows])
    rows.times do |x|
      users.push(CanvasUser.random(settings))
    end
  end
  header = %w[user_id integration_id login_id password ssha_password authentication_provider_id first_name last_name full_name sortable_name short_name email status]
  CSV.open('./users.csv', 'wb', write_headers: true, headers: header) do |csv|
    users.each do |acc|
      csv << acc.to_csv
    end
  end
  return users
end

.random(opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/models/canvas_user.rb', line 21

def self.random (opts = {})
  fn = Forgery('name').first_name
  ln = Forgery('name').last_name
  domain = 'instructure.com'
  if opts
    opts[:email_prefix] ? epre = "#{opts[:email_prefix]}+" : epre = ''
    opts[:sis_prefix] ? sispre = "#{opts[:sis_prefix]}_" : sispre = ''
    opts[:domain] ? domain =  opts[:domain] : domain = 'instructure.com'
  end
  e = "#{epre}#{fn}.#{ln}@#{domain}"
  CanvasUser.new(
    {
      name: "#{fn} #{ln}",
      sis: "#{sispre}#{(3_000+rand(1_000_000))}",
      login: e,
      email: e,
      time_zone: Forgery('time').zone
    }
  )
end

Instance Method Details

#to_csvObject



8
9
10
11
# File 'lib/models/canvas_user.rb', line 8

def to_csv
  names = name.split(' ')
  row = [sis_id, nil, , nil, nil, nil, names.first, names.last, name, "#{names.last}, #{names.first}", "#{names.first[0].downcase}#{names.last.downcase}", email, 'active']
end

#to_sObject



4
5
6
# File 'lib/models/canvas_user.rb', line 4

def to_s
  string = "#{name}, #{sis_id}, #{}, #{email}, #{time_zone}"
end