aliyun_sms_ruby 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -0
- data/aliyun_sms_ruby.gemspec +30 -0
- data/lib/aliyun_sms_ruby/client.rb +39 -0
- data/lib/aliyun_sms_ruby/configuration.rb +17 -0
- data/lib/aliyun_sms_ruby/request/base_request.rb +44 -0
- data/lib/aliyun_sms_ruby/request/message_global_request.rb +31 -0
- data/lib/aliyun_sms_ruby/request/message_request.rb +30 -0
- data/lib/aliyun_sms_ruby/request/query_request.rb +8 -0
- data/lib/aliyun_sms_ruby/version.rb +3 -0
- data/lib/aliyun_sms_ruby.rb +33 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04b9443bcc94bde6a6a76a53b3514396f5534dbfa7d8d6b4a1fd92d63979d922
|
4
|
+
data.tar.gz: 31e66adb1673f8408487bc9abda71c289aae370a017b1d917e0323cc8df69f36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc0ec467f5bd494f7b721d2e84be02642576334282fa5e379746f74c050d836f2af5ac937f22c2fb870d200408865ea8132ae303da042fb26fe723f102fea4c6
|
7
|
+
data.tar.gz: b6c0db9d718bb6f52bf71f3b6492e728219994ae6803a1b486d418085f10010689078b75da6e477da5ded671ed0979dda6ac93657e43a9d94228393830f515fb
|
data/README.md
ADDED
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aliyun_sms_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aliyun_sms_ruby"
|
8
|
+
spec.version = AliyunSmsRuby::VERSION
|
9
|
+
spec.authors = ["Zkun"]
|
10
|
+
spec.email = ["zhukun6150909@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Aliyun sms ruby sdk}
|
13
|
+
spec.description = %q{Aliyun sms ruby sdk}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "uuid", ">=2.0"
|
25
|
+
spec.add_dependency "faraday", "~> 1.8"
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "> 1.14"
|
28
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
29
|
+
spec.add_development_dependency "rspec", ">= 3.0"
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'uuid'
|
3
|
+
require 'json'
|
4
|
+
require 'openssl'
|
5
|
+
require 'base64'
|
6
|
+
require 'faraday'
|
7
|
+
|
8
|
+
module AliyunSmsRuby
|
9
|
+
class Client
|
10
|
+
SERVICE_URL = "http://dysmsapi.aliyuncs.com/"
|
11
|
+
|
12
|
+
def send_request request
|
13
|
+
q_without_sig = build_url(request.get_params)
|
14
|
+
q_full= "Signature=#{sign(q_without_sig)}&#{q_without_sig}"
|
15
|
+
|
16
|
+
response = Faraday.get "#{SERVICE_URL}?#{q_full}"
|
17
|
+
if response != 200 && defined? Rails
|
18
|
+
Rails.logger.error(response.body)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def build_url(hash)
|
25
|
+
hash.map{|k,v|"#{encode(k.to_s)}=#{encode(v.to_s)}"}.sort.join('&')
|
26
|
+
end
|
27
|
+
|
28
|
+
def encode(str)
|
29
|
+
ERB::Util.url_encode str
|
30
|
+
end
|
31
|
+
|
32
|
+
def sign(str)
|
33
|
+
str = "GET&#{encode('/')}&#{encode(str)}"
|
34
|
+
ret = OpenSSL::HMAC.digest('sha1', "#{AliyunSmsRuby.configuration.access_key_secret}&", str)
|
35
|
+
ret = Base64.encode64(ret)
|
36
|
+
encode(ret.chomp)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module AliyunSmsRuby
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :access_key_secret, :access_key_id, :format, :region_id,
|
4
|
+
:sign_name, :signature_method, :signature_version, :version
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@access_key_secret = ''
|
8
|
+
@access_key_id = ''
|
9
|
+
@format = ''
|
10
|
+
@region_id = ''
|
11
|
+
@sign_name = ''
|
12
|
+
@signature_method = ''
|
13
|
+
@signature_version = ''
|
14
|
+
@version = ''
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module AliyunSmsRuby
|
2
|
+
module Request
|
3
|
+
class BaseRequest
|
4
|
+
|
5
|
+
def get_params
|
6
|
+
custom_params.merge intrinsic_params
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def action
|
12
|
+
""
|
13
|
+
end
|
14
|
+
|
15
|
+
def custom_params
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
|
19
|
+
def intrinsic_params
|
20
|
+
configuration = AliyunSmsRuby.configuration
|
21
|
+
{
|
22
|
+
:AccessKeyId => configuration.access_key_id,
|
23
|
+
:SignName => configuration.sign_name,
|
24
|
+
:Format => configuration.format,
|
25
|
+
:RegionId => configuration.region_id,
|
26
|
+
:SignatureMethod => configuration.signature_method,
|
27
|
+
:SignatureVersion => configuration.signature_version,
|
28
|
+
:Timestamp => timestamp,
|
29
|
+
:SignatureNonce => nonce,
|
30
|
+
:Action => action,
|
31
|
+
:Version => configuration.version
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def timestamp
|
36
|
+
Time.now.utc.strftime("%FT%TZ")
|
37
|
+
end
|
38
|
+
|
39
|
+
def nonce
|
40
|
+
UUID.generate
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'aliyun_sms_ruby/request/base_request'
|
2
|
+
|
3
|
+
module AliyunSmsRuby
|
4
|
+
module Request
|
5
|
+
class MessageGlobalRequest < BaseRequest
|
6
|
+
attr_accessor :mobile, :text, :from, :type, :optional_params
|
7
|
+
|
8
|
+
def initialize(mobile, text, from, type, optional_params = nil)
|
9
|
+
self.mobile = mobile
|
10
|
+
self.text = text
|
11
|
+
self.from = from
|
12
|
+
self.type = type
|
13
|
+
self.optional_params = optional_params || {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def action
|
17
|
+
'SendMessageToGlobe'.freeze
|
18
|
+
end
|
19
|
+
|
20
|
+
def custom_params
|
21
|
+
{
|
22
|
+
Message: self.text,
|
23
|
+
To: self.mobile,
|
24
|
+
From: self.from,
|
25
|
+
Type: self.type
|
26
|
+
}.merge!(self.optional_params)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'aliyun_sms_ruby/request/base_request'
|
2
|
+
|
3
|
+
module AliyunSmsRuby
|
4
|
+
module Request
|
5
|
+
class MessageRequest < BaseRequest
|
6
|
+
attr_accessor :mobile, :template_code, :template_param, :optional_params
|
7
|
+
|
8
|
+
def initialize(mobile, template_code, template_param, optional_params = nil)
|
9
|
+
self.mobile = mobile
|
10
|
+
self.template_code = template_code
|
11
|
+
self.template_param = template_param
|
12
|
+
self.optional_params = optional_params || {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def action
|
16
|
+
"SendSms".freeze
|
17
|
+
end
|
18
|
+
|
19
|
+
def custom_params
|
20
|
+
self.template_param = self.template_param.to_json if self.template_param.is_a?(Hash)
|
21
|
+
|
22
|
+
{
|
23
|
+
:PhoneNumbers => self.mobile,
|
24
|
+
:TemplateCode => self.template_code,
|
25
|
+
:TemplateParam => self.template_param.to_s,
|
26
|
+
}.merge!(self.optional_params)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'aliyun_sms_ruby/configuration'
|
2
|
+
require 'aliyun_sms_ruby/client'
|
3
|
+
require 'aliyun_sms_ruby/request/message_request'
|
4
|
+
require 'aliyun_sms_ruby/request/message_global_request'
|
5
|
+
|
6
|
+
module AliyunSmsRuby
|
7
|
+
class << self
|
8
|
+
attr_writer :configuration
|
9
|
+
|
10
|
+
def configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_message(mobile, template_code, template_param, optional_params = nil)
|
19
|
+
request = AliyunSmsRuby::Request::MessageRequest.new(mobile, template_code, template_param, optional_params = nil)
|
20
|
+
client.send_request request
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_global_message(mobile, text, from, type, optional_params = nil)
|
24
|
+
request = AliyunSmsRuby::Request::MessageGlobalRequest.new(mobile, text, from, type, optional_params = nil)
|
25
|
+
client.send_request request
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def client
|
30
|
+
@client ||= AliyunSmsRuby::Client.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyun_sms_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zkun
|
@@ -86,7 +86,17 @@ email:
|
|
86
86
|
executables: []
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
|
-
files:
|
89
|
+
files:
|
90
|
+
- README.md
|
91
|
+
- aliyun_sms_ruby.gemspec
|
92
|
+
- lib/aliyun_sms_ruby.rb
|
93
|
+
- lib/aliyun_sms_ruby/client.rb
|
94
|
+
- lib/aliyun_sms_ruby/configuration.rb
|
95
|
+
- lib/aliyun_sms_ruby/request/base_request.rb
|
96
|
+
- lib/aliyun_sms_ruby/request/message_global_request.rb
|
97
|
+
- lib/aliyun_sms_ruby/request/message_request.rb
|
98
|
+
- lib/aliyun_sms_ruby/request/query_request.rb
|
99
|
+
- lib/aliyun_sms_ruby/version.rb
|
90
100
|
homepage: ''
|
91
101
|
licenses:
|
92
102
|
- MIT
|