Class: HipChat::User

Inherits:
Object
  • Object
show all
Includes:
CommonMethods
Defined in:
lib/hip_chat/user.rb

Constant Summary collapse

URL =
BASE_URL + "user"
ATTRIBUTES =
%w{
  client
  created
  email
  group
  id
  idle
  is_deleted
  is_group_admin
  is_guest
  is_online
  last_active
  links
  mention_name
  name
  password
  photo_url
  presence
  show
  status
  timezone
  title
  token
  type
  version
  xmpp_jid
}

Constants included from CommonMethods

CommonMethods::BASE_URL, CommonMethods::OK_CODES

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(token, attributes) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/hip_chat/user.rb', line 50

def create(token, attributes)
  begin
    create!(token, attributes)
  rescue Error
    false
  end
end

.create!(token, attributes) ⇒ Object



46
47
48
# File 'lib/hip_chat/user.rb', line 46

def create!(token, attributes)
  new(token, attributes).tap(&:save!)
end

.find(token, finder) ⇒ Object

finder can be id, email, or mention_name



42
43
44
# File 'lib/hip_chat/user.rb', line 42

def find(token, finder)
  self.new(token, finder, fetch_details: true)
end

Instance Method Details

#destroy!Object



82
83
84
85
86
# File 'lib/hip_chat/user.rb', line 82

def destroy!
  response = deletion_request(url)
  validate_response(response)
  true
end

#detailsObject



59
60
61
62
63
# File 'lib/hip_chat/user.rb', line 59

def details
  response = get_request(url, auth_hash)
  properties_hash = validate_response(response)
  set_properties(properties_hash)
end

#save!Object



65
66
67
68
69
70
71
72
73
# File 'lib/hip_chat/user.rb', line 65

def save!
  if id.nil?
    response = post_request(URL, hash_for_update)
    validate_response(response)
    true
  else
    update!
  end
end

#update!Object



75
76
77
78
79
80
# File 'lib/hip_chat/user.rb', line 75

def update!
  response = put_request(url, hash_for_update)
  validate_response(response)
  details
  true
end