Class: Utcp::Auth::ApiKey
Instance Method Summary collapse
- #apply_cookies(existing = "") ⇒ Object
- #apply_headers(h) ⇒ Object
- #apply_query(uri) ⇒ Object
-
#initialize(api_key:, var_name: "Authorization", location: "header") ⇒ ApiKey
constructor
A new instance of ApiKey.
Constructor Details
#initialize(api_key:, var_name: "Authorization", location: "header") ⇒ ApiKey
Returns a new instance of ApiKey.
17 18 19 20 21 |
# File 'lib/utcp/auth.rb', line 17 def initialize(api_key:, var_name: "Authorization", location: "header") @api_key = Utils::Subst.apply(api_key) @var_name = var_name @location = location end |
Instance Method Details
#apply_cookies(existing = "") ⇒ Object
36 37 38 39 40 |
# File 'lib/utcp/auth.rb', line 36 def (existing = "") return existing unless @location == "cookie" = "#{@var_name}=#{@api_key}" existing.to_s.empty? ? : "#{existing}; #{cookie}" end |
#apply_headers(h) ⇒ Object
23 24 25 26 27 |
# File 'lib/utcp/auth.rb', line 23 def apply_headers(h) return h unless @location == "header" h[@var_name] = @api_key h end |
#apply_query(uri) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/utcp/auth.rb', line 29 def apply_query(uri) return uri unless @location == "query" q = URI.decode_www_form(uri.query || "") << [@var_name, @api_key] uri.query = URI.encode_www_form(q) uri end |