Sha256: b1110427025fdf6e434287ce2a63564d7928d94a9b58145bd54489c426103591
Contents?: true
Size: 923 Bytes
Versions: 3
Compression:
Stored size: 923 Bytes
Contents
# frozen_string_literal: true module Aitch class URI extend Forwardable def_delegators :@uri, :host, :port, :scheme def initialize(url, data = {}, request_has_body = false) @url = url @data = data @request_has_body = request_has_body begin @uri = ::URI.parse(url) rescue ::URI::InvalidURIError => error raise InvalidURIError, error end end def request_has_body? @request_has_body end def path File.join("/", @uri.path) end def request_uri [path, query, fragment].compact.join("") end def fragment "##{@uri.fragment}" if @uri.fragment end def query query = [@uri.query] query << ::URI.encode_www_form(@data.to_a) if !request_has_body? && @data.respond_to?(:to_a) query = query.compact.reject(&:empty?).join("&") "?#{query}" unless query == "" end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aitch-1.0.2 | lib/aitch/uri.rb |
aitch-1.0.1 | lib/aitch/uri.rb |
aitch-1.0.0 | lib/aitch/uri.rb |