Class: AliyunPush::ParameterSet

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun-push/parameter_set.rb

Instance Method Summary collapse

Constructor Details

#initializeParameterSet

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

#concatenateObject



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_signObject



22
23
24
# File 'lib/aliyun-push/parameter_set.rb', line 22

def string_to_sign
  "GET&%2F&#{CGI.escape(concatenate)}"
end