Module: CobotClient::UrlHelper

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

Constant Summary collapse

@@site =

set this to override the site for accessing the cobot api

'https://www.cobot.me'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.siteObject



7
8
9
# File 'lib/cobot_client/url_helper.rb', line 7

def self.site
  @@site
end

.site=(site) ⇒ Object



11
12
13
# File 'lib/cobot_client/url_helper.rb', line 11

def self.site=(site)
  @@site = site
end

Instance Method Details

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

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



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cobot_client/url_helper.rb', line 17

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(CobotClient::UrlHelper.site)
  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] && options[:params].any?

  url.to_s
end