Class: JsonClient::UriBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/json_client/uri_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, ext, name, port = '80', ssl = false) ⇒ UriBuilder

Returns a new instance of UriBuilder.



5
6
7
8
9
10
11
# File 'lib/json_client/uri_builder.rb', line 5

def initialize(host, ext, name, port = '80', ssl = false)
  @host = host
  @ext = ext
  @name = name
  @port = port
  @ssl = ssl
end

Instance Attribute Details

#extObject (readonly)

Returns the value of attribute ext.



3
4
5
# File 'lib/json_client/uri_builder.rb', line 3

def ext
  @ext
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/json_client/uri_builder.rb', line 3

def host
  @host
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/json_client/uri_builder.rb', line 3

def name
  @name
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/json_client/uri_builder.rb', line 3

def port
  @port
end

#sslObject (readonly)

Returns the value of attribute ssl.



3
4
5
# File 'lib/json_client/uri_builder.rb', line 3

def ssl
  @ssl
end

Instance Method Details

#path(id = nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/json_client/uri_builder.rb', line 13

def path(id = nil)
  base = "#{host}:#{port}"
  if id.nil?
    base + "/#{ext}/#{name}"
  else
    base + "/#{ext}/#{name}/#{id}"
  end
end

#uri(id = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/json_client/uri_builder.rb', line 22

def uri(id = nil)
  p = path(id)

  if ssl
    p = "https://#{p}"
  else
    p = "http://#{p}"
  end

  URI(p)
end