Module: Huanxin::Group
- Included in:
- Client
- Defined in:
- lib/huanxin/group.rb
Instance Method Summary collapse
-
#create_group(name, desc, owner, is_public = true, maxusers = 200, is_approval = false, members = nil) ⇒ Object
创建一个群组.
-
#delete_group(group_id) ⇒ Object
删除一个群组.
-
#get_group_info(group_id) ⇒ Object
获取群组基本信息.
-
#modify_group(group_id, name, desc, maxusers = nil) ⇒ Object
修改群组信息.
Instance Method Details
#create_group(name, desc, owner, is_public = true, maxusers = 200, is_approval = false, members = nil) ⇒ Object
创建一个群组
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/huanxin/group.rb', line 5 def create_group(name, desc, owner, is_public = true, maxusers = 200, is_approval = false, members = nil) token = self.auth_token() body = {groupname: name, desc: desc, public: is_public, owner: owner, maxusers: maxusers, approval: is_approval} body.merge!({members: members}) unless members.nil? result = HTTParty.post("#{@head_url}/chatgroups", :body => body.to_json, :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } ) if result.response.code.to_i == 200 return result["data"]["groupid"] else nil end end |
#delete_group(group_id) ⇒ Object
删除一个群组
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/huanxin/group.rb', line 53 def delete_group(group_id) token = self.auth_token() result = HTTParty.delete("#{@head_url}/chatgroups/#{group_id}", :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } ) if result.response.code.to_i == 200 return [result["data"]["groupid"], result["data"]["success"]] else nil end end |
#get_group_info(group_id) ⇒ Object
获取群组基本信息
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/huanxin/group.rb', line 39 def get_group_info(group_id) token = self.auth_token() result = HTTParty.get("#{@head_url}/chatgroups/#{group_id}", :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } ) if result.response.code.to_i == 200 return result["data"][0] else nil end end |
#modify_group(group_id, name, desc, maxusers = nil) ⇒ Object
修改群组信息
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/huanxin/group.rb', line 22 def modify_group(group_id, name, desc, maxusers = nil) token = self.auth_token() body = {groupname: name, description: desc} body.merge!({maxusers: maxusers}) unless maxusers.nil? result = HTTParty.put("#{@head_url}/chatgroups/#{group_id}", :body => body.to_json, :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } ) if result.response.code.to_i == 200 return result["data"] #maxusers, groupname, description else nil end end |