china_sms 0.0.1

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: e5f162b7555923e2041d9c91e7542ffb8b639f3f
4
+ data.tar.gz: 8004e430e389d4ef935d69270a65e31536ec9cb1
5
+ SHA512:
6
+ metadata.gz: 00cb79fb356a692d3b84d4d4f0d0d04e2819b33b176b6a897a0602c373133c1db46e6be811a36fd2dc2b475cffdc3c72e8b8997be5b4529504a0b415b24669c6
7
+ data.tar.gz: 1d406912d5610e6a0bf96e7bd79bd850c77afa52da7880df42497a316c9c51f2f6e9f3aa16dd40116d19d35d00cae8bae952d0357ee01a197c38f4d0ecb155ef
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in china_sms.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 saberma
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
+ # ChinaSMS 短信平台 Ruby 接口
2
+
3
+ ## 支持以下短信平台
4
+
5
+ 所有短信平台都禁止发送私人短信,并要求在短信内容末尾加上签名后缀,如【19屋】
6
+
7
+ * [推立方](http://tui3.com/) 专注于注册校验码等实时应用,需要[配置内容格式和签名](http://www.tui3.com/Members/smsconfigv2/),自动在短信加上签名后缀
8
+ * [短信宝](http://www.smsbao.com/)
9
+ * [畅友网络](http://www.chanyoo.cn/) 群发短信需要半小时左右的时间审核,星期五等繁忙时段会有几个小时的延时,不适合发送注册校验码等实时短信,单次最多发送500个号码
10
+
11
+ ## 安装
12
+
13
+ 加入以下代码到 Gemfile:
14
+
15
+ gem 'china_sms'
16
+
17
+ 然后执行:
18
+
19
+ $ bundle
20
+
21
+ 或者直接安装:
22
+
23
+ $ gem install china_sms
24
+
25
+ ## 使用
26
+
27
+ ```ruby
28
+ # 支持 :tui3, :smsbao, chanyoo 短信接口
29
+ ChinaSMS.use :smsbao, username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD'
30
+ ChinaSMS.to '13912345678', '[Test]China SMS gem has been released.'
31
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/china_sms.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'china_sms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "china_sms"
8
+ spec.version = ChinaSMS::VERSION
9
+ spec.authors = ["saberma"]
10
+ spec.email = ["mahb45@gmail.com"]
11
+ spec.description = %q{a gem for chinese people to send sms}
12
+ spec.summary = %q{a gem for chinese people to send sms}
13
+ spec.homepage = "https://github.com/saberma/china_sms"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ end
@@ -0,0 +1,23 @@
1
+ module ChinaSMS
2
+ module Service
3
+ module Chanyoo
4
+ extend self
5
+ URL = "http://api.chanyoo.cn/utf8/interface/send_sms.aspx"
6
+ def to(phone, content, options)
7
+ phones = Array(phone).join(',')
8
+ res = Net::HTTP.post_form(URI.parse(URL), username: options[:username], password: options[:password], receiver: phones, content: content)
9
+ result res.body
10
+ end
11
+
12
+ def result(body)
13
+ code = body.match(/.+result>(.+)\<\/result/)[1]
14
+ message = body.match(/.+message>(.+)\<\/message/)[1]
15
+ {
16
+ success: (code.to_i >= 0),
17
+ code: code,
18
+ message: message.force_encoding("UTF-8")
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ module ChinaSMS
2
+ module Service
3
+ module Smsbao
4
+ extend self
5
+ URL = "http://api.smsbao.com/sms"
6
+ MESSAGES = {
7
+ '0' => '短信发送成功',
8
+ '30' => '密码错误',
9
+ '40' => '账号不存在',
10
+ '41' => '余额不足',
11
+ '42' => '帐号过期',
12
+ '43' => 'IP地址限制',
13
+ '50' => '内容含有敏感词',
14
+ '51' => '手机号码不正确'
15
+ }
16
+
17
+ def to(phone, content, options)
18
+ phones = Array(phone).join(',')
19
+ res = Net::HTTP.post_form(URI.parse(URL), u: options[:username], p: Digest::MD5.hexdigest(options[:password]), m: phones, c: content)
20
+ result res.body
21
+ end
22
+
23
+ def result(code)
24
+ {
25
+ success: (code == '0'),
26
+ code: code,
27
+ message: MESSAGES[code]
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ require 'json'
2
+
3
+ module ChinaSMS
4
+ module Service
5
+ module Tui3 # http://tui3.com/
6
+ extend self
7
+ URL = "http://tui3.com/api/send/"
8
+ def to(phone, content, options)
9
+ phones = Array(phone).join(',')
10
+ res = Net::HTTP.post_form(URI.parse(URL), k: options[:password], t: phones, c: content, p: 1, r: 'json')
11
+ result JSON[res.body]
12
+ end
13
+
14
+ def result(body)
15
+ {
16
+ success: body['err_code'] == 0,
17
+ code: body['err_code'],
18
+ message: body['err_msg']
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module ChinaSMS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/china_sms.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "china_sms/version"
2
+ require 'net/http'
3
+ Dir.glob("#{File.expand_path(File.dirname(__FILE__))}/china_sms/service/*.rb").sort.each do |f|
4
+ require f.match(/(china_sms\/service\/.*)\.rb$/)[0]
5
+ end
6
+
7
+ module ChinaSMS
8
+ extend self
9
+ def username
10
+ @username
11
+ end
12
+ def password
13
+ @password
14
+ end
15
+
16
+ def use(service, options)
17
+ @service = ChinaSMS::Service.const_get("#{service.to_s.capitalize}")
18
+ @username = options[:username]
19
+ @password = options[:password]
20
+ end
21
+
22
+ def to(receiver, content)
23
+ @service.to receiver, content, username: @username, password: @password
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ChinaSMS" do
4
+ let(:service) { :tui3 }
5
+ let(:username) { 'saberma' }
6
+ let(:password) { '666666' }
7
+ let(:phone) { '13928452841' }
8
+ let(:content) { '活动通知:深圳 Rubyist 活动时间变更到明天下午 7:00,请留意。' }
9
+ before { ChinaSMS.use service, username: username, password: password }
10
+ describe "#use" do
11
+ subject { ChinaSMS }
12
+ its(:username) { should eql "saberma"}
13
+ end
14
+ describe "#to" do
15
+ subject { ChinaSMS.to(phone, content) }
16
+ before { ChinaSMS::Service::Tui3.stub(:to).with(phone, content, username: username, password: password).and_return(success: true, code: 0) }
17
+ its([:success]) { should eql true }
18
+ its([:code]) { should eql 0 }
19
+ end
20
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Chanyoo" do
4
+ describe "#to" do
5
+ let(:username) { 'saberma' }
6
+ let(:password) { '666666' }
7
+ let(:url) { "http://api.chanyoo.cn/utf8/interface/send_sms.aspx" }
8
+ let(:content) { '【畅友短信测试】深圳 Rubyist 活动时间变更到周六下午 3:00,请留意。【19屋】' }
9
+ subject { ChinaSMS::Service::Chanyoo.to phone, content, username: username, password: password }
10
+ describe 'single phone' do
11
+ let(:phone) { '13928452841' }
12
+ before do
13
+ stub_request(:post, url).
14
+ with(body: {username: username, password: password, receiver: phone, content: content}).
15
+ to_return(body: '<?xml version="1.0" encoding="utf-8" ?><response><result>50</result><message>短信发送成功</message></response>')
16
+ end
17
+ its([:success]) { should eql true }
18
+ its([:code]) { should eql '50' }
19
+ its([:message]) { should eql "短信发送成功" }
20
+ end
21
+
22
+ describe 'multiple phones' do
23
+ let(:phone) { ['13928452841', '13590142385'] }
24
+ before do
25
+ stub_request(:post, url).
26
+ with(body: {username: username, password: password, receiver: phone.join(','), content: content}).
27
+ to_return(body: '<?xml version="1.0" encoding="utf-8" ?><response><result>50</result><message>短信发送成功</message></response>')
28
+ end
29
+ its([:success]) { should eql true }
30
+ its([:code]) { should eql '50' }
31
+ its([:message]) { should eql "短信发送成功" }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Smsbao" do
4
+ describe "#to" do
5
+ let(:username) { 'saberma' }
6
+ let(:password) { '666666' }
7
+ let(:url) { "http://api.smsbao.com/sms" }
8
+ let(:content) { '【短信宝测试】深圳 Rubyist 活动时间变更到明天下午 7:00,请留意。【19屋】' }
9
+ subject { ChinaSMS::Service::Smsbao.to phone, content, username: username, password: password }
10
+ describe 'single phone' do
11
+ let(:phone) { '13928452841' }
12
+ before do
13
+ stub_request(:post, url).
14
+ with(body: {u: username, p: Digest::MD5.hexdigest(password), m: phone, c: content}).
15
+ to_return(body: '0')
16
+ end
17
+ its([:success]) { should eql true }
18
+ its([:code]) { should eql '0' }
19
+ its([:message]) { should eql "短信发送成功" }
20
+ end
21
+
22
+ describe 'multiple phones' do
23
+ let(:phone) { ['13928452841', '13590142385'] }
24
+ before do
25
+ stub_request(:post, url).
26
+ with(body: {u: username, p: Digest::MD5.hexdigest(password), m: phone.join(','), c: content}).
27
+ to_return(body: '0')
28
+ end
29
+ its([:success]) { should eql true }
30
+ its([:code]) { should eql '0' }
31
+ its([:message]) { should eql "短信发送成功" }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Tui3" do
4
+ describe "#to" do
5
+ let(:username) { 'saberma' }
6
+ let(:password) { '666666' }
7
+ let(:url) { "http://tui3.com/api/send/" }
8
+ let(:content) { '推立方测试:深圳 Rubyist 活动时间变更到明天下午 7:00,请留意。' }
9
+ subject { ChinaSMS::Service::Tui3.to phone, content, username: username, password: password }
10
+ describe 'single phone' do
11
+ let(:phone) { '13928452841' }
12
+ before do
13
+ stub_request(:post, url).
14
+ with(body: {k: password, t: phone, c: content, p: '1', r: 'json'}).
15
+ to_return(body: '{"err_code":0,"err_msg":"操作成功!","server_time":"2013-07-01 21:42:37"}' )
16
+ end
17
+ its([:success]) { should eql true }
18
+ its([:code]) { should eql 0 }
19
+ its([:message]) { should eql "操作成功!" }
20
+ end
21
+
22
+ describe 'multiple phones' do
23
+ let(:phone) { ['13928452841', '13590142385'] }
24
+ before do
25
+ stub_request(:post, url).
26
+ with(body: {k: password, t: phone.join(','), c: content, p: '1', r: 'json'}).
27
+ to_return(body: '{"err_code":0,"err_msg":"操作成功!","server_time":"2013-07-01 21:42:37"}' )
28
+ end
29
+ its([:success]) { should eql true }
30
+ its([:code]) { should eql 0 }
31
+ its([:message]) { should eql "操作成功!" }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,6 @@
1
+ require 'webmock/rspec'
2
+ require 'china_sms'
3
+
4
+ #WebMock.allow_net_connect!
5
+ RSpec.configure do |config|
6
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: china_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - saberma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-01 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: a gem for chinese people to send sms
70
+ email:
71
+ - mahb45@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - china_sms.gemspec
82
+ - lib/china_sms.rb
83
+ - lib/china_sms/service/chanyoo.rb
84
+ - lib/china_sms/service/smsbao.rb
85
+ - lib/china_sms/service/tui3.rb
86
+ - lib/china_sms/version.rb
87
+ - spec/china_sms_spec.rb
88
+ - spec/service/chanyoo_spec.rb
89
+ - spec/service/smsbao_spec.rb
90
+ - spec/service/tui3_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: https://github.com/saberma/china_sms
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.3
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: a gem for chinese people to send sms
116
+ test_files:
117
+ - spec/china_sms_spec.rb
118
+ - spec/service/chanyoo_spec.rb
119
+ - spec/service/smsbao_spec.rb
120
+ - spec/service/tui3_spec.rb
121
+ - spec/spec_helper.rb