module CobotClient::UrlHelper

Public Class Methods

site() click to toggle source
# File lib/cobot_client/url_helper.rb, line 7
def self.site
  @@site
end
site=(site) click to toggle source
# File lib/cobot_client/url_helper.rb, line 11
def self.site=(site)
  @@site = site
end

Public Instance Methods

cobot_url(subdomain = 'www', *path_options) click to toggle source

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

# 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