Sha256: b191fb96a159d8c445d5be26410f3a56382b1e8a4ccef86aed0b58f3e3922256

Contents?: true

Size: 700 Bytes

Versions: 6

Compression:

Stored size: 700 Bytes

Contents

require 'active_support/core_ext/module/attribute_accessors'
require 'uri'

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

  # 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(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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cobot_client-0.5.0 lib/cobot_client/url_helper.rb
cobot_client-0.4.0 lib/cobot_client/url_helper.rb
cobot_client-0.3.0 lib/cobot_client/url_helper.rb
cobot_client-0.2.0 lib/cobot_client/url_helper.rb
cobot_client-0.1.0 lib/cobot_client/url_helper.rb
cobot_client-0.0.1 lib/cobot_client/url_helper.rb