Class: Totango::User

Inherits:
Object
  • Object
show all
Defined in:
lib/totango-api/user.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ User

Returns a new instance of User.



3
4
5
6
# File 'lib/totango-api/user.rb', line 3

def initialize(args = {})
  @attributes = Hash.new(nil)
  args.each {|k,v| self.send("#{k}=".to_sym,v)}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(s, *args) ⇒ Object

Raises:

  • (NoMethodError)


22
23
24
25
26
27
28
# File 'lib/totango-api/user.rb', line 22

def method_missing(s,*args)
  m=s.to_s.sub(/=$/,"")
  attr_name = "sdr_u.#{m}"
  return @attributes[attr_name] = "#{args.join(" ")}" if args.length > 0
  raise NoMethodError, "#{s.to_s} for #{self.class}" unless @attributes[attr_name]
  return @attributes[attr_name]
end

Instance Method Details

#attributesObject



30
31
32
# File 'lib/totango-api/user.rb', line 30

def attributes
  @attributes.delete_if {|k,v| v.nil? }
end

#idObject



8
9
10
# File 'lib/totango-api/user.rb', line 8

def id
  @attributes["sdr_u"]
end

#id=(id) ⇒ Object



11
12
13
# File 'lib/totango-api/user.rb', line 11

def id=(id)
  @attributes["sdr_u"]=id
end

#nameObject



15
16
17
# File 'lib/totango-api/user.rb', line 15

def name
  @attributes["sdr_u.name"]
end

#name=(n) ⇒ Object



18
19
20
# File 'lib/totango-api/user.rb', line 18

def name=(n)
  @attributes["sdr_u.name"]=n
end