Class: GoogleApps::Atom::User
- 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
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#login ⇒ Object
Returns the value of attribute login.
-
#password ⇒ Object
Returns the value of attribute password.
-
#quota ⇒ Object
Returns the value of attribute quota.
-
#suspended ⇒ Object
Returns the value of attribute suspended.
Instance Method Summary collapse
-
#add_node(type, attrs) ⇒ Object
add_node creates the specified node in the user document.
-
#hash_password(password) ⇒ Object
hash_password hashes the provided password.
-
#initialize(xml = nil) ⇒ User
constructor
A new instance of User.
-
#node(name) ⇒ Object
TODO: Move this method.
-
#set(attributes) ⇒ Object
set adds the values for the given attributes to the current document.
-
#to_s ⇒ Object
to_s returns @doc as a string.
-
#update_node(type, attribute, value) ⇒ Object
update_node updates an existing node in the document.
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
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
6 7 8 |
# File 'lib/google_apps/atom/user.rb', line 6 def doc @doc end |
#first_name ⇒ Object
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_name ⇒ Object
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 |
#login ⇒ Object
Returns the value of attribute login.
6 7 8 |
# File 'lib/google_apps/atom/user.rb', line 6 def login @login end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/google_apps/atom/user.rb', line 6 def password @password end |
#quota ⇒ Object
Returns the value of attribute quota.
6 7 8 |
# File 'lib/google_apps/atom/user.rb', line 6 def quota @quota end |
#suspended ⇒ Object
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_s ⇒ Object
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 |