Class: JsonClient::UriBuilder
- Inherits:
-
Object
- Object
- JsonClient::UriBuilder
- Defined in:
- lib/json_client/uri_builder.rb
Instance Attribute Summary collapse
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
Instance Method Summary collapse
-
#initialize(host, ext, name, port = '80', ssl = false) ⇒ UriBuilder
constructor
A new instance of UriBuilder.
- #path(id = nil) ⇒ Object
- #uri(id = nil) ⇒ Object
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
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
3 4 5 |
# File 'lib/json_client/uri_builder.rb', line 3 def ext @ext end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
3 4 5 |
# File 'lib/json_client/uri_builder.rb', line 3 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/json_client/uri_builder.rb', line 3 def name @name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
3 4 5 |
# File 'lib/json_client/uri_builder.rb', line 3 def port @port end |
#ssl ⇒ Object (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 |