Set the @server variable externally
Creates the Endpoint object with default values for internal variables Params:
initial_path
Starting point of the URL this class will build
# File lib/client/helper/endpoint.rb, line 10 def initialize(initial_path) @path = { default: initial_path } @server = nil @protocol = "http://" end
Add a section to the path Params:
key
Symbol, the key to identify the section
value
Any value to store with the associated key
# File lib/client/helper/endpoint.rb, line 27 def add(key, value) @path[key.to_sym] = value end
Deletes a value from the internal hash based on a key Params:
key
Symbol, the key to identify the section
# File lib/client/helper/endpoint.rb, line 41 def delete(key) @path.delete(key) end
Checks whether a key exists Params:
key
Symbol, the key to identify the section
# File lib/client/helper/endpoint.rb, line 48 def exists?(key) @path.key? key end
Return a value based on the provided key Params:
key
Symbol, the key to identify the section
# File lib/client/helper/endpoint.rb, line 34 def get(key) @path[key.to_sym] end
Set endpoint protocol Params:
use_https
Boolean value for whether to use HTTPS
# File lib/client/helper/endpoint.rb, line 19 def protocol=(use_https) @protocol = 'https://' if use_https end
Override the #to_s method to return an endpoint fragment
# File lib/client/helper/endpoint.rb, line 53 def to_s output = @protocol + @server @path.each_pair do |_k, value| output += value end output end