yuntongxun_api 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a7e8859ef4c24e7fa089d55b4f548fe75803878c
4
+ data.tar.gz: d27bccf99d5f5717f8014eaa0ba9482769bcce01
5
+ SHA512:
6
+ metadata.gz: 3251269785a67ab38019572526636d242a0a870d9b4abe5bc76547e2721f5a7fb6af91405fede94bf3c090d627fda7ba34e5663528b6d92f95f37f9a84702346
7
+ data.tar.gz: d32e21a10967e17f8287f27eacf59d0fcaca04a967e7256824c6c30d66891e5e096d6030da82a944751f921c7003b2db1c6a8387bc2161e7d1693c6c7e5aa605
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yuntongxun_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 skji
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,112 @@
1
+ # YunTongXun Api
2
+
3
+ 容联·云通讯SDK for Ruby
4
+
5
+ DONE: 短信
6
+ DONE: 语音验证码
7
+ DONE: 电话回拨
8
+ DONE: 外呼通知
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'yuntongxun_api'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install yuntongxun_api
25
+
26
+ ## Usage
27
+
28
+ ### Setting
29
+
30
+ Create `config\initializers\yuntongxun.rb`
31
+
32
+ ```ruby
33
+ YunTongXun.setup do |config|
34
+ config.server = 'https://app.cloopen.com:8883'
35
+ config.account_sid = ''
36
+ config.auth_token = ''
37
+ config.version = '2013-12-26'
38
+ end
39
+ ```
40
+
41
+ ### SMS
42
+
43
+ ```ruby
44
+ params = {
45
+ to: '',
46
+ appId: '',
47
+ templateId: '',
48
+ datas: '',
49
+ }
50
+
51
+ YunTongXun::Sms.send(params)
52
+ ```
53
+
54
+ ### 语音验证
55
+
56
+ ```ruby
57
+ params = {
58
+ to: '',
59
+ appId: '',
60
+ verifyCode: '',
61
+ }
62
+
63
+ YunTongXun::Voice.voice_verify(params)
64
+ ```
65
+
66
+ ### 电话回拨
67
+
68
+ ```ruby
69
+ params = {
70
+ from: '',
71
+ to: ''
72
+ }
73
+
74
+ YunTongXun::Voice.double_call(params)
75
+ ```
76
+
77
+ ### 取消回拨
78
+
79
+ ```ruby
80
+ params = {
81
+ appId: '',
82
+ callSid: '',
83
+ type: '',
84
+ }
85
+
86
+ YunTongXun::Voice.cancel_call(params)
87
+ ```
88
+
89
+ ### 取消回拨
90
+
91
+ ```ruby
92
+ params = {
93
+ appId: '',
94
+ to: '',
95
+ }
96
+
97
+ YunTongXun::Voice.landing_call(params)
98
+ ```
99
+
100
+
101
+ ## Contributing
102
+
103
+ 1. [Fork it](https://github.com/skji/yuntongxun_api/fork)
104
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
105
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
106
+ 4. Push to the branch (`git push origin my-new-feature`)
107
+ 5. Create a new Pull Request
108
+
109
+ ## License
110
+
111
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
112
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yuntongxun_api"
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,41 @@
1
+ # coding: utf-8
2
+ module YunTongXun
3
+ class Configuration
4
+ # API请求地址分为正式(http/https)和沙箱(http/https)共四个地址
5
+ # 正式-http: http://app.cloopen.com:8883
6
+ # 正式-https: https://app.cloopen.com:8883
7
+ # 沙箱-http: http://sandboxapp.cloopen.com:8883
8
+ # 沙箱-https: https://sandboxapp.cloopen.com:8883
9
+ def server
10
+ @server ||= 'https://app.cloopen.com:8883'
11
+ end
12
+
13
+ def server=(server)
14
+ @server = server
15
+ end
16
+
17
+ def account_sid
18
+ @account_sid ||= 'your_account_sid'
19
+ end
20
+
21
+ def account_sid=(account_sid)
22
+ @account_sid = account_sid
23
+ end
24
+
25
+ def auth_token
26
+ @auth_token ||= 'your_auth_token'
27
+ end
28
+
29
+ def auth_token=(auth_token)
30
+ @auth_token = auth_token
31
+ end
32
+
33
+ def version
34
+ @version ||= 'version'
35
+ end
36
+
37
+ def version=(version)
38
+ @version = version
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,56 @@
1
+ # coding: utf-8
2
+ require "json"
3
+ require 'digest'
4
+ require 'base64'
5
+ require 'net/http'
6
+ require 'net/https'
7
+
8
+ module YunTongXun
9
+ module Helper
10
+ # 获得响应结果
11
+ def get_response(params)
12
+ uri = URI.parse(url)
13
+ https = Net::HTTP.new(uri.host, uri.port)
14
+ https.use_ssl = true
15
+ request = Net::HTTP::Post.new(url, headers)
16
+ request.body = params.to_json
17
+ response = https.request(request)
18
+
19
+ YunTongXun.logger.info response.body
20
+ return JSON.parse(response.body)
21
+ end
22
+
23
+ private
24
+ def url
25
+ "#{YunTongXun.config.server}/#{YunTongXun.config.version}/#{@accounts}/#{YunTongXun.config.account_sid}/#{@method}?sig=#{sign}"
26
+ end
27
+
28
+ def sign
29
+ # REST API 验证参数,生成规则如下
30
+ # 1.使用MD5加密(账户Id + 账户授权令牌 + 时间戳)。其中账户Id和账户授权令牌根据url的验证级别对应主账户。
31
+ # 时间戳是当前系统时间,格式"yyyyMMddHHmmss"。时间戳有效时间为24小时,如:20140416142030
32
+ # 2.SigParameter参数需要大写,如不能写成sig=abcdefg而应该写成sig=ABCDEFG
33
+ Digest::MD5.hexdigest(YunTongXun.config.account_sid + YunTongXun.config.auth_token + timestamp).upcase
34
+ end
35
+
36
+ def headers
37
+ # Accept String必选客户端响应接收数据格式:application/xml、application/json
38
+ # Content-Type String必选类型:application/xml;charset=utf-8、application/json;charset=utf-8
39
+ # Content-Length String必选Content-Length
40
+ # Authorization String 必选 验证信息,生成规则详见下方说明
41
+ # 1.使用Base64编码(账户Id + 冒号 + 时间戳)其中账户Id根据url的验证级别对应主账户
42
+ # 2.冒号为英文冒号
43
+ # 3.时间戳是当前系统时间,格式"yyyyMMddHHmmss",需与SigParameter中时间戳相同。
44
+ {
45
+ 'Accept' => 'application/json',
46
+ 'Content-Type' => 'application/json;charset=utf-8',
47
+ 'Authorization' => Base64.strict_encode64(YunTongXun.config.account_sid + ':' + timestamp)
48
+ }
49
+ end
50
+
51
+ def timestamp
52
+ Time.now.strftime("%Y%m%d%H%M%S")
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+ module YunTongXun
3
+ module Sms
4
+ class << self
5
+ include YunTongXun::Helper
6
+
7
+ @accounts = 'Accounts'
8
+
9
+ # 短信发送
10
+ def send(params)
11
+ @method = 'SMS/TemplateSMS'
12
+ response = get_response(params)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module YunTongXun
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ module YunTongXun
3
+ module Voice
4
+ class << self
5
+ include YunTongXun::Helper
6
+
7
+ # 语音验证
8
+ def voice_verify(params)
9
+ @accounts = 'Accounts'
10
+ @method = 'Calls/VoiceVerify'
11
+
12
+ response = get_response(params)
13
+ end
14
+
15
+ # 电话回拨
16
+ def double_call(params)
17
+ @accounts = 'SubAccounts'
18
+ @method = 'Calls/Callback'
19
+
20
+ response = get_response(params)
21
+ end
22
+
23
+ # 取消回拨
24
+ def cancel_call(params)
25
+ @accounts = 'Accounts'
26
+ @method = 'Calls/CallCancel'
27
+
28
+ response = get_response(params)
29
+ end
30
+
31
+ # 外呼通知
32
+ def landing_call(params)
33
+ @accounts = 'Accounts'
34
+ @method = 'Calls/LandingCalls'
35
+
36
+ response = get_response(params)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ require "yuntongxun_api/version"
2
+ require "yuntongxun_api/configuration"
3
+ require "yuntongxun_api/helper"
4
+ require "yuntongxun_api/sms"
5
+ require "yuntongxun_api/voice"
6
+ require "logger"
7
+
8
+ module YunTongXun
9
+ class << self
10
+ def setup
11
+ yield config
12
+ end
13
+
14
+ def config
15
+ @config ||= Configuration.new
16
+ end
17
+
18
+ def logger
19
+ @logger ||= Logger.new(STDOUT)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yuntongxun_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yuntongxun_api"
8
+ spec.version = YunTongXun::VERSION
9
+ spec.authors = ["skji"]
10
+ spec.email = ["jishankai@qq.com"]
11
+
12
+ spec.summary = %q{容联·云通讯SDK Ruby版}
13
+ spec.description = %q{容联·云通讯SDK Ruby版 提供短信,语音验证码,电话回拨和外呼通知等功能}
14
+ spec.homepage = "https://github.com/skji/yuntongxun_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yuntongxun_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - skji
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-05 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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: "容联·云通讯SDK Ruby版 提供短信,语音验证码,电话回拨和外呼通知等功能"
42
+ email:
43
+ - jishankai@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
+ - bin/console
54
+ - bin/setup
55
+ - lib/yuntongxun_api.rb
56
+ - lib/yuntongxun_api/configuration.rb
57
+ - lib/yuntongxun_api/helper.rb
58
+ - lib/yuntongxun_api/sms.rb
59
+ - lib/yuntongxun_api/version.rb
60
+ - lib/yuntongxun_api/voice.rb
61
+ - yuntongxun_api.gemspec
62
+ homepage: https://github.com/skji/yuntongxun_api
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.6.3
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: "容联·云通讯SDK Ruby版"
86
+ test_files: []