Class: UrlSigner::Base

Inherits:
Struct
  • Object
show all
Defined in:
lib/url_signer/base.rb

Overview

:nodoc:

Direct Known Subclasses

Signer, Verifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, key: nil, hash_method: nil) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/url_signer/base.rb', line 10

def initialize(url, key: nil, hash_method: nil)
  # load and check url
  url = URI.parse(url) if url.kind_of?(String)
  raise "expecting a String or URI instance" unless url.kind_of?(URI)

  # load and check signing key
  key ||= ENV['URL_SIGNING_KEY']
  raise "You need to provided a signing key to your UrlSigner instance" unless key

  # load the hash method
  hash_method ||= Digest::SHA1

  super(url, key, hash_method)
end

Instance Attribute Details

#hash_methodObject

Returns the value of attribute hash_method

Returns:

  • (Object)

    the current value of hash_method



8
9
10
# File 'lib/url_signer/base.rb', line 8

def hash_method
  @hash_method
end

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



8
9
10
# File 'lib/url_signer/base.rb', line 8

def key
  @key
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



8
9
10
# File 'lib/url_signer/base.rb', line 8

def url
  @url
end

Instance Method Details

#signatureObject



25
26
27
# File 'lib/url_signer/base.rb', line 25

def signature
  compute_signature(url.host, url.path, params)
end