Sha256: 23cf63cc569f4b82031f5c99c6b69496e04d6fce0b95fcac39737a5839af303d

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

class Ey::Hmac::Adapter::Faraday < Ey::Hmac::Adapter
  def method
    request[:method].to_s.upcase
  end

  def content_type
    %w[CONTENT-TYPE CONTENT_TYPE Content-Type Content_Type].inject(nil) { |r,h| r || request[:request_headers][h] }
  end

  def content_digest
    if existing = %w[CONTENT-DIGEST CONTENT_DIGEST Content-Digest Content_Digest].inject(nil) { |r,h| r || request[:request_headers][h] }
      existing
    elsif digestable = body && Digest::MD5.hexdigest(body)
      request[:request_headers]['Content-Digest'] = digestable
    else nil
    end
  end

  def body
    if request[:body] && request[:body].to_s != ""
      request[:body]
    else nil
    end
  end

  def date
    existing = %w[DATE Date].inject(nil) { |r,h| r || request[h] }
    existing || (request[:request_headers]['Date'] = Time.now.httpdate)
  end

  def path
    request[:url].path
  end

  def sign!(key_id, key_secret)
    %w[CONTENT-TYPE CONTENT_TYPE Content-Type Content_Type].inject(nil){|r,h| request[:request_headers][h]}
    if options[:version]
      request[:request_headers]['X-Signature-Version'] = options[:version]
    end

    request[:request_headers][authorization_header] = authorization(key_id, key_secret)
  end

  def authorization_signature
    %w[Authorization AUTHORIZATION].inject(nil){|r, h| r || request[:request_headers][h]}
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ey-hmac-2.0.0 lib/ey-hmac/adapter/faraday.rb
ey-hmac-1.0.0 lib/ey-hmac/adapter/faraday.rb
ey-hmac-0.1.3 lib/ey-hmac/adapter/faraday.rb
ey-hmac-0.1.2 lib/ey-hmac/adapter/faraday.rb
ey-hmac-0.1.1 lib/ey-hmac/adapter/faraday.rb