china_sms 0.0.6 → 0.0.7
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 +4 -4
- data/README.md +16 -4
- data/lib/china_sms.rb +1 -1
- data/lib/china_sms/service/yunpian.rb +19 -11
- data/lib/china_sms/version.rb +1 -1
- data/spec/service/yunpian_spec.rb +80 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e5842aa72def89ea1a2a8300b95301d35337d0a
|
4
|
+
data.tar.gz: 5e7ff2e05f50124f63d2cf91eb6d30323b13fefa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae1937ec1e79db7bbc5b7f1279e279593231a5c336777e1029c6f59bad67221df4f98f2e4f3af0244da0959681537d1676126b26442873d9b8a749b7e8d3eb8a
|
7
|
+
data.tar.gz: 660dba084b4c14d81e9a2d361881c1a4d569e042cc1ce5e8b0348a74286321804a5e3c38736a4d93b9b7b5b9802f3828bea0b9e7a98472bcd8e494a58d4a0b4d
|
data/README.md
CHANGED
@@ -35,12 +35,24 @@
|
|
35
35
|
ChinaSMS.use :tui3, username: 'YOUR_USERNAME', password: 'YOUR_PASSWORD'
|
36
36
|
ChinaSMS.to '13912345678', '[Test]China SMS gem has been released.'
|
37
37
|
|
38
|
-
|
39
|
-
#
|
40
|
-
#
|
38
|
+
|
39
|
+
# :yunpian
|
40
|
+
# 如果content(第二个参数) 是字符串
|
41
|
+
# 调用 通用接口 发送短信
|
42
|
+
# 如果是 Hash
|
43
|
+
# 调用 模板接口 发送短信
|
44
|
+
# 可选参数:
|
45
|
+
# :tpl_id 默认是 2
|
41
46
|
|
42
47
|
ChinaSMS.use :yunpian, password: 'YOUR_API_KEY'
|
43
|
-
|
48
|
+
|
49
|
+
# 通用接口
|
50
|
+
ChinaSMS.to '13912345678', '[Test]China SMS gem has been released.'
|
51
|
+
|
52
|
+
# 模板接口
|
53
|
+
# 模板是 "您的验证码是#code#【#company#】”
|
54
|
+
tpl_params = { code: 123, company: '19wu' }
|
55
|
+
ChinaSMS.to '13912345678', tpl_params, tpl_id: 1
|
44
56
|
|
45
57
|
```
|
46
58
|
|
data/lib/china_sms.rb
CHANGED
@@ -4,22 +4,32 @@ module ChinaSMS
|
|
4
4
|
module Yunpian
|
5
5
|
extend self
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
GET_URL = "http://yunpian.com/v1/sms/get.json"
|
8
|
+
SEND_URL = 'http://yunpian.com/v1/sms/send.json'
|
9
|
+
TPL_SEND_URL = 'http://yunpian.com/v1/sms/tpl_send.json'
|
9
10
|
|
10
11
|
def to phone, content, options = {}
|
11
|
-
message = parse_content content, options[:company]
|
12
12
|
options[:tpl_id] ||= 2
|
13
13
|
options[:apikey] ||= options[:password]
|
14
|
-
except! options, :username, :password
|
15
|
-
|
16
|
-
res =
|
14
|
+
except! options, :username, :password
|
15
|
+
|
16
|
+
res = if content.is_a? Hash
|
17
|
+
message = parse_content content
|
18
|
+
options.merge!({ mobile: phone, tpl_value: message })
|
19
|
+
Net::HTTP.post_form(URI.parse(TPL_SEND_URL), options)
|
20
|
+
else
|
21
|
+
except! options, :tpl_id
|
22
|
+
message = content
|
23
|
+
options.merge!({ mobile: phone, text: message })
|
24
|
+
Net::HTTP.post_form(URI.parse(SEND_URL), options)
|
25
|
+
end
|
26
|
+
|
17
27
|
result res.body
|
18
28
|
end
|
19
29
|
|
20
30
|
def get options = {}
|
21
31
|
options[:apikey] ||= options[:password]
|
22
|
-
except! options, :username, :password
|
32
|
+
except! options, :username, :password
|
23
33
|
res = Net::HTTP.post_form(URI.parse(GET_URL), options)
|
24
34
|
result res.body
|
25
35
|
end
|
@@ -43,10 +53,8 @@ module ChinaSMS
|
|
43
53
|
options
|
44
54
|
end
|
45
55
|
|
46
|
-
def parse_content content
|
47
|
-
content
|
48
|
-
company ||= '云片网'
|
49
|
-
"#code#=#{content}&#company#=#{company}"
|
56
|
+
def parse_content content
|
57
|
+
content.map { |k, v| "##{k}#=#{v}" }.join('&')
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
data/lib/china_sms/version.rb
CHANGED
@@ -4,25 +4,25 @@ require 'spec_helper'
|
|
4
4
|
describe "Yunpian" do
|
5
5
|
describe "#to" do
|
6
6
|
let(:apikey) { '2022b1599967a8cb788c05ddd9fc339e' }
|
7
|
-
let(:
|
7
|
+
let(:send_url) { "http://yunpian.com/v1/sms/send.json" }
|
8
|
+
let(:tpl_send_url) { "http://yunpian.com/v1/sms/tpl_send.json" }
|
8
9
|
let(:content) { '云片测试:验证码 1234。' }
|
9
|
-
|
10
|
+
let(:tpl_content) { Hash[:code, 123, :company, '云片网'] }
|
10
11
|
|
11
12
|
describe 'single phone' do
|
12
13
|
let(:phone) { '13928452841' }
|
13
14
|
|
14
15
|
before do
|
15
|
-
stub_request(:post,
|
16
|
+
stub_request(:post, tpl_send_url).
|
16
17
|
with(
|
17
|
-
:
|
18
|
+
body: {
|
18
19
|
"apikey" => apikey,
|
19
20
|
"mobile" => phone,
|
20
21
|
"tpl_id" => "2",
|
21
|
-
"tpl_value" =>"#code
|
22
|
-
:
|
22
|
+
"tpl_value" => "#code#=123&#company#=云片网" },
|
23
|
+
headers: {
|
23
24
|
'Content-Type' => 'application/x-www-form-urlencoded'
|
24
|
-
}
|
25
|
-
).
|
25
|
+
}).
|
26
26
|
to_return(
|
27
27
|
body: {
|
28
28
|
'code' => 0,
|
@@ -34,28 +34,76 @@ describe "Yunpian" do
|
|
34
34
|
}
|
35
35
|
}.to_json
|
36
36
|
)
|
37
|
+
|
38
|
+
stub_request(:post, send_url).
|
39
|
+
with(
|
40
|
+
body: {
|
41
|
+
"apikey" => apikey,
|
42
|
+
"mobile" => phone,
|
43
|
+
"text" => content },
|
44
|
+
headers: {
|
45
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
46
|
+
}).
|
47
|
+
to_return(
|
48
|
+
body: {
|
49
|
+
'code' => 0,
|
50
|
+
'msg' => 'OK',
|
51
|
+
'result' => {
|
52
|
+
'count' => '1',
|
53
|
+
'fee' => '1',
|
54
|
+
'sid' => '592762800'
|
55
|
+
}
|
56
|
+
}.to_json
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'string content' do
|
61
|
+
subject { ChinaSMS::Service::Yunpian.to phone, content, password: apikey }
|
62
|
+
|
63
|
+
its(["code"]) { should eql 0 }
|
64
|
+
its(["msg"]) { should eql "OK" }
|
37
65
|
end
|
38
66
|
|
39
|
-
|
40
|
-
|
67
|
+
context 'tpl content' do
|
68
|
+
subject { ChinaSMS::Service::Yunpian.to phone, tpl_content, password: apikey }
|
69
|
+
|
70
|
+
its(["code"]) { should eql 0 }
|
71
|
+
its(["msg"]) { should eql "OK" }
|
72
|
+
end
|
41
73
|
end
|
42
74
|
|
43
|
-
|
75
|
+
describe 'invalid key' do
|
44
76
|
let(:phone) { '13928452841' }
|
45
77
|
let(:apikey) { '666666' }
|
46
78
|
|
47
79
|
before do
|
48
|
-
stub_request(:post,
|
80
|
+
stub_request(:post, tpl_send_url).
|
49
81
|
with(
|
50
|
-
:
|
82
|
+
body: {
|
51
83
|
"apikey" => apikey,
|
52
84
|
"mobile" => phone,
|
53
85
|
"tpl_id" => "2",
|
54
|
-
"tpl_value" =>"#code
|
55
|
-
:
|
86
|
+
"tpl_value" => "#code#=123&#company#=云片网" },
|
87
|
+
headers: {
|
56
88
|
'Content-Type' => 'application/x-www-form-urlencoded'
|
57
|
-
}
|
58
|
-
|
89
|
+
}).
|
90
|
+
to_return(
|
91
|
+
body: {
|
92
|
+
"code" => -1,
|
93
|
+
"msg" => "非法的apikey",
|
94
|
+
"detail" => "请检查的apikey是否正确"
|
95
|
+
}.to_json
|
96
|
+
)
|
97
|
+
|
98
|
+
stub_request(:post, send_url).
|
99
|
+
with(
|
100
|
+
body: {
|
101
|
+
"apikey" => apikey,
|
102
|
+
"mobile" => phone,
|
103
|
+
"text" => content },
|
104
|
+
headers: {
|
105
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
106
|
+
}).
|
59
107
|
to_return(
|
60
108
|
body: {
|
61
109
|
"code" => -1,
|
@@ -65,9 +113,21 @@ describe "Yunpian" do
|
|
65
113
|
)
|
66
114
|
end
|
67
115
|
|
68
|
-
|
69
|
-
|
70
|
-
|
116
|
+
context 'string content' do
|
117
|
+
subject { ChinaSMS::Service::Yunpian.to phone, content, password: apikey }
|
118
|
+
|
119
|
+
its(["code"]) { should eql -1 }
|
120
|
+
its(["msg"]) { should eql "非法的apikey" }
|
121
|
+
its(["detail"]) { should eql "请检查的apikey是否正确" }
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'tpl content' do
|
125
|
+
subject { ChinaSMS::Service::Yunpian.to phone, tpl_content, password: apikey }
|
126
|
+
|
127
|
+
its(["code"]) { should eql -1 }
|
128
|
+
its(["msg"]) { should eql "非法的apikey" }
|
129
|
+
its(["detail"]) { should eql "请检查的apikey是否正确" }
|
130
|
+
end
|
71
131
|
end
|
72
132
|
|
73
133
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: china_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- saberma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.0.6
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: a gem for chinese people to send sms
|