Module: Dingxin::Vms
- Defined in:
- lib/dingxin/vms.rb,
lib/dingxin/vms/version.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
"0.0.1"
Class Attribute Summary collapse
Class Method Summary collapse
-
.canonicalized_query_string(params) ⇒ Object
规范化参数.
- .configure {|configuration| ... } ⇒ Object
-
.encode(input) ⇒ Object
对字符串进行 PERCENT 编码 apidock.com/ruby/ERB/Util/url_encode.
- .get_url(params) ⇒ Object
- .send(phone, tpl_id, param) ⇒ Object
Class Attribute Details
.configuration ⇒ Object
21 22 23 |
# File 'lib/dingxin/vms.rb', line 21 def configuration @configuration ||= Configuration.new end |
Class Method Details
.canonicalized_query_string(params) ⇒ Object
规范化参数
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dingxin/vms.rb', line 50 def canonicalized_query_string(params) cqstring = '' params.sort_by{|key, val| key}.each do |key, value| if cqstring.empty? cqstring += "#{encode(key)}=#{encode(value)}" else cqstring += "&#{encode(key)}=#{encode(value)}" end end cqstring end |
.configure {|configuration| ... } ⇒ Object
25 26 27 |
# File 'lib/dingxin/vms.rb', line 25 def configure yield(configuration) end |
.encode(input) ⇒ Object
对字符串进行 PERCENT 编码 apidock.com/ruby/ERB/Util/url_encode
45 46 47 |
# File 'lib/dingxin/vms.rb', line 45 def encode(input) output = url_encode(input) end |
.get_url(params) ⇒ Object
38 39 40 41 |
# File 'lib/dingxin/vms.rb', line 38 def get_url(params) coded_params = canonicalized_query_string(params) url = 'http://yuyin2.market.alicloudapi.com/dx/voice_notice?' + coded_params end |
.send(phone, tpl_id, param) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/dingxin/vms.rb', line 29 def send(phone, tpl_id, param) Typhoeus.post(get_url({ 'phone' => phone, 'tpl_id' => tpl_id, 'param' => param }), headers: { "Authorization" => "APPCODE #{configuration.app_code}" }) end |