yunpiansms 1.0.2 → 1.0.3
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/lib/yunpiansms/version.rb +1 -1
- data/lib/yunpiansms.rb +22 -11
- data/test.rb +17 -4
- data/yunpiansms.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d07991ac6a8551791386d66526a5fe87c7eda48a
|
4
|
+
data.tar.gz: 81e6e676b08af92f85e45656a621a26dd7e89316
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0835e5dd6584c23161bf4b54cc4fb5f956b4e196419e7b0529183d604d3cfa1704d20491f6a1eb3073af9ae873cf12f99e6d38ec0fdc0e9a1e07bc6ae8d07ab2
|
7
|
+
data.tar.gz: 6496b50d9f87063129147232ddd850a851d31d7adf0ded6832944eec6a5d334e6a9340d27354f70c953dfcd437aca11a72bbe6519517ac6605a2986454d7f020
|
data/lib/yunpiansms/version.rb
CHANGED
data/lib/yunpiansms.rb
CHANGED
@@ -5,11 +5,10 @@ require 'yunpiansms/http_base'
|
|
5
5
|
|
6
6
|
module Yunpiansms
|
7
7
|
class Service
|
8
|
-
attr_accessor :apikey, :
|
8
|
+
attr_accessor :apikey, :connection_adapter,:debug_flg
|
9
9
|
|
10
|
-
def initialize(apikey: "",
|
10
|
+
def initialize(apikey: "", connection_adapter: :net_http, debug_flg: false)
|
11
11
|
@apikey = apikey
|
12
|
-
@signature = signature
|
13
12
|
@connection_adapter = connection_adapter
|
14
13
|
@debug_flg = debug_flg
|
15
14
|
end
|
@@ -18,26 +17,26 @@ module Yunpiansms
|
|
18
17
|
yield service = new; service
|
19
18
|
end
|
20
19
|
|
21
|
-
def send_to(content, mobiles = nil
|
22
|
-
http.post(Yunpiansms::SmsResources::SEND_URL,params_data(content, mobiles
|
20
|
+
def send_to(content, mobiles = nil)
|
21
|
+
http.post(Yunpiansms::SmsResources::SEND_URL,params_data(content, mobiles))
|
23
22
|
end
|
24
23
|
|
25
|
-
def tpl_send_to(content, mobiles = nil, tpl_id = nil, tpl_value=nil
|
26
|
-
http.post(Yunpiansms::SmsResources::TPL_SEND_URL,params_data_tpl(content, mobiles, tpl_id,tpl_value
|
24
|
+
def tpl_send_to(content, mobiles = nil, tpl_id = nil, tpl_value=nil)
|
25
|
+
http.post(Yunpiansms::SmsResources::TPL_SEND_URL,params_data_tpl(content, mobiles, tpl_id,tpl_value))
|
27
26
|
end
|
28
27
|
|
29
28
|
private
|
30
29
|
|
31
|
-
def params_data(content, mobiles
|
30
|
+
def params_data(content, mobiles)
|
32
31
|
content = format_content(content,mobiles)
|
33
|
-
content[:text] = "#{
|
32
|
+
content[:text] = "#{format_tpl_value(content[:text])}"
|
34
33
|
content
|
35
34
|
end
|
36
35
|
|
37
|
-
def params_data_tpl(content, mobiles = nil, tpl_id = nil, tpl_value=nil
|
36
|
+
def params_data_tpl(content, mobiles = nil, tpl_id = nil, tpl_value=nil)
|
38
37
|
content = format_content(content,mobiles)
|
39
38
|
content[:tpl_id] = tpl_id || content.detele(:tpl_id)
|
40
|
-
content[:tpl_value] = "#{
|
39
|
+
content[:tpl_value] = "#{format_tpl_value(content[:tpl_value])}"
|
41
40
|
content
|
42
41
|
end
|
43
42
|
|
@@ -63,5 +62,17 @@ module Yunpiansms
|
|
63
62
|
params[:mobile] = mobile_format(mobiles || params[:mobile])
|
64
63
|
params
|
65
64
|
end
|
65
|
+
|
66
|
+
def format_tpl_value(tpl_value)
|
67
|
+
if tpl_value.is_a?(Hash)
|
68
|
+
tpl_value = parse_tpl_value(tpl_value)
|
69
|
+
else
|
70
|
+
tpl_value
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def parse_tpl_value tpl_value
|
75
|
+
tpl_value.map { |k, v| "##{k}#=#{v}" }.join('&')
|
76
|
+
end
|
66
77
|
end
|
67
78
|
end
|
data/test.rb
CHANGED
@@ -3,13 +3,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
Dir[File.dirname(__FILE__) + '/lib/*.rb'].each {|file| require file }
|
4
4
|
@yunpiansms_service = Yunpiansms::Service.config do |s|
|
5
5
|
s.apikey = ""
|
6
|
-
s.signature = "TryCatch"
|
7
6
|
s.connection_adapter = :net_http # default
|
8
7
|
end
|
9
8
|
content = {
|
10
9
|
apikey: "",
|
11
|
-
mobile: "
|
12
|
-
text: "
|
10
|
+
mobile: "",
|
11
|
+
text: "123",
|
13
12
|
uid: "15279"
|
14
13
|
}
|
15
|
-
result = @yunpiansms_service.send_to(content,"
|
14
|
+
result = @yunpiansms_service.send_to(content,"")
|
15
|
+
content = {
|
16
|
+
apikey: "",
|
17
|
+
mobile: "",
|
18
|
+
tpl_value: {key:"1245",key1:"23"},
|
19
|
+
uid: "15279"
|
20
|
+
}
|
21
|
+
result = @yunpiansms_service.tpl_send_to(content,"",1,nil)
|
22
|
+
content = {
|
23
|
+
apikey: "",
|
24
|
+
mobile: "",
|
25
|
+
text: {key:"1245",key1:"23"},
|
26
|
+
uid: "15279"
|
27
|
+
}
|
28
|
+
result = @yunpiansms_service.send_to(content,"")
|
data/yunpiansms.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["guoyoujin123@gmail.com"]
|
11
11
|
spec.summary = ["trycatch"]
|
12
12
|
spec.description = %q{yunpian send sms Ruby Server SDK.}
|
13
|
-
spec.homepage = "https://github.com/guoyoujin/
|
13
|
+
spec.homepage = "https://github.com/guoyoujin/yunpiansms"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
16
|
spec.bindir = "exe"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yunpiansms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- trycatch
|
@@ -71,7 +71,7 @@ files:
|
|
71
71
|
- lib/yunpiansms/version.rb
|
72
72
|
- test.rb
|
73
73
|
- yunpiansms.gemspec
|
74
|
-
homepage: https://github.com/guoyoujin/
|
74
|
+
homepage: https://github.com/guoyoujin/yunpiansms
|
75
75
|
licenses:
|
76
76
|
- MIT
|
77
77
|
metadata: {}
|