Sha256: d1e77861f3efe7d95217f613aa292f31646e4fa23fbef28ef5b95d63a22c193b

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

module Bamboo
  module Client
    module Http
      class Abstract
        attr_reader :uri

        def initialize(url)
          @uri = URI.parse url
        end

        private

        # argument is only an uri if its coming from a result set.
        # in this case, we don't need to prefix the path anymore.
        def uri_for(uri_or_path, params = nil)
          if uri_or_path.kind_of? URI
            u = uri_or_path.dup

            u.host   = @uri.host
            u.port   = @uri.port
            u.scheme = @uri.scheme
          else
            u = uri.dup
            u.path = File.join(uri.path, uri_or_path)
          end

          u.query = query_string_for(params) if params
          u.to_s
        end

        def query_string_for(params)
          params.map { |k, v| "#{k.to_s}=#{CGI.escape(v.to_s)}" }.join('&')
        end

      end # Abstract
    end # Http
  end # Client
end # Bamboo

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bamboo-client-0.1.9 lib/bamboo-client/http/abstract.rb