Class: GoogleBusinessApiUrlSigner::Signer
- Inherits:
-
Object
- Object
- GoogleBusinessApiUrlSigner::Signer
- Defined in:
- lib/google_business_api_url_signer/signer.rb
Overview
Public: Takes care of signing URLs
Google’s documentation for this can be found here: developers.google.com/maps/documentation/business/webservices#generating_valid_signatures
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Signer
constructor
Public: Initializes the signer.
- #private_key ⇒ Object
-
#signature ⇒ Object
Public: Calculates the signature from the given URL and private key.
-
#signed_url ⇒ Object
Public: Calculates the signature and returns a signed version of the URL.
Constructor Details
#initialize(options = {}) ⇒ Signer
Public: Initializes the signer
options - url must be given within the options,
private_key can be given, or you can set default value with:
GoogleBusinessApiUrlSigner::Signer.default_private_key = 'key'
22 23 24 25 26 |
# File 'lib/google_business_api_url_signer/signer.rb', line 22 def initialize( = {}) @url = .fetch :url @private_key = .fetch :private_key, default_private_key @private_key = default_private_key if @private_key.blank? end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
14 15 16 |
# File 'lib/google_business_api_url_signer/signer.rb', line 14 def url @url end |
Instance Method Details
#private_key ⇒ Object
28 29 30 31 |
# File 'lib/google_business_api_url_signer/signer.rb', line 28 def private_key return @private_key if @private_key.present? fail MissingPrivateKeyError end |
#signature ⇒ Object
Public: Calculates the signature from the given URL and private key
34 35 36 |
# File 'lib/google_business_api_url_signer/signer.rb', line 34 def signature Base64.urlsafe_encode64 signature_digest end |
#signed_url ⇒ Object
Public: Calculates the signature and returns a signed version of the URL
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/google_business_api_url_signer/signer.rb', line 39 def signed_url [ parsed_url.scheme, '://', parsed_url.host, parsed_url.path, '?', query_params_as_string_with_signature ].join.html_safe end |