Module: Huanxin::ChatRoom

Included in:
Client
Defined in:
lib/huanxin/chat_room.rb

Instance Method Summary collapse

Instance Method Details

#create_chat_room(name, desc, owner, maxusers = 200, members = nil) ⇒ Object

创建一个聊天室



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/huanxin/chat_room.rb', line 5

def create_chat_room(name, desc, owner, maxusers = 200, members = nil) 
  token =    self.auth_token()
  body  =    {name: name, description: desc, owner: owner, maxusers: maxusers}
  body.merge!({members: members}) unless members.nil?

  result = HTTParty.post("#{@head_url}/chatrooms", 
      :body => body.to_json,
      :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )

  if result.response.code.to_i == 200
    return result["data"]["id"] 
  else
    nil
  end 
end

#delete_chat_room(room_id) ⇒ Object

删除一个聊天室



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/huanxin/chat_room.rb', line 50

def delete_chat_room(room_id)
  token =    self.auth_token()

  result = HTTParty.delete("#{@head_url}/chatrooms/#{room_id}", 
      :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )

  if result.response.code.to_i == 200
    return [result["data"]["id"], result["data"]["success"]]
  else
    nil
  end 
end

#get_chat_room_info(room_id) ⇒ Object

获取聊天室基本信息



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/huanxin/chat_room.rb', line 36

def get_chat_room_info(room_id) 
  token =    self.auth_token()

  result = HTTParty.get("#{@head_url}/chatrooms/#{room_id}", 
      :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )

  if result.response.code.to_i == 200
    return result["data"] 
  else
    nil
  end 
end

#modify_chat_room(room_id, name, desc, maxusers) ⇒ Object

修改聊天室



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/huanxin/chat_room.rb', line 21

def modify_chat_room(room_id, name, desc, maxusers) 
  token =    self.auth_token()
  body  =    {name: name, description: desc,  maxusers: maxusers}

  result = HTTParty.put("#{@head_url}/chatrooms/#{room_id}", 
      :body => body.to_json,
      :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )

  if result.response.code.to_i == 200
    return result["data"] 
  else
    nil
  end 
end