netease_im 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58207eff418789dea17cf18e585ba834a1354348
4
+ data.tar.gz: 2d0891776917fadd1e956157a30018c5902b7d52
5
+ SHA512:
6
+ metadata.gz: 17473ad4a31ae3d38621949d6d96c1ca0246f5dea37edfd3f86469d960b5dd0a72ff205c0c55b4416c2f7812e315e0565f9e8365b0986d092d50049a62ab2698
7
+ data.tar.gz: 6ec0be8b06132f814c41be6ce691dc0c7e151f9e53e73effa12e881a3941b36afd130e89a6fd9668bb8be0c39f0f7bb73dc46a9adba16b81be5a9c162332b313
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ .ruby-version
20
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at liuliang0817@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://gems.ruby-china.org'
2
+
3
+ # Specify your gem's dependencies in netease_im.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 liuliang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # NeteaseIm
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/netease_im`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ NeteaseIM Server SDK in Ruby.
6
+
7
+ ## API文档
8
+ - 官方文档(http://dev.netease.im/docs?doc=server)
9
+
10
+ ## API接口
11
+
12
+ ### User
13
+ - create 创建云信ID
14
+ - update 云信ID更新
15
+ - refresh_token 更新并获取新token
16
+ - block 封禁云信ID
17
+ - unblock 解禁云信ID
18
+ - update_uinfo 更新用户名片
19
+ - get_uinfos 获取用户名片
20
+ - set_donnop 设置桌面端在线时,移动端是否需要推送
21
+
22
+ ### ChatRoom
23
+ - create 创建聊天室
24
+ - get 查询聊天室信息
25
+ - update 更新聊天室信息
26
+ - toggle_close_stat 修改聊天室开/关闭状态
27
+ - set_member_role 设置聊天室内用户角色
28
+ - request_addr 请求聊天室地址
29
+ - send_msg 发送聊天室消息
30
+ - add_robot 往聊天室内添加机器人
31
+ - remove_robot 从聊天室内删除机器人
32
+ - temporary_mute 设置临时禁言状态
33
+ - queue_offer 往聊天室有序队列中新加或更新元素
34
+ - queue_poll 从队列中取出元素
35
+ - queue_list 排序列出队列中所有元素
36
+ - queue_drop 删除清理整个队列
37
+ - queue_init 初始化队列
38
+ - mute_room 将聊天室整体禁言
39
+ - topn 查询聊天室统计指标TopN
40
+ - members_by_page 分页获取成员列表
41
+ - query_members 批量获取在线成员信息
42
+
43
+ ### Msg
44
+ - send_msg 发送普通消息
45
+ - send_batch_msg 批量发送点对点普通消息
46
+ - send_attach_msg 发送自定义系统通知
47
+
48
+ ### 例子
49
+ ```ruby
50
+
51
+ NeteaseIM.app_key = "abc"
52
+ NeteaseIM.app_secret = "456"
53
+ NeteaseIM.gateway = "https://api.netease.im"
54
+
55
+ NeteaseIM::User.create(accid: 'test', name: 'test')
56
+ NeteaseIM::ChatRoom.create(name: 'test')
57
+ NeteaseIM::Msg.send_msg(from: 'test', ope: 0, to: 't2', type: 0, body: {msg: 'hello'})
58
+
59
+ ```
60
+
61
+ ## Installation
62
+
63
+ Add this line to your application's Gemfile:
64
+
65
+ ```ruby
66
+ gem 'netease_im'
67
+ ```
68
+
69
+ And then execute:
70
+
71
+ $ bundle
72
+
73
+ Or install it yourself as:
74
+
75
+ $ gem install netease_im
76
+
77
+ ## Usage
78
+
79
+ TODO: Write usage instructions here
80
+
81
+ ## Development
82
+
83
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
84
+
85
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
86
+
87
+ ## Contributing
88
+
89
+ Bug reports and pull requests are welcome on GitHub at https://github.com/liuliang/netease_im. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
90
+
91
+
92
+ ## License
93
+
94
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
95
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
3
+ task :console do
4
+ exec "irb -r netease_im -I ./lib"
5
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "netease_im"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+ module NeteaseIM
3
+ class ChatRoom
4
+
5
+ def self.create(params)
6
+ Utils.check_required_params(params, %w(creator name))
7
+ Request.send_sync('chatroom/create.action', params)
8
+ end
9
+
10
+ def self.get(params)
11
+ Utils.check_required_params(params, %w(roomid))
12
+ Request.send_sync('chatroom/get.action', params)
13
+ end
14
+
15
+ def update(params)
16
+ Utils.check_required_params(params, %w(roomid))
17
+ Request.send_sync('chatroom/update.action', params)
18
+ end
19
+
20
+ def toggle_close_stat(params)
21
+ Utils.check_required_params(params, %w(roomid operator valid))
22
+ Request.send_sync('chatroom/toggleCloseStat.action', params)
23
+ end
24
+
25
+ def set_member_role(params)
26
+ Utils.check_required_params(params, %w(roomid operator target opt optvalue))
27
+ Request.send_sync('chatroom/setMemberRole.action', params)
28
+ end
29
+
30
+ def request_addr(params)
31
+ Utils.check_required_params(params, %w(roomid accid))
32
+ Request.send_sync('chatroom/requestAddr.action', params)
33
+ end
34
+
35
+ def send_msg(params)
36
+ Utils.check_required_params(params, %w(roomid msgId fromAccid msgType))
37
+ Request.send_sync('chatroom/sendMsg.action', params)
38
+ end
39
+
40
+ def add_robot(params)
41
+ Utils.check_required_params(params, %w(roomid accids))
42
+ Request.send_sync('chatroom/addRobot.action', params)
43
+ end
44
+
45
+ def remove_robot(params)
46
+ Utils.check_required_params(params, %w(roomid accids))
47
+ Request.send_sync('chatroom/removeRobot.action', params)
48
+ end
49
+
50
+ def temporary_mute(params)
51
+ Utils.check_required_params(params, %w(roomid operator target muteDuration))
52
+ Request.send_sync('chatroom/temporaryMute.action', params)
53
+ end
54
+
55
+ def queue_offer(params)
56
+ Utils.check_required_params(params, %w(roomid key value))
57
+ Request.send_sync('chatroom/queueOffer.action', params)
58
+ end
59
+
60
+ def queue_poll(params)
61
+ Utils.check_required_params(params, %w(roomid))
62
+ Request.send_sync('chatroom/queueOffer.action', params)
63
+ end
64
+
65
+ def queue_list(params)
66
+ Utils.check_required_params(params, %w(roomid))
67
+ Request.send_sync('chatroom/queueList.action', params)
68
+ end
69
+
70
+ def queue_drop(params)
71
+ Utils.check_required_params(params, %w(roomid))
72
+ Request.send_sync('chatroom/queueDrop.action', params)
73
+ end
74
+
75
+ def queue_init(params)
76
+ Utils.check_required_params(params, %w(roomid sizeLimit))
77
+ Request.send_sync('chatroom/queueInit.action', params)
78
+ end
79
+
80
+ def mute_room(params)
81
+ Utils.check_required_params(params, %w(roomid operator mute))
82
+ Request.send_sync('chatroom/muteRoom.action', params)
83
+ end
84
+
85
+ def topn(params)
86
+ Utils.check_required_params(params, %w(topn))
87
+ Request.send_sync('chatroom/topn.action', params)
88
+ end
89
+
90
+ def members_by_page(params)
91
+ Utils.check_required_params(params, %w(roomid type endtime limit))
92
+ Request.send_sync('chatroom/membersByPage.action', params)
93
+ end
94
+
95
+ def query_members(params)
96
+ Utils.check_required_params(params, %w(roomid accids))
97
+ Request.send_sync('chatroom/queryMembers.action', params)
98
+ end
99
+
100
+ end
101
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ module NeteaseIM
3
+ class Msg
4
+
5
+ def self.send_msg(params)
6
+ Utils.check_required_params(params, %w(from ope to type body))
7
+ Request.send_sync('msg/sendMsg.action', params)
8
+ end
9
+
10
+ def self.send_batch_msg(params)
11
+ Utils.check_required_params(params, %w(fromAccid toAccids type body))
12
+ Request.send_sync('msg/sendBatchMsg.action', params)
13
+ end
14
+
15
+ def self.send_attach_msg(params)
16
+ Utils.check_required_params(params, %w(from msgtype to attach))
17
+ Request.send_sync('msg/sendAttachMsg.action', params)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module NeteaseIM
2
+ class Request
3
+
4
+ def self.send_sync(action, params)
5
+ headers = {
6
+ AppKey: NeteaseIM.app_key,
7
+ Nonce: SecureRandom.hex,
8
+ CurTime: Time.now.to_i,
9
+ content_type: 'Content-Type: application/x-www-form-urlencoded'
10
+ }
11
+ headers[:CheckSum] = Digest::SHA1.hexdigest "#{NeteaseIM.app_secret}#{headers[:Nonce]}#{headers[:CurTime]}"
12
+ JSON.parse RestClient.post("#{NeteaseIM.gateway}/nimserver/#{action}", params, headers)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ module NeteaseIM
3
+ class User
4
+
5
+ def self.create(params)
6
+ Utils.check_required_params(params, %w(accid))
7
+ Request.send_sync('user/create.action', params)
8
+ end
9
+
10
+ def self.update(params)
11
+ Utils.check_required_params(params, %w(accid))
12
+ Request.send_sync('user/update.action', params)
13
+ end
14
+
15
+ def refresh_token(params)
16
+ Utils.check_required_params(params, %w(accid))
17
+ Request.send_sync('user/refreshToken.action', params)
18
+ end
19
+
20
+ def block(params)
21
+ Utils.check_required_params(params, %w(accid))
22
+ Request.send_sync('user/block.action', params)
23
+ end
24
+
25
+ def unblock(params)
26
+ Utils.check_required_params(params, %w(accid))
27
+ Request.send_sync('user/unblock.action', params)
28
+ end
29
+
30
+ def update_uinfo(params)
31
+ Utils.check_required_params(params, %w(accid))
32
+ Request.send_sync('user/updateUinfo.action', params)
33
+ end
34
+
35
+ def get_uinfos(params)
36
+ Utils.check_required_params(params, %w(accids))
37
+ Request.send_sync('user/getUinfos.action', params)
38
+ end
39
+
40
+ def set_donnop(params)
41
+ Utils.check_required_params(params, %w(accid))
42
+ Request.send_sync('user/setDonnop.action', params)
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ module NeteaseIM
2
+ module Utils
3
+ def self.check_required_params(params, names)
4
+ missing_params = names.map(&:to_s) - params.keys.map(&:to_s)
5
+ warn("Warn: missing required option: #{missing_params.join(',')}") if missing_params.size > 0
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module NeteaseIM
2
+ VERSION = "0.1.0"
3
+ end
data/lib/netease_im.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'rest-client'
2
+ require 'digest/sha1'
3
+ require 'securerandom'
4
+ require "netease_im/version"
5
+ require 'netease_im/utils'
6
+ require 'netease_im/request'
7
+ require 'netease_im/user'
8
+ require 'netease_im/chat_room'
9
+ require 'netease_im/msg'
10
+
11
+ module NeteaseIM
12
+ class << self
13
+ attr_accessor :app_key, :app_secret, :gateway
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'netease_im/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "netease_im"
8
+ spec.version = NeteaseIM::VERSION
9
+ spec.authors = ["liuliang"]
10
+ spec.email = ["liuliang0817@gmail.com"]
11
+
12
+ spec.summary = %q{网易IM服务端接口.}
13
+ spec.description = %q{网易IM服务端接口.}
14
+ spec.homepage = "https://github.com/liuliang/netease_im"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.4"
27
+ spec.add_development_dependency "rest-client", "~> 1.8"
28
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netease_im
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - liuliang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ description: 网易IM服务端接口.
70
+ email:
71
+ - liuliang0817@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/netease_im.rb
86
+ - lib/netease_im/chat_room.rb
87
+ - lib/netease_im/msg.rb
88
+ - lib/netease_im/request.rb
89
+ - lib/netease_im/user.rb
90
+ - lib/netease_im/utils.rb
91
+ - lib/netease_im/version.rb
92
+ - netease_im.gemspec
93
+ homepage: https://github.com/liuliang/netease_im
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: 网易IM服务端接口.
117
+ test_files: []