Class: Aitch::URI
Instance Method Summary collapse
- #fragment ⇒ Object
-
#initialize(url, data = {}, request_has_body = false) ⇒ URI
constructor
A new instance of URI.
- #path ⇒ Object
- #query ⇒ Object
- #request_has_body? ⇒ Boolean
- #request_uri ⇒ Object
Constructor Details
#initialize(url, data = {}, request_has_body = false) ⇒ URI
Returns a new instance of URI.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/aitch/uri.rb', line 8 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 |
Instance Method Details
#fragment ⇒ Object
32 33 34 |
# File 'lib/aitch/uri.rb', line 32 def fragment "##{@uri.fragment}" if @uri.fragment end |
#path ⇒ Object
24 25 26 |
# File 'lib/aitch/uri.rb', line 24 def path File.join("/", @uri.path) end |
#query ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/aitch/uri.rb', line 36 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 |
#request_has_body? ⇒ Boolean
20 21 22 |
# File 'lib/aitch/uri.rb', line 20 def request_has_body? @request_has_body end |
#request_uri ⇒ Object
28 29 30 |
# File 'lib/aitch/uri.rb', line 28 def request_uri [path, query, fragment].compact.join("") end |