Class: Gaah::Provisioning::User

Inherits:
ApiModel
  • Object
show all
Defined in:
lib/gaah/provisioning/user.rb

Instance Attribute Summary collapse

Attributes inherited from ApiModel

#id

Instance Method Summary collapse

Methods inherited from ApiModel

#==, batch_create

Constructor Details

#initialize(entry) ⇒ User

Returns a new instance of User.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gaah/provisioning/user.rb', line 6

def initialize(entry)
  store_xml(entry)

  # Meta
  @id        = inner_text(:id)
  @email     = parse_email
  @suspended = attr_value('apps|login', 'suspended') == 'true'
  @admin     = attr_value('apps|login', 'admin') == 'true'

  # Name
  @title       = inner_text(:title)
  @user_name   = attr_value('apps|login', 'userName')
  @family_name = attr_value('apps|name', 'familyName')
  @given_name  = attr_value('apps|name', 'givenName')
  @email     ||= "#{@user_name}@#{Gaah.domain}"
end

Instance Attribute Details

#adminObject (readonly)

Returns the value of attribute admin.



4
5
6
# File 'lib/gaah/provisioning/user.rb', line 4

def admin
  @admin
end

#emailObject (readonly)

Returns the value of attribute email.



4
5
6
# File 'lib/gaah/provisioning/user.rb', line 4

def email
  @email
end

#family_nameObject (readonly)

Returns the value of attribute family_name.



4
5
6
# File 'lib/gaah/provisioning/user.rb', line 4

def family_name
  @family_name
end

#given_nameObject (readonly)

Returns the value of attribute given_name.



4
5
6
# File 'lib/gaah/provisioning/user.rb', line 4

def given_name
  @given_name
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/gaah/provisioning/user.rb', line 4

def name
  @name
end

#suspendedObject (readonly)

Returns the value of attribute suspended.



4
5
6
# File 'lib/gaah/provisioning/user.rb', line 4

def suspended
  @suspended
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/gaah/provisioning/user.rb', line 4

def title
  @title
end

#user_nameObject (readonly)

Returns the value of attribute user_name.



4
5
6
# File 'lib/gaah/provisioning/user.rb', line 4

def user_name
  @user_name
end

Instance Method Details

#events(xoauth_requestor_id, options = {}) ⇒ Object



35
36
37
38
# File 'lib/gaah/provisioning/user.rb', line 35

def events(xoauth_requestor_id, options = {})
  options[:email] = @email
  Gaah::Calendar::Api.events(xoauth_requestor_id, options)
end

#marshal_dumpObject



53
54
55
# File 'lib/gaah/provisioning/user.rb', line 53

def marshal_dump
  [@id, @suspended, @admin, @title, @user_name, @family_name, @given_name, @name, @email]
end

#marshal_load(array) ⇒ Object



57
58
59
# File 'lib/gaah/provisioning/user.rb', line 57

def marshal_load(array)
  @id, @suspended, @admin, @title, @user_name, @family_name, @given_name, @name, @email = array
end

#parse_emailObject



23
24
25
26
27
28
29
# File 'lib/gaah/provisioning/user.rb', line 23

def parse_email
  email_link = (@xml/'gd|feedLink').select { |link|
    link.attr('rel').end_with?('user.emailLists')
  }.first
  return nil if email_link.nil?
  CGI::unescape(email_link.attr('href').split('recipient=').last)
end

#to_json(*args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/gaah/provisioning/user.rb', line 40

def to_json(*args)
  {
    id:          @id,
    suspended:   @suspended,
    admin:       @admin,
    title:       @title,
    user_name:   @user_name,
    family_name: @family_name,
    given_name:  @given_name,
    name:        @name,
  }.to_json
end