huanxin 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6830d7a4854d536f51f7688f1fbfb97f2a18211d
4
- data.tar.gz: 0e05fc2065187813660ea05a40c309f80c7c5591
3
+ metadata.gz: a0d15740b0f4352db78aaefa49071b7713437e00
4
+ data.tar.gz: 42da239e90dbabecce0cc885eeb04bc18e9d712d
5
5
  SHA512:
6
- metadata.gz: 0dcae61318d872ccd0ddbb9ddde8834a26490ced86520f137e66e7f99463290fb4e01fee5f203e41697125d8ea4d65af674ca918d779dad21d010ed6f6651fc0
7
- data.tar.gz: 32b6ce92226c53815e5635e6bd12c44278467d13afe575845a0935d7d66c987cde1e225c19d4cf5cf4b4943703d43a9599f8051acdcebb83d3a60cb4265b7af2
6
+ metadata.gz: 1298745ba980bef97f88a09976d7ee007445a74a8da97171db0bcff9c098f3e25fab99e4c8f479c7796039c7adbf26fba6e5aea8e846427eac36fd07e6140692
7
+ data.tar.gz: 3b2dcb6add58ef78df9327a837ca0adc429e4ad3a6be4db994252a77d1a88985fb10957ac3996f916b5defaa02859be080c3d6c6c854ed32811331f8d2189cb0
@@ -6,40 +6,45 @@ PATH
6
6
  GEM
7
7
  remote: http://ruby.taobao.org/
8
8
  specs:
9
- activesupport (4.2.3)
10
- i18n (~> 0.7)
11
- json (~> 1.7, >= 1.7.7)
12
- minitest (~> 5.1)
13
- thread_safe (~> 0.3, >= 0.3.4)
14
- tzinfo (~> 1.1)
9
+ activesupport (4.0.13)
10
+ i18n (~> 0.6, >= 0.6.9)
11
+ minitest (~> 4.2)
12
+ multi_json (~> 1.3)
13
+ thread_safe (~> 0.1)
14
+ tzinfo (~> 0.3.37)
15
15
  diff-lcs (1.2.5)
16
16
  httparty (0.13.5)
17
17
  json (~> 1.8)
18
18
  multi_xml (>= 0.5.2)
19
19
  i18n (0.7.0)
20
20
  json (1.8.3)
21
- minitest (5.7.0)
21
+ minitest (4.7.5)
22
+ multi_json (1.11.2)
22
23
  multi_xml (0.5.5)
23
24
  rake (10.4.2)
24
- rspec (2.99.0)
25
- rspec-core (~> 2.99.0)
26
- rspec-expectations (~> 2.99.0)
27
- rspec-mocks (~> 2.99.0)
28
- rspec-core (2.99.2)
29
- rspec-expectations (2.99.2)
30
- diff-lcs (>= 1.1.3, < 2.0)
31
- rspec-mocks (2.99.4)
25
+ rspec (3.3.0)
26
+ rspec-core (~> 3.3.0)
27
+ rspec-expectations (~> 3.3.0)
28
+ rspec-mocks (~> 3.3.0)
29
+ rspec-core (3.3.1)
30
+ rspec-support (~> 3.3.0)
31
+ rspec-expectations (3.3.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.3.0)
34
+ rspec-mocks (3.3.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.3.0)
37
+ rspec-support (3.3.0)
32
38
  thread_safe (0.3.5)
33
- tzinfo (1.2.2)
34
- thread_safe (~> 0.1)
39
+ tzinfo (0.3.44)
35
40
 
36
41
  PLATFORMS
37
42
  ruby
38
43
 
39
44
  DEPENDENCIES
40
- activesupport
45
+ activesupport (~> 4.0.1)
41
46
  bundler (~> 1.8)
42
47
  httparty (~> 0.13.3)
43
48
  huanxin!
44
49
  rake (~> 10.0)
45
- rspec (~> 2.6)
50
+ rspec (~> 3.0)
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.8"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "rspec", "~> 2.6"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
29
  spec.add_development_dependency "httparty", "~> 0.13.3"
30
- spec.add_development_dependency "activesupport"
30
+ spec.add_development_dependency "activesupport" ,"~> 4.0.1"
31
31
  end
@@ -1,6 +1,8 @@
1
1
  require "huanxin/version"
2
2
  require "huanxin/base"
3
3
  require "huanxin/client"
4
+ #require "huanxin/user_messsage"
5
+ #require "huanxin/user_group"
4
6
 
5
7
  module Huanxin
6
8
  # Your code goes here...
@@ -11,7 +11,9 @@ module Huanxin
11
11
  end
12
12
 
13
13
  class Base
14
- RAND_WORDS = [('a'..'z'), ('A'..'Z'), (0..9), ['_']].map { |i| i.to_a }.flatten
14
+ RAND_WORDS = [('a'..'z'), (0..9), ['_','-']].map { |i| i.to_a }.flatten
15
+ #RAND_WORDS = [('a'..'z'), ('A'..'Z'), (0..9), ['_']].map { |i| i.to_a }.flatten
16
+ #由于环信聊天接口会强制转换用户名成小写,所以最好不要包括大写字符,已经和他们沟通,他们不会修改.
15
17
  #cache_client 所有实现了 ActiveSupport::Cache::Store 的对象实例
16
18
  #如果是在rails里面使用,可以直接传递 Rails.cache
17
19
  #
@@ -21,8 +23,8 @@ module Huanxin
21
23
  @client_id = Huanxin.config[:client_id]
22
24
  @client_secret = Huanxin.config[:client_secret]
23
25
  @base_url = Huanxin.config[:host] || 'https://a1.easemob.com'
24
- @username_len = Huanxin.config[:username_len] || 8
25
- @password_len = Huanxin.config[:password_len] || 10
26
+ @username_len = Huanxin.config[:username_len] || 10
27
+ @password_len = Huanxin.config[:password_len] || 12
26
28
 
27
29
  @org_name = org_name
28
30
  @app_name = app_name
@@ -0,0 +1,64 @@
1
+ module Huanxin
2
+
3
+ module ChatRoom
4
+ #创建一个聊天室
5
+ def create_chat_room(name, desc, owner, maxusers = 200, members = nil)
6
+ token = self.auth_token()
7
+ body = {name: name, description: desc, owner: owner, maxusers: maxusers}
8
+ body.merge!({members: members}) unless members.nil?
9
+
10
+ result = HTTParty.post("#{@head_url}/chatrooms",
11
+ :body => body.to_json,
12
+ :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )
13
+
14
+ if result.response.code.to_i == 200
15
+ return result["data"]["id"]
16
+ else
17
+ nil
18
+ end
19
+ end
20
+ #修改聊天室
21
+ def modify_chat_room(room_id, name, desc, maxusers)
22
+ token = self.auth_token()
23
+ body = {name: name, description: desc, maxusers: maxusers}
24
+
25
+ result = HTTParty.put("#{@head_url}/chatrooms/#{room_id}",
26
+ :body => body.to_json,
27
+ :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )
28
+
29
+ if result.response.code.to_i == 200
30
+ return result["data"]
31
+ else
32
+ nil
33
+ end
34
+ end
35
+ #获取聊天室基本信息
36
+ def get_chat_room_info(room_id)
37
+ token = self.auth_token()
38
+
39
+ result = HTTParty.get("#{@head_url}/chatrooms/#{room_id}",
40
+ :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )
41
+
42
+ if result.response.code.to_i == 200
43
+ return result["data"]
44
+ else
45
+ nil
46
+ end
47
+ end
48
+ #删除一个聊天室
49
+ #
50
+ def delete_chat_room(room_id)
51
+ token = self.auth_token()
52
+
53
+ result = HTTParty.delete("#{@head_url}/chatrooms/#{room_id}",
54
+ :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )
55
+
56
+ if result.response.code.to_i == 200
57
+ return [result["data"]["id"], result["data"]["success"]]
58
+ else
59
+ nil
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -1,12 +1,18 @@
1
1
  require 'httparty'
2
+ require 'huanxin/group'
3
+ require 'huanxin/chat_room'
2
4
 
3
5
  module Huanxin
4
6
 
5
7
  class Client < Huanxin::Base
6
8
 
9
+ include Huanxin::Group
10
+ include Huanxin::ChatRoom
11
+
7
12
  def initialize(cache_client, org_name, app_name)
8
13
  super(cache_client, org_name, app_name)
9
- end
14
+ end
15
+
10
16
  #注册用户到环信
11
17
  def register(user_id, nickname = nil)
12
18
  self.register_by_name_pwd(self.generate_username(user_id), self.generate_password(), nickname)
@@ -0,0 +1,67 @@
1
+ module Huanxin
2
+ module Group
3
+
4
+ #创建一个群组
5
+ def create_group(name, desc, owner, is_public = true, maxusers = 200, is_approval = false, members = nil)
6
+ token = self.auth_token()
7
+ body = {groupname: name, desc: desc, public: is_public, owner: owner, maxusers: maxusers, approval: is_approval}
8
+ body.merge!({members: members}) unless members.nil?
9
+
10
+ result = HTTParty.post("#{@head_url}/chatgroups",
11
+ :body => body.to_json,
12
+ :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )
13
+
14
+
15
+ if result.response.code.to_i == 200
16
+ return result["data"]["groupid"]
17
+ else
18
+ nil
19
+ end
20
+ end
21
+ #修改群组信息
22
+ def modify_group(group_id, name, desc, maxusers = nil)
23
+ token = self.auth_token()
24
+ body = {groupname: name, description: desc}
25
+ body.merge!({maxusers: maxusers}) unless maxusers.nil?
26
+
27
+ result = HTTParty.put("#{@head_url}/chatgroups/#{group_id}",
28
+ :body => body.to_json,
29
+ :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )
30
+
31
+
32
+ if result.response.code.to_i == 200
33
+ return result["data"] #maxusers, groupname, description
34
+ else
35
+ nil
36
+ end
37
+ end
38
+ #获取群组基本信息
39
+ def get_group_info(group_id)
40
+ token = self.auth_token()
41
+
42
+ result = HTTParty.get("#{@head_url}/chatgroups/#{group_id}",
43
+ :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )
44
+
45
+ if result.response.code.to_i == 200
46
+ return result["data"][0]
47
+ else
48
+ nil
49
+ end
50
+ end
51
+ #删除一个群组
52
+ #
53
+ def delete_group(group_id)
54
+ token = self.auth_token()
55
+
56
+ result = HTTParty.delete("#{@head_url}/chatgroups/#{group_id}",
57
+ :headers => { 'Content-Type' => 'application/json', 'Authorization'=>"Bearer #{token}" } )
58
+
59
+ if result.response.code.to_i == 200
60
+ return [result["data"]["groupid"], result["data"]["success"]]
61
+ else
62
+ nil
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Huanxin
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huanxin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robot Jiang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-10 00:00:00.000000000 Z
11
+ date: 2015-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.6'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.6'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: httparty
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: activesupport
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 4.0.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 4.0.1
83
83
  description: "环信 Rest API 的 Ruby Client "
84
84
  email:
85
85
  - robot.z.jiang@gmail.com
@@ -100,7 +100,9 @@ files:
100
100
  - huanxin.gemspec
101
101
  - lib/huanxin.rb
102
102
  - lib/huanxin/base.rb
103
+ - lib/huanxin/chat_room.rb
103
104
  - lib/huanxin/client.rb
105
+ - lib/huanxin/group.rb
104
106
  - lib/huanxin/version.rb
105
107
  homepage: https://github.com/RobotJiang/ruby-for-huanxin
106
108
  licenses: