Class: GoogleApps::Atom::User

Inherits:
Document
  • Object
show all
Defined in:
lib/google_apps/atom/user.rb

Overview

TODO: Move User attribute map to user class TODO: Update attribute map to include @ for instance variables

Constant Summary collapse

MAP =
{
  userName: :login,
  suspended: :suspended,
  familyName: :last_name,
  givenName: :first_name,
  limit: :quota,
  password: :password
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Document

add_type, #attrs_from_props, #build_root, #delete_node, #determine_namespaces, #find_and_update, #find_values, inherited, #make_document, #new_empty_doc, #parse, #set_instances, sub_to_meth, #type_to_s, #type_to_sym, types

Methods included from Node

#add_attributes, #add_namespaces, #add_prop_node, #check_value, #create_node, #get_content, #get_values, #node_match?

Constructor Details

#initialize(xml = nil) ⇒ User

Returns a new instance of User.



17
18
19
20
21
22
23
24
25
# File 'lib/google_apps/atom/user.rb', line 17

def initialize(xml = nil)
    if xml
      super(xml, MAP)
      find_values
    else
      super(nil, MAP)
	  @doc.root = build_root :user
    end
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



6
7
8
# File 'lib/google_apps/atom/user.rb', line 6

def doc
  @doc
end

#first_nameObject

Returns the value of attribute first_name.



6
7
8
# File 'lib/google_apps/atom/user.rb', line 6

def first_name
  @first_name
end

#last_nameObject

Returns the value of attribute last_name.



6
7
8
# File 'lib/google_apps/atom/user.rb', line 6

def last_name
  @last_name
end

#loginObject

Returns the value of attribute login.



6
7
8
# File 'lib/google_apps/atom/user.rb', line 6

def 
  @login
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/google_apps/atom/user.rb', line 6

def password
  @password
end

#quotaObject

Returns the value of attribute quota.



6
7
8
# File 'lib/google_apps/atom/user.rb', line 6

def quota
  @quota
end

#suspendedObject

Returns the value of attribute suspended.



6
7
8
# File 'lib/google_apps/atom/user.rb', line 6

def suspended
  @suspended
end

Instance Method Details

#add_node(type, attrs) ⇒ Object

add_node creates the specified node in the user document. It takes a type/name and an array of attribute, value pairs as arguments. It also parses the new document and saves the copy in @doc

add_node ‘apps:login’, [[‘userName’, ‘Zanzabar’]]

add_node returns a parsed copy of the new document.



48
49
50
51
52
# File 'lib/google_apps/atom/user.rb', line 48

def add_node(type, attrs) # TODO: Should take a target argument rather than only appending to @doc.root
  @doc.root << create_node(type: type, attrs: attrs)

  @doc = parse @doc
end

#hash_password(password) ⇒ Object

hash_password hashes the provided password

hash_password ‘new password’

hash_password returns an SHA1 digest of the password



156
157
158
# File 'lib/google_apps/atom/user.rb', line 156

def hash_password(password)
  OpenSSL::Digest::SHA1.hexdigest password
end

#node(name) ⇒ Object

TODO: Move this method.



65
66
67
# File 'lib/google_apps/atom/user.rb', line 65

def node(name)
  @doc.find_first("//#{name}")
end

#set(attributes) ⇒ Object

set adds the values for the given attributes to the current document. populates takes a hash of attribute, value pairs.

set login: ‘Zuddile’, password: ‘old shoes’



33
34
35
36
37
# File 'lib/google_apps/atom/user.rb', line 33

def set(attributes)
  attributes.keys.each do |key|
    self.send("#{key}=", attributes[key])
  end
end

#to_sObject

to_s returns @doc as a string



162
163
164
# File 'lib/google_apps/atom/user.rb', line 162

def to_s
  @doc.to_s
end

#update_node(type, attribute, value) ⇒ Object

update_node updates an existing node in the document. It takes the type/name, attribute name and the new value as arguments

update_node ‘apps:login’, :userName, true



59
60
61
# File 'lib/google_apps/atom/user.rb', line 59

def update_node(type, attribute, value)
  find_and_update "//#{type}", { attribute => [instance_variable_get("@#{MAP[attribute]}").to_s, value.to_s]}
end