cloopen 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: c3d825e322649ecf2230a69f8e84bf87eeb1182b
4
+ data.tar.gz: c1ce494e43f85e2d67c92359ce90b761e5c2fc87
5
+ SHA512:
6
+ metadata.gz: 7b6b89a11ac44e8fd280a18f8ba4d3596eb9a4caecbefd50260439f85b5abeeff4356632050b3c12abe92e639756f255f119999c57ffcdd9f2e8dc35c8a6c2b7
7
+ data.tar.gz: 285d758754ac8a568f66ea3332304cd0c6859f389e8d0282581abb70e76570f9715c84dcb22ac17296f963b061f53fa671eb854f53ca7cc8a40af7b66f46c99b
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .ruby-gemset
24
+ .ruby-version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cloopen.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 xiaoronglv
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,71 @@
1
+ # Cloopen
2
+
3
+ 云通讯发送短信的 Gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cloopen'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cloopen
18
+
19
+ ## Usage
20
+
21
+ ### 申请云通讯的短信通道服务
22
+
23
+ 1. 注册 [云通讯](http://www.yuntongxun.com) ,申请企业认证(只有企业帐号才可以发短信)。
24
+
25
+ 2. 在 [这个页面](http://www.yuntongxun.com/member/main) 查看帐号的 account_sid, auth_token
26
+
27
+ 3. 在 [这个页面](http://www.yuntongxun.com/member/app/view) 创建 App,获得 app_id
28
+
29
+ 4. 在 [这里](http://www.yuntongxun.com/member/smsTemplate/view) 创建你的短信模板,比如:
30
+
31
+ `【薄荷网】您的的验证码是{1}`
32
+
33
+ 5. 等待云通讯的管理员审核,大概需要 2 个小时的时间。
34
+
35
+ * App 通过审核
36
+ * 短信模板通过审核
37
+
38
+ ### 生成配置文件
39
+
40
+ 1. 执行 `rails g cloopen` 生成配置文件 `config/initialiers/cloopen_setup.rb`
41
+
42
+ 2. 替换 sid、token、app_id、env
43
+
44
+ ```ruby
45
+ # config/initialiers/cloopen_setup.rb
46
+ Cloopen.account_sid = "Your Yuntongxun Account Sid"
47
+ Cloopen.auth_token = "Your Yuntongxun Auth token"
48
+ Cloopen.app_id = "Your Yuntongxun App id"
49
+ Cloopen.env = "production" # 如果是测试环境,填写 "development"
50
+ ```
51
+
52
+
53
+ ### 发送短信
54
+
55
+ ```ruby
56
+ Cloopen::SMS.deliver(18668189883, 3127, ['a32d1k'])
57
+ ```
58
+ * 第一个参数是手机号码
59
+
60
+ * 第二个是模板id。只有模板通过审核后,才可以用这个模板发短信。
61
+
62
+ * 第三个是模板中的变量的值。用于替换 `【薄荷网】您的的验证码是{1}` 中的变量。
63
+
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it ( https://github.com/[my-github-username]/cloopen/fork )
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/cloopen.gemspec ADDED
@@ -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 'cloopen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cloopen"
8
+ spec.version = Cloopen::VERSION
9
+ spec.authors = ["xiaoronglv"]
10
+ spec.email = ["xiaoronglv@hotmail.com"]
11
+ spec.summary = %q{ call yuntongxun Api to send short message. }
12
+ spec.description = %q{ call yuntongxun Api to send short message. }
13
+ spec.homepage = "https://github.com/xiaoronglv/cloopen"
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.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rest-client"
24
+ end
data/lib/cloopen.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "cloopen/version"
2
+ require "cloopen/sms"
3
+ require "cloopen/sign"
4
+
5
+ module Cloopen
6
+ class << self
7
+ attr_accessor :account_sid, :auth_token, :app_id, :env
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ require 'digest/md5'
2
+ require 'base64'
3
+
4
+ module Cloopen
5
+ class Sign
6
+ # 生成验证参数
7
+ # 1. SigParameter
8
+ # 2. Authorization
9
+ def self.generate_sig_and_auth
10
+ time = Time.now.strftime("%Y%m%d%H%M%S")
11
+ sig_parameter = Digest::MD5.hexdigest(Cloopen.account_sid + Cloopen.auth_token + time).upcase
12
+ authorization = Base64.strict_encode64("#{Cloopen.account_sid}:#{time}")
13
+ [sig_parameter, authorization]
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,50 @@
1
+ require 'rest_client'
2
+ require 'uri'
3
+ require 'json'
4
+
5
+ module Cloopen
6
+ class SMS
7
+ def initialize(cellphone, tmpl_id, contents)
8
+ @cellphone = cellphone
9
+ @template_id = tmpl_id
10
+ @contents = contents
11
+ @sig_parameter, @authorization = Sign.generate_sig_and_auth
12
+ end
13
+
14
+ def deliver
15
+ if Cloopen.env == "production"
16
+ base_uri = "https://app.cloopen.com:8883/2013-12-26/Accounts/"
17
+ else
18
+ base_uri = "https://sandboxapp.cloopen.com:8883/2013-12-26/Accounts/"
19
+ end
20
+
21
+ sms_url = "#{base_uri}#{Cloopen.account_sid}/SMS/TemplateSMS?sig=#{@sig_parameter}"
22
+
23
+ payload = {
24
+ to: @cellphone,
25
+ appId: Cloopen.app_id,
26
+ templateId: @template_id,
27
+ datas: @contents
28
+ }.to_json
29
+
30
+ header = {
31
+ "Content-type" => "application/json;charset=utf-8",
32
+ "Accept" => "application/json",
33
+ "Authorization" => @authorization
34
+ }
35
+
36
+ res = JSON.parse(RestClient.post sms_url, payload, header)
37
+ [res["statusCode"], res["statusMsg"]]
38
+ end
39
+
40
+ # 发送短信
41
+ # Cloopen::SMS.deliver(18668189882, 3127, ["w1n2ty"])
42
+ # 手机号: 18668189882
43
+ # 模板 id: 3127
44
+ # 模板变量替换值: ["w1n2ty"]
45
+ def self.deliver(cellphone, tmpl_id, contents)
46
+ sms = new(cellphone, tmpl_id, contents)
47
+ sms.deliver
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module Cloopen
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails/generators'
2
+ class CloopenGenerator < Rails::Generators::Base
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ def install
7
+ template "cloopen_setup.rb", "config/initializers/cloopen_setup.rb"
8
+ end
9
+
10
+ end
@@ -0,0 +1,8 @@
1
+ ##### 云通讯的配置文件 ####
2
+
3
+ Cloopen.setup do |config|
4
+ config.account_sid = "YOUR_ACCOUNT_SID"
5
+ config.auth_token = "YOUR_AUTH_TOKEN"
6
+ config.app_id = "YOUR_APP_ID"
7
+ config.env = "production"
8
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloopen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - xiaoronglv
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ' call yuntongxun Api to send short message. '
56
+ email:
57
+ - xiaoronglv@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - cloopen.gemspec
68
+ - lib/cloopen.rb
69
+ - lib/cloopen/sign.rb
70
+ - lib/cloopen/sms.rb
71
+ - lib/cloopen/version.rb
72
+ - lib/generators/cloopen/cloopen_generator.rb
73
+ - lib/generators/cloopen/templates/cloopen_setup.rb
74
+ homepage: https://github.com/xiaoronglv/cloopen
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: call yuntongxun Api to send short message.
98
+ test_files: []