Sha256: 3f0d20bdab99b5e3742be70242b8ef749d7258d0253df852e6db6e9814b4399f

Contents?: true

Size: 754 Bytes

Versions: 28

Compression:

Stored size: 754 Bytes

Contents

require 'uri'

module CobotClient::UrlHelper
  # set this to override the site for accessing the cobot api

  @@site = 'https://www.cobot.me'
  def self.site
    @@site
  end

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

  # generates a url to access the cobot api
  # see the spec for usage examples
  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
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
cobot_client-5.0.0 lib/cobot_client/url_helper.rb
cobot_client-4.0.0 lib/cobot_client/url_helper.rb
cobot_client-3.1.0 lib/cobot_client/url_helper.rb
cobot_client-3.0.0 lib/cobot_client/url_helper.rb
cobot_client-2.1.0 lib/cobot_client/url_helper.rb
cobot_client-2.0.0 lib/cobot_client/url_helper.rb
cobot_client-1.4.2 lib/cobot_client/url_helper.rb
cobot_client-1.4.0 lib/cobot_client/url_helper.rb
cobot_client-1.3.1 lib/cobot_client/url_helper.rb
cobot_client-1.3.0 lib/cobot_client/url_helper.rb
cobot_client-1.2.4 lib/cobot_client/url_helper.rb
cobot_client-1.2.3 lib/cobot_client/url_helper.rb
cobot_client-1.2.2 lib/cobot_client/url_helper.rb
cobot_client-1.2.1 lib/cobot_client/url_helper.rb
cobot_client-1.2.0 lib/cobot_client/url_helper.rb
cobot_client-1.1.1 lib/cobot_client/url_helper.rb
cobot_client-1.1.0 lib/cobot_client/url_helper.rb
cobot_client-1.0.0 lib/cobot_client/url_helper.rb
cobot_client-0.8.0 lib/cobot_client/url_helper.rb
cobot_client-0.7.0 lib/cobot_client/url_helper.rb