class Pili::Credentials
Attributes
access_key[R]
secret_key[R]
Public Class Methods
base64_url_encode(string)
click to toggle source
# File lib/pili/credentials.rb, line 20 def base64_url_encode(string) Base64.encode64(string).tr("+/", "-_").gsub(/[\n\r]?/, "") end
digest(secret, bytes)
click to toggle source
# File lib/pili/credentials.rb, line 24 def digest(secret, bytes) OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), secret, bytes) end
generate_signature(options = {})
click to toggle source
# File lib/pili/credentials.rb, line 32 def generate_signature(options = {}) method = options[:method] url = options[:url] content_type = options[:content_type] body = options[:body] uri = URI.parse(url) signature = "#{method} #{uri.path}" query_string = uri.query if !query_string.nil? && !query_string.empty? signature += '?' + query_string end signature += "\nHost: #{uri.host}" if !content_type.nil? && !content_type.empty? && content_type != "application/octet-stream" signature += "\nContent-Type: #{content_type}" end signature += "\n\n" if body.is_a?(Hash) signature += body.to_json end return signature end
new(access_key, secret_key)
click to toggle source
# File lib/pili/credentials.rb, line 12 def initialize(access_key, secret_key) @access_key = access_key @secret_key = secret_key end
sign(secret, bytes)
click to toggle source
# File lib/pili/credentials.rb, line 28 def sign(secret, bytes) base64_url_encode(digest(secret, bytes)) end