baichuan 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/baichuan.gemspec +23 -0
- data/lib/baichuan.rb +228 -0
- data/lib/baichuan/version.rb +3 -0
- metadata +80 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6ddccfe27a7a015f6bb00cb135eccf121b933c6b
|
|
4
|
+
data.tar.gz: c8f65dd2380b4c1b068f65dfcfd7ac28f6e2babb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 29dfd91d6b58b223a88e59279b470449e56b159cf10fe5dc8beae9f12d69c50dde5e576935dba8174f9e4f610a3369a3617e9c00de50d56d88fc925b4e909cbb
|
|
7
|
+
data.tar.gz: 3d65c730ef50aed338dfd7961bbf58a5188b0488fb7c389ddbf907a6a34a21040aa953d42ed185cb9da5d29d21bbb091fca207a9907e0915f761bbcb2747f7cd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2016 Star
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Baichuan
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'baichuan'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install baichuan
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
TODO: Write usage instructions here
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/baichuan/fork )
|
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/baichuan.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'baichuan/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "baichuan"
|
|
8
|
+
spec.version = Baichuan::VERSION
|
|
9
|
+
spec.authors = ["Star"]
|
|
10
|
+
spec.email = ["137379612@qq.com"]
|
|
11
|
+
spec.summary = %q{baichuan wrapper for taobao.}
|
|
12
|
+
spec.description = %q{baichuan wrapper for taobao.}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
23
|
+
end
|
data/lib/baichuan.rb
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
require "baichuan/version"
|
|
2
|
+
require "net/http"
|
|
3
|
+
|
|
4
|
+
module Baichuan
|
|
5
|
+
class Client
|
|
6
|
+
|
|
7
|
+
ACTION_ADD_USERS = 'taobao.openim.users.add'
|
|
8
|
+
ACTION_GET_USERS = 'taobao.openim.users.get'
|
|
9
|
+
ACTION_UPDATE_USERS = 'taobao.openim.users.update'
|
|
10
|
+
ACTION_DELETE_USERS = 'taobao.openim.users.delete'
|
|
11
|
+
|
|
12
|
+
ACTION_CUSTMSG_PUSH = 'taobao.openim.custmsg.push'
|
|
13
|
+
ACTION_IMMSG_PUSH = 'taobao.openim.immsg.push'
|
|
14
|
+
ACTION_SEND_GROUP_MSG = 'taobao.openim.tribe.sendmsg'
|
|
15
|
+
|
|
16
|
+
ACTION_GET_RELATIONS = 'taobao.openim.relations.get'
|
|
17
|
+
ACTION_GET_CHATLOGS = 'taobao.openim.chatlogs.get'
|
|
18
|
+
|
|
19
|
+
ACTION_CREATE_GROUP = 'taobao.openim.tribe.create'
|
|
20
|
+
ACTION_GET_GROUP = 'taobao.openim.tribe.gettribeinfo'
|
|
21
|
+
ACTION_JOIN_GROUP = 'taobao.openim.tribe.join'
|
|
22
|
+
ACTION_INVITE_GROUP = 'taobao.openim.tribe.invite'
|
|
23
|
+
ACTION_QUIT_GROUP = 'taobao.openim.tribe.quit'
|
|
24
|
+
ACTION_EXPEL_GROUP = 'taobao.openim.tribe.expel'
|
|
25
|
+
ACTION_DISMISS_GROUP = 'taobao.openim.tribe.dismiss'
|
|
26
|
+
ACTION_SET_MANAGER = 'taobao.openim.tribe.setmanager'
|
|
27
|
+
ACTION_GET_MEMBERS = 'taobao.openim.tribe.getmembers'
|
|
28
|
+
ACTION_UNSET_MANAGER = 'taobao.openim.tribe.unsetmanager'
|
|
29
|
+
ACTION_GET_ALL_GROUPS = 'taobao.openim.tribe.getalltribes'
|
|
30
|
+
ACTION_UPDATE_GROUP = 'taobao.openim.tribe.modifytribeinfo'
|
|
31
|
+
ACTION_SET_MEMBER_NICK = 'taobao.openim.tribe.setmembernick'
|
|
32
|
+
|
|
33
|
+
ACTION_IMPORT_CHAT_LOGS = 'taobao.openim.chatlogs.import'
|
|
34
|
+
ACTION_IMPORT_GROUP_LOGS = 'taobao.openim.tribelogs.import'
|
|
35
|
+
ACTION_GET_GROUP_LOGS = 'taobao.openim.tribelogs.get'
|
|
36
|
+
ACTION_GET_APP_CHAT_LOGS = 'taobao.openim.app.chatlogs.get'
|
|
37
|
+
|
|
38
|
+
ACTION_GET_DETAILS = 'taobao.openim.track.getdetails'
|
|
39
|
+
ACTION_GET_SUMMARY = 'taobao.openim.track.getsummary'
|
|
40
|
+
|
|
41
|
+
def initialize(app_key, secret, sandbox = false)
|
|
42
|
+
@version = 1.0
|
|
43
|
+
@api_host = sandbox ? 'https://gw.api.tbsandbox.com/router/rest' : 'https://eco.taobao.com/router/rest'
|
|
44
|
+
@app_key = app_key || ENV['app_key']
|
|
45
|
+
@secret = secret || ENV['secret']
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def make_signature(params)
|
|
49
|
+
Digest::MD5.hexdigest("#{@secret}#{params.sort.join}#{@secret}").upcase
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def header
|
|
53
|
+
{
|
|
54
|
+
'User-Agent' => 'BaiChuanSdk/BaiChuan-Ruby-Sdk #{RUBY_VERSION} (#{@version})',
|
|
55
|
+
'Content-Type' => 'application/x-www-form-urlencoded;charset=utf-8'
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def common_params(action)
|
|
60
|
+
{
|
|
61
|
+
method: action,
|
|
62
|
+
app_key: @app_key,
|
|
63
|
+
timestamp: Time.now.strftime('%Y-%m-%d %H:%M:%S'),
|
|
64
|
+
format: 'json',
|
|
65
|
+
v: '2.0',
|
|
66
|
+
sign_method: 'md5'
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def http_call(url, data)
|
|
71
|
+
uri = URI.parse(url)
|
|
72
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
73
|
+
http.use_ssl = uri.scheme == 'https'
|
|
74
|
+
http.ssl_version = :TLSv1
|
|
75
|
+
# http.ciphers = ['RC4-SHA']
|
|
76
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
77
|
+
req = Net::HTTP::Post.new(uri.path, initheader = header)
|
|
78
|
+
req.body = URI.encode_www_form(data)
|
|
79
|
+
res = http.request(req)
|
|
80
|
+
response_object(JSON.parse(res.body))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def response_object(body)
|
|
84
|
+
response = Struct.new(:success, :data).new
|
|
85
|
+
response.success = !body.has_key?('error_response')
|
|
86
|
+
response.data = body
|
|
87
|
+
response
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def post(action, params)
|
|
91
|
+
params = common_params(action).merge(params)
|
|
92
|
+
params.merge!(sign: make_signature(params))
|
|
93
|
+
http_call(@api_host, params)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def cust_msg_push(cust_msg)
|
|
97
|
+
post( ACTION_CUSTMSG_PUSH, { custmsg: cust_msg.to_json } )
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def im_msg_push(im_msg)
|
|
101
|
+
post( ACTION_IMMSG_PUSH, { immsg: im_msg.to_json } )
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def add_users(userinfos)
|
|
105
|
+
post( ACTION_ADD_USERS, { userinfos: userinfos.to_json } )
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def get_users(user_ids)
|
|
109
|
+
post( ACTION_GET_USERS, { userids: user_ids.join(',') } )
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def update_users(userinfos)
|
|
113
|
+
post( ACTION_UPDATE_USERS, { userinfos: userinfos.to_json } )
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def delete_users(user_ids)
|
|
117
|
+
post( ACTION_DELETE_USERS, { userids: user_ids.join(',') } )
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def get_relations(user, beg_date, end_date)
|
|
121
|
+
post( ACTION_GET_RELATIONS, { user: user, beg_date: beg_date, end_date: end_date })
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def send_group_msg(member, group_id, msg)
|
|
125
|
+
post( ACTION_SEND_GROUP_MSG, { user: member, tribe_id: group_id, msg: msg })
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def create_group(master, group_name, notice, members, tribe_type = 1)
|
|
129
|
+
post( ACTION_CREATE_GROUP, { user: master,
|
|
130
|
+
tribe_name: group_name,
|
|
131
|
+
notice: notice,
|
|
132
|
+
members: members,
|
|
133
|
+
tribe_type: tribe_type
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def invite_group(master, group_id, members)
|
|
139
|
+
post( ACTION_INVITE_GROUP, { tribe_id: group_id,
|
|
140
|
+
user: master,
|
|
141
|
+
members: members
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def join_group(member, group_id)
|
|
147
|
+
post( ACTION_JOIN_GROUP, { user: member, tribe_id: group_id } )
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def expel_group(user, group_id, member)
|
|
151
|
+
post( ACTION_EXPEL_GROUP, { tribe_id: group_id,
|
|
152
|
+
user: user,
|
|
153
|
+
member: member
|
|
154
|
+
}
|
|
155
|
+
)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def quit_group(member, group_id)
|
|
159
|
+
post( ACTION_QUIT_GROUP, { tribe_id: group_id, user: member } )
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def dismiss_group(master, group_id)
|
|
163
|
+
post( ACTION_DISMISS_GROUP, { tribe_id: group_id, user: master } )
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def get_group(master, group_id)
|
|
167
|
+
post( ACTION_GET_GROUP, { tribe_id: group_id, user: master } )
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def update_group(master, group_id, group_name, notice)
|
|
171
|
+
post( ACTION_UPDATE_GROUP, { tribe_id: group_id,
|
|
172
|
+
tribe_name: group_name,
|
|
173
|
+
notice: notice,
|
|
174
|
+
user: master
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def set_manager(master, group_id, member)
|
|
180
|
+
post( ACTION_SET_MANAGER, { user: master, tid: group_id, member: member } )
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def unset_manager(master, group_id, member)
|
|
184
|
+
post( ACTION_UNSET_MANAGER, { user: master, tid: group_id, member: member } )
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def get_group_members(member, group_id)
|
|
188
|
+
post( ACTION_GET_MEMBERS, { user: member, tribe_id: group_id } )
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def get_all_group(user, group_types = [0])
|
|
192
|
+
post( ACTION_GET_ALL_GROUP, { user: user, tribe_types: group_types } )
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def set_member_nick(user, group_id, member, nick)
|
|
196
|
+
post( ACTION_SET_MEMBER_NICK, { user: user,
|
|
197
|
+
tribe_id: group_id,
|
|
198
|
+
member: member,
|
|
199
|
+
nick: nick
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def get_group_logs(group_id, begin_time, end_time, count)
|
|
205
|
+
post( ACTION_GET_GROUP_LOGS, { tribe_id: group_id, begin: begin_time, end: end_time, count: count } )
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def import_group_logs(group_id, messages)
|
|
209
|
+
post( ACTION_IMPORT_GROUP_LOGS, { tribe_id: group_id, messages: messages } )
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def import_chat_logs(messages)
|
|
213
|
+
post( ACTION_IMPORT_CHAT_LOGS, { messages: messages } )
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def get_details(im_id, start_time, end_time)
|
|
217
|
+
post( ACTION_GET_DETAILS, { uid: im_id, starttime: start_time, endtime: end_time } )
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def get_summary(im_id)
|
|
221
|
+
post( ACTION_GET_SUMMARY, { uid: im_id } )
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def get_app_chat_logs(begin_time, end_time, count)
|
|
225
|
+
post( ACTION_GET_APP_CHAT_LOGS, { beg: begin_time, end: end_time, count: count } )
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: baichuan
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1.0'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Star
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-07-31 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.7'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.7'
|
|
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
|
+
description: baichuan wrapper for taobao.
|
|
42
|
+
email:
|
|
43
|
+
- 137379612@qq.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- Gemfile
|
|
50
|
+
- LICENSE.txt
|
|
51
|
+
- README.md
|
|
52
|
+
- Rakefile
|
|
53
|
+
- baichuan.gemspec
|
|
54
|
+
- lib/baichuan.rb
|
|
55
|
+
- lib/baichuan/version.rb
|
|
56
|
+
homepage: ''
|
|
57
|
+
licenses:
|
|
58
|
+
- MIT
|
|
59
|
+
metadata: {}
|
|
60
|
+
post_install_message:
|
|
61
|
+
rdoc_options: []
|
|
62
|
+
require_paths:
|
|
63
|
+
- lib
|
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
requirements: []
|
|
75
|
+
rubyforge_project:
|
|
76
|
+
rubygems_version: 2.4.5
|
|
77
|
+
signing_key:
|
|
78
|
+
specification_version: 4
|
|
79
|
+
summary: baichuan wrapper for taobao.
|
|
80
|
+
test_files: []
|