class Rapa::Signer

Public Class Methods

new(host:, http_method:, key:, path:, query_string:) click to toggle source

@param host [String] @param http_method [String] @param key [String] @param path [String] @param query_string [String]

# File lib/rapa/signer.rb, line 12
def initialize(host:, http_method:, key:, path:, query_string:)
  @host = host
  @http_method = http_method
  @key = key
  @path = path
  @query_string = query_string
end

Public Instance Methods

sign() click to toggle source

@return [String]

# File lib/rapa/signer.rb, line 21
def sign
  ::CGI.escape(
    ::Base64.encode64(
      ::OpenSSL::HMAC.digest(
        digest,
        key,
        source,
      ),
    ).chomp
  )
end

Private Instance Methods

digest() click to toggle source

@private @return [OpenSSL::Digest]

# File lib/rapa/signer.rb, line 37
def digest
  ::OpenSSL::Digest.new("sha256")
end
host() click to toggle source

@private @return [String]

# File lib/rapa/signer.rb, line 43
def host
  @host
end
http_method() click to toggle source

@private @return [String]

# File lib/rapa/signer.rb, line 49
def http_method
  @http_method
end
key() click to toggle source

@private @return [String]

# File lib/rapa/signer.rb, line 55
def key
  @key
end
path() click to toggle source

@private @return [String]

# File lib/rapa/signer.rb, line 61
def path
  @path
end
query_string() click to toggle source

@private @return [String]

# File lib/rapa/signer.rb, line 67
def query_string
  @query_string
end
source() click to toggle source

@private @return [String]

# File lib/rapa/signer.rb, line 73
def source
  [
    http_method,
    host,
    path,
    query_string,
  ].join("\n")
end