Class: Aitch::URI
Instance Method Summary collapse
- #fragment ⇒ Object
-
#initialize(url, data = {}, request_has_body = false) ⇒ URI
constructor
rubocop:disable Style/OptionalBooleanParameter.
- #path ⇒ Object
- #query ⇒ Object
- #request_has_body? ⇒ Boolean
- #request_uri ⇒ Object
Constructor Details
#initialize(url, data = {}, request_has_body = false) ⇒ URI
rubocop:disable Style/OptionalBooleanParameter
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/aitch/uri.rb', line 9 def initialize(url, data = {}, request_has_body = false) # rubocop:disable Style/OptionalBooleanParameter @url = url @data = data @request_has_body = request_has_body begin @uri = ::URI.parse(url) rescue ::URI::InvalidURIError => error raise InvalidURIError, error end end |
Instance Method Details
#fragment ⇒ Object
33 34 35 |
# File 'lib/aitch/uri.rb', line 33 def fragment "##{@uri.fragment}" if @uri.fragment end |
#path ⇒ Object
25 26 27 |
# File 'lib/aitch/uri.rb', line 25 def path File.join("/", @uri.path) end |
#query ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/aitch/uri.rb', line 37 def query query = [@uri.query] if !request_has_body? && @data.respond_to?(:to_a) query << ::URI.encode_www_form(@data.to_a) end query = query.compact.reject(&:empty?).join("&") "?#{query}" unless query == "" end |
#request_has_body? ⇒ Boolean
21 22 23 |
# File 'lib/aitch/uri.rb', line 21 def request_has_body? @request_has_body end |
#request_uri ⇒ Object
29 30 31 |
# File 'lib/aitch/uri.rb', line 29 def request_uri [path, query, fragment].compact.join end |