Class: UriSigner::Signer
- Inherits:
-
Object
- Object
- UriSigner::Signer
- Defined in:
- lib/uri_signer/signer.rb
Overview
This is the object that wraps the other building blocks and can be used to sign requests.
Instance Method Summary collapse
-
#http_method ⇒ String
Returns the uppercased HTTP Method.
-
#initialize(http_method, uri, secret) ⇒ void
constructor
Create a new UriSigner instance.
-
#signature ⇒ String
Returns the signature.
-
#uri ⇒ String
Returns the URI passed into the constructor.
-
#uri_with_signature ⇒ Object
Returns the URI with the signature appended to the query string.
-
#valid?(other) ⇒ Bool
Returns true if
other
matches the proper signature.
Constructor Details
#initialize(http_method, uri, secret) ⇒ void
Create a new UriSigner instance
37 38 39 40 41 42 43 44 45 |
# File 'lib/uri_signer/signer.rb', line 37 def initialize(http_method, uri, secret) @http_method = http_method @uri = uri @secret = secret raise UriSigner::Errors::MissingHttpMethodError.new("Please provide an HTTP method") unless http_method? raise UriSigner::Errors::MissingUriError.new("Please provide a URI") unless uri? raise UriSigner::Errors::MissingSecretError.new("Please provide a secret to sign the string") unless secret? end |
Instance Method Details
#http_method ⇒ String
Returns the uppercased HTTP Method
66 67 68 |
# File 'lib/uri_signer/signer.rb', line 66 def http_method @http_method.to_s.upcase end |
#signature ⇒ String
Returns the signature
73 74 75 |
# File 'lib/uri_signer/signer.rb', line 73 def signature uri_signature.signature end |
#uri ⇒ String
Returns the URI passed into the constructor
50 51 52 |
# File 'lib/uri_signer/signer.rb', line 50 def uri @uri end |
#uri_with_signature ⇒ Object
Returns the URI with the signature appended to the query string
return [String]
57 58 59 60 61 |
# File 'lib/uri_signer/signer.rb', line 57 def uri_with_signature separator = if request_parser.query_params? then '&' else '?' end encoded_signature = signature.extend(UriSigner::Helpers::String).escaped "%s%s_signature=%s" % [self.uri, separator, encoded_signature] end |
#valid?(other) ⇒ Bool
Returns true if other
matches the proper signature
80 81 82 |
# File 'lib/uri_signer/signer.rb', line 80 def valid?(other) self.signature === other end |