Class: Coyodlee::UriBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, cobrand_name: 'restserver', version: 'v1') ⇒ UriBuilder

Returns a new instance of UriBuilder.


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

def initialize(host:, cobrand_name: 'restserver', version: 'v1')
  @cobrand_name = cobrand_name
  @version = version
  @host = host
  @path_prefix = 'ysl'
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host


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

def host
  @host
end

Instance Method Details

#build(resource_path, query: nil, use_ssl: true) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/coyodlee/uri_builder.rb', line 12

def build(resource_path, query: nil, use_ssl: true)
  uri_builder = use_ssl ? URI::HTTPS : URI::HTTP
  revised_resource_path = if resource_path.start_with?('/')
                            resource_path.slice(1..-1)
                          else
                            resource_path
                          end
  path = [@path_prefix, @cobrand_name, @version, revised_resource_path]
           .compact
           .join('/')
           .prepend('/')
  uri_builder.build(host: @host, path: path, query: query)
end