Class: Http2::UrlBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/http2/url_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUrlBuilder

Returns a new instance of UrlBuilder.



4
5
6
# File 'lib/http2/url_builder.rb', line 4

def initialize
  @params = {}
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



2
3
4
# File 'lib/http2/url_builder.rb', line 2

def host
  @host
end

#paramsObject

Returns the value of attribute params.



2
3
4
# File 'lib/http2/url_builder.rb', line 2

def params
  @params
end

#pathObject

Returns the value of attribute path.



2
3
4
# File 'lib/http2/url_builder.rb', line 2

def path
  @path
end

#portObject

Returns the value of attribute port.



2
3
4
# File 'lib/http2/url_builder.rb', line 2

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



2
3
4
# File 'lib/http2/url_builder.rb', line 2

def protocol
  @protocol
end

Instance Method Details

#buildObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/http2/url_builder.rb', line 41

def build
  url = ""
  url << "#{protocol}://" if protocol

  if host
    url << host
    url << ":#{port}/" if port
  end

  url << build_path_and_params

  url
end

#build_paramsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/http2/url_builder.rb', line 8

def build_params
  url_params = ""

  unless params.empty?
    first = true

    params.each do |key, val|
      if first
        first = false
      else
        url_params << "&"
      end

      url_params << Http2::Utils.urlenc(key)
      url_params << "="
      url_params << Http2::Utils.urlenc(val)
    end
  end

  url_params
end

#build_path_and_paramsObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/http2/url_builder.rb', line 30

def build_path_and_params
  url = path.to_s

  if params?
    url << "?"
    url << build_params
  end

  url
end

#params?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/http2/url_builder.rb', line 55

def params?
  @params.any?
end