Module: RongCloud::Signature

Included in:
Request
Defined in:
lib/rong_cloud/signature.rb

Overview

a seperate module to perform api signature www.rongcloud.cn/docs/server.html#通用API接口签名规则

Instance Method Summary collapse

Instance Method Details

#signature(nonce, timestamp) ⇒ String

generate the final signature

Parameters:

  • nonce (String)

    a random string with a whatever length

  • timestamp (String)

    timestamp, the elapsed seconds from 1970-01-01 00:00:00 UTC

Returns:

  • (String)

    the final signature



14
15
16
17
# File 'lib/rong_cloud/signature.rb', line 14

def signature(nonce, timestamp)
  str = "#{RongCloud::Configuration.app_secret}#{nonce}#{timestamp}"
  Digest::SHA1.hexdigest(str)
end

#signed_headersHash

Note:

consist of the following request headers: App-Key Nonce Timestamp Signature

get required request headers

Returns:

  • (Hash)

    headers represented as a Ruby hash



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rong_cloud/signature.rb', line 26

def signed_headers
  nonce = rand(10**6)
  timestamp = Time.now.to_i
  signature = signature(nonce, timestamp)

  {
    'App-Key' => RongCloud::Configuration.app_key,
    'Nonce' => nonce,
    'Timestamp' => timestamp,
    'Signature' => signature
  }
end