Class: AliyunPush::ParameterSet
- Inherits:
-
Object
- Object
- AliyunPush::ParameterSet
- Defined in:
- lib/aliyun-push/parameter_set.rb
Instance Method Summary collapse
- #add(key, value) ⇒ Object
- #concatenate ⇒ Object
-
#initialize ⇒ ParameterSet
constructor
A new instance of ParameterSet.
- #sign(access_key_secret) ⇒ Object
- #string_to_sign ⇒ Object
Constructor Details
#initialize ⇒ ParameterSet
Returns a new instance of ParameterSet.
8 9 10 |
# File 'lib/aliyun-push/parameter_set.rb', line 8 def initialize @params = {} end |
Instance Method Details
#add(key, value) ⇒ Object
12 13 14 |
# File 'lib/aliyun-push/parameter_set.rb', line 12 def add(key, value) @params[key] = value end |
#concatenate ⇒ Object
16 17 18 19 20 |
# File 'lib/aliyun-push/parameter_set.rb', line 16 def concatenate @params.sort_by{ |key, value| key }.to_h.map do |key, value| "#{custom_url_encode(key)}=#{custom_url_encode(value)}" end.join '&' end |
#sign(access_key_secret) ⇒ Object
26 27 28 |
# File 'lib/aliyun-push/parameter_set.rb', line 26 def sign(access_key_secret) Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), access_key_secret + '&', string_to_sign)).strip end |
#string_to_sign ⇒ Object
22 23 24 |
# File 'lib/aliyun-push/parameter_set.rb', line 22 def string_to_sign "GET&%2F&#{CGI.escape(concatenate)}" end |