Class: Zensana::Zendesk::User

Inherits:
Object
  • Object
show all
Includes:
Validate::Key, Access
Defined in:
lib/zensana/models/zendesk/user.rb

Constant Summary collapse

REQUIRED_KEYS =
[ :name, :email ]
OPTIONAL_KEYS =
[ :time_zone, :locale_id, :organization_id, :role, :verified, :phone, :photo ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validate::Key

#has_required_keys?, #has_unknown_keys?, #optional_keys, #required_keys, #valid_keys, #validate_keys

Methods included from Access

#zendesk_service

Constructor Details

#initializeUser

Returns a new instance of User.



14
15
16
# File 'lib/zensana/models/zendesk/user.rb', line 14

def initialize
  @attributes = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



31
32
33
# File 'lib/zensana/models/zendesk/user.rb', line 31

def method_missing(name, *args, &block)
  attributes[name.to_s] || super
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



12
13
14
# File 'lib/zensana/models/zendesk/user.rb', line 12

def attributes
  @attributes
end

Instance Method Details

#create(attributes) ⇒ Object

Raises:



22
23
24
25
26
27
28
29
# File 'lib/zensana/models/zendesk/user.rb', line 22

def create(attributes)
  validate_keys attributes
  email = attributes['email'] || (attributes['user'] && attributes['user']['email'])
  raise AlreadyExists, "User '#{email}' already exists" if email && lookup_by_email(email)
  user = create_user(attributes)
  update_cache user
  @attributes = user
end

#find(spec) ⇒ Object



18
19
20
# File 'lib/zensana/models/zendesk/user.rb', line 18

def find(spec)
  @attributes = lookup(spec)
end