yx_sdk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/yx_sdk.rb +46 -0
- data/lib/yx_sdk/api/user.rb +19 -0
- data/lib/yx_sdk/client.rb +31 -0
- data/lib/yx_sdk/config.rb +24 -0
- data/lib/yx_sdk/handler/result_handler.rb +27 -0
- data/lib/yx_sdk/version.rb +3 -0
- data/yx_sdk.gemspec +33 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9128faf55adb0188c7bc1515f0c85f5975c0893a
|
4
|
+
data.tar.gz: e036887c4311eef00c5442ca26e9fb13a9243c96
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8be797917e6c12ccf1ac9a6e478ee759e78e4e4290448a887d1c04d3a888f085daa5aee94d8f634dfbe86d0b0c3e28a067c93299c88cc76177ed9b1c1854ba2
|
7
|
+
data.tar.gz: 0219a4ea5c35e966943a4ea16116589f53baf918f3d82d5ae75fdcbe467b954fd6ff6ca8add027ed44a9c2601dbd21a802051697a1bbdde0fce9528f50c1bd73
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 karidyang
|
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,44 @@
|
|
1
|
+
# YxSdk
|
2
|
+
|
3
|
+
网易云信的Server端SDK
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'yx_sdk'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install yx_sdk
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
1. 同步账号
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
$client = YxSdk::Client.new(appkey, appsecrt)
|
27
|
+
$client.
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
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).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/yx_sdk.
|
39
|
+
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
44
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yx_sdk"
|
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
data/lib/yx_sdk.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "yx_sdk/version"
|
2
|
+
require "rest-client"
|
3
|
+
|
4
|
+
module YxSdk
|
5
|
+
|
6
|
+
DEFAULT_CODE = 200
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def http_post_without_token(url, post_body={}, url_params={}, header = {}, endpoint="plain")
|
11
|
+
post_api_url = endpoint_url(endpoint, url)
|
12
|
+
if endpoint == "plain" || endpoint == CUSTOM_ENDPOINT
|
13
|
+
post_body = JSON.dump(post_body)
|
14
|
+
end
|
15
|
+
load_json(resource(post_api_url, header).post(post_body, params: url_params))
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def resource(url, header)
|
20
|
+
RestClient::Resource.new(url, header)
|
21
|
+
end
|
22
|
+
|
23
|
+
# return hash
|
24
|
+
def load_json(string)
|
25
|
+
result_hash = JSON.parse(string.force_encoding("UTF-8").gsub(/[\u0011-\u001F]/, ""))
|
26
|
+
code = result_hash.delete("code")
|
27
|
+
info = result_hash.delete("info")
|
28
|
+
ResultHandler.new(code, info)
|
29
|
+
end
|
30
|
+
|
31
|
+
def endpoint_url(endpoint, url)
|
32
|
+
send("#{endpoint}_endpoint") + url
|
33
|
+
end
|
34
|
+
|
35
|
+
def plain_endpoint
|
36
|
+
"#{api_endpoint}/nimserver"
|
37
|
+
end
|
38
|
+
|
39
|
+
def api_endpoint
|
40
|
+
"https://api.netease.im"
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module YxSdk
|
2
|
+
|
3
|
+
module Api
|
4
|
+
module User
|
5
|
+
#同步创建
|
6
|
+
def create(id, name, icon, token)
|
7
|
+
user_info_url = "#{user_base_url}/create.action"
|
8
|
+
http_post(user_info_url, {accid: id, name: name, icon: icon, token: token})
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def user_base_url
|
14
|
+
"/user"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module YxSdk
|
2
|
+
class Client
|
3
|
+
attr_accessor app_key, app_secret
|
4
|
+
|
5
|
+
def initialize(app_key, app_secret, options={})
|
6
|
+
@app_key = app_key
|
7
|
+
@app_secret = app_secret
|
8
|
+
super()
|
9
|
+
end
|
10
|
+
|
11
|
+
# 暴露出:http_get,http_post两个方法,方便第三方开发者扩展未开发的微信API。
|
12
|
+
def http_post(url, post_body={}, url_params={}, endpoint="plain")
|
13
|
+
# url_params = url_params.merge(access_token_param)
|
14
|
+
YxSdk.http_post_without_token(url, post_body, url_params, get_header, endpoint)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_header
|
18
|
+
timestamp = Time.now.to_i
|
19
|
+
noncestr = SecureRandom.hex(16)
|
20
|
+
str = "#{AppSecret}#{noncestr}#{timestamp}"
|
21
|
+
signature = Digest::SHA1.hexdigest(str)
|
22
|
+
{
|
23
|
+
"AppKey" => @app_key,
|
24
|
+
"Nonce" => noncestr,
|
25
|
+
"CurTime" => timestamp,
|
26
|
+
"CheckSum" => signature,
|
27
|
+
"Content-Type" => "application/x-www-form-urlencoded;charset=utf-8"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module YxSdk
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :config
|
5
|
+
|
6
|
+
def configure
|
7
|
+
yield self.config ||= Config.new
|
8
|
+
end
|
9
|
+
|
10
|
+
# 可选配置: RestClient timeout, etc.
|
11
|
+
# key 必须是符号
|
12
|
+
# 如果出现 RestClient::SSLCertificateNotVerified Exception: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
|
13
|
+
# 这个错,除了改 verify_ssl: true,请参考:http://www.extendi.it/blog/2015/5/23/47-sslv3-read-server-certificate-b-certificate-verify-failed
|
14
|
+
def rest_client_options
|
15
|
+
if config.nil?
|
16
|
+
return {timeout: 5, open_timeout: 5, verify_ssl: true}
|
17
|
+
end
|
18
|
+
config.rest_client_options
|
19
|
+
end
|
20
|
+
end
|
21
|
+
class Config
|
22
|
+
attr_accessor :rest_client_options
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module YxSdk
|
2
|
+
class ResultHandler
|
3
|
+
attr_accessor :code, :result
|
4
|
+
|
5
|
+
def initialize(code, result = {})
|
6
|
+
@code = code || DEFAULT_CODE
|
7
|
+
@result = package_result(result)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# if define Rails constant
|
13
|
+
# result = WeixinAuthorize::ResultHandler.new("0", "success", {:ok => "true"})
|
14
|
+
# result.result["ok"] #=> true
|
15
|
+
# result.result[:ok] #=> true
|
16
|
+
# result.result['ok'] #=> true
|
17
|
+
def package_result(result)
|
18
|
+
return result unless result.is_a?(Hash)
|
19
|
+
if defined?(Rails)
|
20
|
+
ActiveSupport::HashWithIndifferentAccess.new(result)
|
21
|
+
else
|
22
|
+
result
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
data/yx_sdk.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yx_sdk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yx_sdk"
|
8
|
+
spec.version = YxSdk::VERSION
|
9
|
+
spec.authors = ["karidyang"]
|
10
|
+
spec.email = ["karidyang@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{netease.im server sdk}
|
13
|
+
spec.description = %q{netease.im server sdk}
|
14
|
+
spec.homepage = "http://github.com/karidyang/yx_sdk"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yx_sdk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- karidyang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-21 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: netease.im server sdk
|
56
|
+
email:
|
57
|
+
- karidyang@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/yx_sdk.rb
|
72
|
+
- lib/yx_sdk/api/user.rb
|
73
|
+
- lib/yx_sdk/client.rb
|
74
|
+
- lib/yx_sdk/config.rb
|
75
|
+
- lib/yx_sdk/handler/result_handler.rb
|
76
|
+
- lib/yx_sdk/version.rb
|
77
|
+
- yx_sdk.gemspec
|
78
|
+
homepage: http://github.com/karidyang/yx_sdk
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.6.8
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: netease.im server sdk
|
102
|
+
test_files: []
|