class Avo::Services::URIService
def append_paths(*paths)
def append_paths(*paths) paths = Array.wrap(paths).flatten return self if paths.blank? # Add the intermediary forward slash @uri.path = @uri.path.concat("/") unless @uri.path.ends_with? "/" # Add the paths to the URI @uri.merge!(path: @uri.path.concat(join_paths(paths))) self end
def append_query(params)
def append_query(params) params = if params.is_a? Hash params.map do |key, value| "#{key}=#{value}" end else {} end return self if params.blank? # Add the query params to the URI @uri.merge!(query: [@uri.query, *params].compact.join("&")) self end
def call
def call to_s end
def initialize(path = "")
def initialize(path = "") @uri = Addressable::URI.parse(path) end
def join_paths(paths)
def join_paths(paths) paths .map do |path| sanitize_path path end .join("/") end
def parse(path)
def parse(path) new path end
def sanitize_path(path)
def sanitize_path(path) if path.to_s.starts_with? "/" path = path[1..] end ERB::Util.url_encode path end
def to_s
def to_s @uri.to_s end