easemob 0.2.0 → 0.3.0

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: 56ed81345e9a563df461fd8429d9d00cb3458a79
4
- data.tar.gz: 8e1e91fd5bd5f05f98d4e8ac1f06fa87b8a84884
3
+ metadata.gz: 8055d485f3b40b7996d8bf5419069d97e63385e1
4
+ data.tar.gz: c636336061874989cad3240a2a7683df9deab07d
5
5
  SHA512:
6
- metadata.gz: fb273fa328e8ec22595d7c5399830187fcc4ba814b9c0b0437509c253cb4b7c03a95eade2fbc33f45c6a6d6263284dc1db084ae8d1b8a3ef068f95b6618ac5ca
7
- data.tar.gz: 2e6d665da1c25459436c770edb202a63c9862c27c7353f893410d1e2c7adc880211d206a8a1cc9ceb829671e6d282ea1b0577f7f9fdeb6d6a5658ee82a8f0c97
6
+ metadata.gz: 11491457c0ef576aa92f23437c01497654da88241fea5235aa8722c4819f7d9e98900f00456da2e6c2022a298ff97e55a473a9684067c51352870a1aa98dc4c0
7
+ data.tar.gz: 8b0e157de9dd3aa419656af2b8e723534f891fd2e917a5e26e23ea877e6029ab54a2a989dfd57b015f450ee7131aae5d6c9dca119f4296b3ddbef50aab727753
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/.travis.yml CHANGED
@@ -3,4 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.2.5
5
5
  cache: bundler
6
+ script:
7
+ - bundle exec rake
8
+ - bundle exec codeclimate-test-reporter
6
9
  bundler_args: --jobs=3 --retry=3
@@ -1,13 +1,14 @@
1
1
  module Easemob
2
+ autoload(:FileoperationMessage, File.expand_path('message/fileoperation_message', __dir__))
2
3
  module Fileoperation
3
4
  def upload_chatfile(file_path, restrict_access: true)
4
- request :upload, 'chatfiles', form: { file: HTTP::FormData::File.new(file_path),
5
+ FileoperationMessage.new request :upload, 'chatfiles', form: { file: HTTP::FormData::File.new(file_path),
5
6
  hack: 'X' }, # Existing here for http-form_data 1.0.1 handle single param improperly, see https://github.com/httprb/form_data.rb/issues/4
6
- restrict_access: restrict_access
7
+ restrict_access: restrict_access
7
8
  end
8
9
 
9
10
  def download_chatfile(chatfile_uuid, share_secret: nil, thumbnail: false)
10
- request :download, "chatfiles/#{chatfile_uuid}", share_secret: share_secret, thumbnail: thumbnail
11
+ FileoperationMessage.new request :download, "chatfiles/#{chatfile_uuid}", share_secret: share_secret, thumbnail: thumbnail
11
12
  end
12
13
  end
13
14
  end
@@ -1,35 +1,36 @@
1
1
  module Easemob
2
+ autoload(:GroupMessage, File.expand_path('message/group_message', __dir__))
2
3
  module Groups
3
4
  def create_group(groupname, description, owner, members: nil, is_public: true, maxusers: 200, is_approval: false)
4
5
  jd = { groupname: groupname, desc: description, public: is_public, owner: owner, users: maxusers, approval: is_approval }
5
6
  jd[:members] = members unless members.nil?
6
- request :post, 'chatgroups', json: jd
7
+ GroupMessage.new request :post, 'chatgroups', json: jd
7
8
  end
8
9
 
9
10
  def get_groups(group_ids)
10
- request :get, "chatgroups/#{[*group_ids].join(',')}"
11
+ GroupMessage.new request :get, "chatgroups/#{[*group_ids].join(',')}"
11
12
  end
12
13
 
13
14
  def query_groups(limit = 50, cursor: nil)
14
15
  params = { limit: limit }
15
16
  params[:cursor] = cursor unless cursor.nil?
16
- request :get, 'chatgroups', params: params
17
+ GroupMessage.new request :get, 'chatgroups', params: params
17
18
  end
18
19
 
19
20
  def query_group_users(group_id)
20
- request :get, "chatgroups/#{group_id}/users"
21
+ GroupMessage.new request :get, "chatgroups/#{group_id}/users"
21
22
  end
22
23
 
23
24
  def query_group_blocks(group_id)
24
- request :get, "chatgroups/#{group_id}/blocks/users"
25
+ GroupMessage.new request :get, "chatgroups/#{group_id}/blocks/users"
25
26
  end
26
27
 
27
28
  def user_joined_chatgroups(username)
28
- request :get, "users/#{username}/joined_chatgroups"
29
+ GroupMessage.new request :get, "users/#{username}/joined_chatgroups"
29
30
  end
30
31
 
31
32
  def delete_group(group_id)
32
- request :delete, "chatgroups/#{group_id}"
33
+ GroupMessage.new request :delete, "chatgroups/#{group_id}"
33
34
  end
34
35
 
35
36
  def modify_group(group_id, groupname: nil, description: nil, maxusers: nil)
@@ -37,35 +38,35 @@ module Easemob
37
38
  jd[:groupname] = groupname unless groupname.nil?
38
39
  jd[:description] = description unless description.nil?
39
40
  jd[:maxusers] = maxusers unless maxusers.nil?
40
- request :put, "chatgroups/#{group_id}", json: jd
41
+ GroupMessage.new request :put, "chatgroups/#{group_id}", json: jd
41
42
  end
42
43
 
43
44
  def user_join_group(group_id, username:)
44
- request :post, "chatgroups/#{group_id}/users/#{username}"
45
+ GroupMessage.new request :post, "chatgroups/#{group_id}/users/#{username}"
45
46
  end
46
47
 
47
48
  def user_leave_group(group_id, username:)
48
- request :delete, "chatgroups/#{group_id}/users/#{username}"
49
+ GroupMessage.new request :delete, "chatgroups/#{group_id}/users/#{username}"
49
50
  end
50
51
 
51
52
  def group_add_users(group_id, usernames:)
52
- request :post, "chatgroups/#{group_id}/users", json: { usernames: [*usernames] }
53
+ GroupMessage.new request :post, "chatgroups/#{group_id}/users", json: { usernames: [*usernames] }
53
54
  end
54
55
 
55
56
  def group_remove_users(group_id, usernames:)
56
- request :delete, "chatgroups/#{group_id}/users/#{[*usernames].join(',')}"
57
+ GroupMessage.new request :delete, "chatgroups/#{group_id}/users/#{[*usernames].join(',')}"
57
58
  end
58
59
 
59
60
  def group_set_owner(group_id, newowner:)
60
- request :put, "chatgroups/#{group_id}", json: { newowner: newowner }
61
+ GroupMessage.new request :put, "chatgroups/#{group_id}", json: { newowner: newowner }
61
62
  end
62
63
 
63
64
  def add_to_group_block(group_id, to_block_usernames:)
64
- request :post, "chatgroups/#{group_id}/blocks/users", json: { usernames: [*to_block_usernames] }
65
+ GroupMessage.new request :post, "chatgroups/#{group_id}/blocks/users", json: { usernames: [*to_block_usernames] }
65
66
  end
66
67
 
67
68
  def remove_from_group_block(group_id, blocked_usernames:)
68
- request :delete, "chatgroups/#{group_id}/blocks/users/#{[*blocked_usernames].join(',')}"
69
+ GroupMessage.new request :delete, "chatgroups/#{group_id}/blocks/users/#{[*blocked_usernames].join(',')}"
69
70
  end
70
71
  end
71
72
  end
@@ -0,0 +1,51 @@
1
+ module Easemob
2
+ class BaseMessage
3
+ attr_reader :raw_http_response, :code, :body, :body_hash
4
+ attr_reader :action
5
+ attr_reader :application
6
+ attr_reader :params
7
+ attr_reader :uri
8
+ attr_reader :entities
9
+ attr_reader :data
10
+ attr_reader :timestamp
11
+ attr_reader :duration
12
+ attr_reader :organization
13
+ attr_reader :applicationName
14
+ attr_reader :cursor
15
+ attr_reader :count
16
+
17
+ def initialize(http_response)
18
+ @raw_http_response = http_response
19
+ @code = http_response.code
20
+ @body = http_response.body
21
+
22
+ return if http_response.code != 200 \
23
+ || http_response.headers['Content-Type'].index('application/octet-stream')
24
+
25
+ @body_hash = JSON.parse(http_response.body.to_s)
26
+ @action = @body_hash['action']
27
+ @application = @body_hash['application']
28
+ @params = @body_hash['params']
29
+ @uri = @body_hash['uri']
30
+ @entities = @body_hash['entities']
31
+ @data = @body_hash['data']
32
+ @timestamp = @body_hash['timestamp']
33
+ @duration = @body_hash['duration']
34
+ @organization = @body_hash['organization']
35
+ @applicationName = @body_hash['applicationName']
36
+ @cursor = @body_hash['cursor']
37
+ @count = @body_hash['count']
38
+ end
39
+
40
+ def to_s
41
+ @body.to_s
42
+ end
43
+
44
+ def inspect
45
+ "#{self.class.name}(code: #{@code}, body: #{@body}, action: #{@action},
46
+ application: #{@application}, params: #{@params}, uri: #{@uri}, entities: #{@entities},
47
+ data: #{@data}, timestamp: #{@timestamp}, duration: #{@duration}, organization: #{@organization},
48
+ applicationName: #{@applicationName}, cursor: #{@cursor}, count: #{@count})"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'base_message'
2
+
3
+ module Easemob
4
+ class ChatMessage < Easemob::BaseMessage
5
+
6
+ def all_success?
7
+ flag = true
8
+ @data.values.each{ |ar| flag = false if ar != 'success' }
9
+
10
+ flag
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'base_message'
2
+
3
+ module Easemob
4
+ class FileoperationMessage < Easemob::BaseMessage
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'base_message'
2
+
3
+ module Easemob
4
+ class GroupMessage < Easemob::BaseMessage
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ require_relative 'base_message'
2
+
3
+ module Easemob
4
+ class UserMessage < Easemob::BaseMessage
5
+ end
6
+ end
@@ -1,4 +1,5 @@
1
1
  module Easemob
2
+ autoload(:ChatMessage, File.expand_path('message/chat_message', __dir__))
2
3
  module Messages
3
4
  def message_to(target, target_type: :users, text:,
4
5
  from: nil, ext: nil)
@@ -6,7 +7,7 @@ module Easemob
6
7
  msg: { type: :txt, txt: text } }
7
8
  jd[:from] = from unless from.nil?
8
9
  jd[:ext] = ext unless ext.nil?
9
- request :post, 'messages', json: jd
10
+ ChatMessage.new request :post, 'messages', json: jd
10
11
  end
11
12
 
12
13
  def image_to(target, target_type: :users, url:, filename:,
@@ -17,7 +18,7 @@ module Easemob
17
18
  jd[:from] = from unless from.nil?
18
19
  jd[:size] = image_size unless image_size.nil?
19
20
  jd[:ext] = ext unless ext.nil?
20
- request :post, 'messages', json: jd
21
+ ChatMessage.new request :post, 'messages', json: jd
21
22
  end
22
23
 
23
24
  def audio_to(target, target_type: :users, url:, filename:, length:,
@@ -27,7 +28,7 @@ module Easemob
27
28
  jd[:msg][:secret] = secret unless secret.nil?
28
29
  jd[:from] = from unless from.nil?
29
30
  jd[:ext] = ext unless ext.nil?
30
- request :post, 'messages', json: jd
31
+ ChatMessage.new request :post, 'messages', json: jd
31
32
  end
32
33
 
33
34
  def video_to(target, target_type: :users, url:, filename:, length:, file_length:, thumb:,
@@ -39,7 +40,7 @@ module Easemob
39
40
  jd[:msg][:thumb_secret] = thumb_secret unless thumb_secret.nil?
40
41
  jd[:from] = from unless from.nil?
41
42
  jd[:ext] = ext unless ext.nil?
42
- request :post, 'messages', json: jd
43
+ ChatMessage.new request :post, 'messages', json: jd
43
44
  end
44
45
 
45
46
  def command_to(target, target_type: :users, action:,
@@ -48,7 +49,7 @@ module Easemob
48
49
  msg: { type: :cmd, action: action } }
49
50
  jd[:from] = from unless from.nil?
50
51
  jd[:ext] = ext unless ext.nil?
51
- request :post, 'messages', json: jd
52
+ ChatMessage.new request :post, 'messages', json: jd
52
53
  end
53
54
  end
54
55
  end
data/lib/easemob/token.rb CHANGED
@@ -5,7 +5,7 @@ module Easemob
5
5
  http.post "#{Easemob.head_url}/token", json: { grant_type: 'client_credentials', client_id: Easemob.client_id, client_secret: Easemob.client_secret }
6
6
  end
7
7
  raise "Failed to refresh easemob token: #{res}" unless res.code == 200
8
- write_to_store(JSON.parse(res.to_s))
8
+ write_to_store(JSON.parse(res.body.to_s))
9
9
  read_from_store
10
10
  end
11
11
 
data/lib/easemob/users.rb CHANGED
@@ -1,89 +1,90 @@
1
1
  module Easemob
2
+ autoload(:UserMessage, File.expand_path('message/user_message', __dir__))
2
3
  module Users
3
4
  def create_user(username, password, nickname: nil)
4
5
  valid_username!(username)
5
6
  jd = { username: username, password: password }
6
7
  jd[:nickname] = nickname unless nickname.nil?
7
- request :post, 'users', json: jd
8
+ UserMessage.new request :post, 'users', json: jd
8
9
  end
9
10
 
10
11
  def create_users(users)
11
12
  users.map { |user| valid_username!(user['username'] || user[:username]) }
12
- request :post, 'users', json: users
13
+ UserMessage.new request :post, 'users', json: users
13
14
  end
14
15
 
15
16
  def get_user(username)
16
- request :get, "users/#{username}"
17
+ UserMessage.new request :get, "users/#{username}"
17
18
  end
18
19
 
19
20
  def query_users(limit = 50, cursor: nil)
20
21
  params = { limit: limit }
21
22
  params[:cursor] = cursor unless cursor.nil?
22
- request :get, 'users', params: params
23
+ UserMessage.new request :get, 'users', params: params
23
24
  end
24
25
 
25
26
  def delete_user(username)
26
- request :delete, "users/#{username}"
27
+ UserMessage.new request :delete, "users/#{username}"
27
28
  end
28
29
 
29
30
  def delete_users!(number = 100)
30
- request :delete, 'users', params: { limit: number }
31
+ UserMessage.new request :delete, 'users', params: { limit: number }
31
32
  end
32
33
 
33
34
  def reset_user_password(username, newpassword:)
34
- request :put, "users/#{username}/password", json: { newpassword: newpassword }
35
+ UserMessage.new request :put, "users/#{username}/password", json: { newpassword: newpassword }
35
36
  end
36
37
 
37
38
  def set_user_nickname(username, nickname:)
38
- request :put, "users/#{username}", json: { nickname: nickname }
39
+ UserMessage.new request :put, "users/#{username}", json: { nickname: nickname }
39
40
  end
40
41
 
41
42
  def add_user_friend(owner_username, friend_username:)
42
- request :post, "users/#{owner_username}/contacts/users/#{friend_username}"
43
+ UserMessage.new request :post, "users/#{owner_username}/contacts/users/#{friend_username}"
43
44
  end
44
45
 
45
46
  def remove_user_friend(owner_username, friend_username:)
46
- request :delete, "users/#{owner_username}/contacts/users/#{friend_username}"
47
+ UserMessage.new request :delete, "users/#{owner_username}/contacts/users/#{friend_username}"
47
48
  end
48
49
 
49
50
  def query_user_friends(owner_username)
50
- request :get, "users/#{owner_username}/contacts/users"
51
+ UserMessage.new request :get, "users/#{owner_username}/contacts/users"
51
52
  end
52
53
 
53
54
  def add_to_user_block(owner_username, to_block_usernames:)
54
- request :post, "users/#{owner_username}/blocks/users", json: { usernames: [*to_block_usernames] }
55
+ UserMessage.new request :post, "users/#{owner_username}/blocks/users", json: { usernames: [*to_block_usernames] }
55
56
  end
56
57
 
57
58
  def remove_from_user_block(owner_username, blocked_username:)
58
- request :delete, "users/#{owner_username}/blocks/users/#{blocked_username}"
59
+ UserMessage.new request :delete, "users/#{owner_username}/blocks/users/#{blocked_username}"
59
60
  end
60
61
 
61
62
  def query_user_blocks(owner_username)
62
- request :get, "users/#{owner_username}/blocks/users"
63
+ UserMessage.new request :get, "users/#{owner_username}/blocks/users"
63
64
  end
64
65
 
65
66
  def get_user_status(username)
66
- request :get, "users/#{username}/status"
67
+ UserMessage.new request :get, "users/#{username}/status"
67
68
  end
68
69
 
69
70
  def get_user_offline_msg_count(owner_username)
70
- request :get, "users/#{owner_username}/offline_msg_count"
71
+ UserMessage.new request :get, "users/#{owner_username}/offline_msg_count"
71
72
  end
72
73
 
73
74
  def get_user_offline_msg_status(username, msg_id)
74
- request :get, "users/#{username}/offline_msg_status/#{msg_id}"
75
+ UserMessage.new request :get, "users/#{username}/offline_msg_status/#{msg_id}"
75
76
  end
76
77
 
77
78
  def deactivate_user(username)
78
- request :post, "users/#{username}/deactivate"
79
+ UserMessage.new request :post, "users/#{username}/deactivate"
79
80
  end
80
81
 
81
82
  def activate_user(username)
82
- request :post, "users/#{username}/activate"
83
+ UserMessage.new request :post, "users/#{username}/activate"
83
84
  end
84
85
 
85
86
  def disconnect_user(username)
86
- request :get, "users/#{username}/disconnect"
87
+ UserMessage.new request :get, "users/#{username}/disconnect"
87
88
  end
88
89
 
89
90
  private
@@ -1,3 +1,3 @@
1
1
  module Easemob
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easemob
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Guo
@@ -30,7 +30,7 @@ cert_chain:
30
30
  R5k6Ma92sW8jupX4cqbSu9rntdVQkNRpoHIrfU0MZT0cKsg/D1zMteylxrO3KMsz
31
31
  SPQRv+nrI1J0zevFqb8010heoR8SDyUA0Mm3+Q==
32
32
  -----END CERTIFICATE-----
33
- date: 2016-10-17 00:00:00.000000000 Z
33
+ date: 2016-12-05 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: http
@@ -133,6 +133,11 @@ files:
133
133
  - lib/easemob/chatrooms.rb
134
134
  - lib/easemob/fileoperation.rb
135
135
  - lib/easemob/groups.rb
136
+ - lib/easemob/message/base_message.rb
137
+ - lib/easemob/message/chat_message.rb
138
+ - lib/easemob/message/fileoperation_message.rb
139
+ - lib/easemob/message/group_message.rb
140
+ - lib/easemob/message/user_message.rb
136
141
  - lib/easemob/messages.rb
137
142
  - lib/easemob/token.rb
138
143
  - lib/easemob/users.rb
@@ -157,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
162
  version: '0'
158
163
  requirements: []
159
164
  rubyforge_project:
160
- rubygems_version: 2.6.7
165
+ rubygems_version: 2.6.8
161
166
  signing_key:
162
167
  specification_version: 4
163
168
  summary: An unofficial Easemob IM(instant message) service integration gem
metadata.gz.sig CHANGED
@@ -1,3 +1,3 @@
1
- VAg*'��>��� 9f$���(k\Ugj
2
- � �GPUKM@���Y<�LZ�bχ�r"�j;���i9!]�N��F�*rɦ, ���u����X /�X(\ ��0Wt��# [B��+���*;^�>_ހ����9��_�dt�h���ʯC󨂻`48<���
3
- �PLd�-^���B�����#��JE�}Qjƭ /ſo^�z2&
1
+ aL'��q. ���'�ŝK��m*0�ħ��'PH�'�T�7�whˀݗ��a�a������h|h���q9�Ơi3��j� #�<�QGԩL[��5��A8[�u
2
+ ��T_a=ls���4
3
+ �#�eۇ��5�ʝyw�\��F��F�bkW?>z!��D��A� �a�mэN��� -oa����c,�e�T16��OV�g�}y�E��Z�0�;0��������to†T���sb�ީ$�~�ޕfWW�����