Module: CobotClient::UrlHelper

Included in:
NavigationLinkService
Defined in:
lib/cobot_client/url_helper.rb

Instance Method Summary collapse

Instance Method Details

#cobot_url(subdomain = 'www', *path_options) ⇒ Object

generates a url to access the cobot api see the spec for usage examples



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cobot_client/url_helper.rb', line 10

def cobot_url(subdomain = 'www', *path_options)
  path = path_options.first.is_a?(String) ? path_options.first : '/'
  options = path_options.find{|p| p.is_a?(Hash)} || {}

  url = URI.parse(site || 'https://www.cobot.me')
  url.host = url.host.split('.').tap{|parts| parts[0] = subdomain}.join('.')
  url.path = path
  url.query = URI.encode_www_form(options[:params]) if options[:params]

  url.to_s
end