Class: ApiSignature::Signer
- Inherits:
-
Object
- Object
- ApiSignature::Signer
- Defined in:
- lib/api_signature/signer.rb
Overview
The signer requires secret key.
signer = ApiSignature::Signer.new('access key', 'secret key', uri_escape_path: true)
Constant Summary collapse
- NAME =
'API-HMAC-SHA256'
Instance Method Summary collapse
-
#initialize(access_key, secret_key, options = {}) ⇒ Signer
constructor
Options:.
-
#sign_request(request) ⇒ Signature
Computes a signature.
Constructor Details
#initialize(access_key, secret_key, options = {}) ⇒ Signer
Options:
31 32 33 34 35 |
# File 'lib/api_signature/signer.rb', line 31 def initialize(access_key, secret_key, = {}) @access_key = access_key @secret_key = secret_key @options = end |
Instance Method Details
#sign_request(request) ⇒ Signature
Computes a signature. Returns the resultant signature as a hash of headers to apply to your HTTP request. The given request is not modified.
signature = signer.sign_request(
http_method: 'PUT',
url: 'https://domain.com',
headers: {
'Abc' => 'xyz',
},
body: 'body' # String or IO object
)
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/api_signature/signer.rb', line 67 def sign_request(request) builder = Builder.new(request, unsigned_headers) sig_headers = builder.build_sign_headers(apply_checksum_header?) data = build_signature(builder) # apply signature sig_headers[signature_header_name] = data[:header] # Returning the signature components. Signature.new(data.merge!(headers: sig_headers)) end |