Sha256: a6b571662cb23ad35f12b8718e0005ed923dad7d1a933212dfdec8b8e9dbd51b

Contents?: true

Size: 1.16 KB

Versions: 13

Compression:

Stored size: 1.16 KB

Contents

module Gitlab
  module Triage
    module UrlBuilders
      class UrlBuilder
        def initialize(options)
          @host_url = options.fetch(:host_url)
          @api_version = options.fetch(:api_version)
          @source = options.fetch(:source, 'projects')
          @source_id = options.fetch(:source_id)
          @resource_type = options.fetch(:resource_type)
          @sub_resource_type = options.fetch(:sub_resource_type, nil)
          @resource_id = options.fetch(:resource_id, nil)
          @params = options.fetch(:params, [])
        end

        def build
          base_url.tap do |url|
            url << "/#{@resource_id}" if @resource_id
            url << "/#{@sub_resource_type}" if @sub_resource_type
            url << params_string if @params
          end
        end

        private

        def host_with_api_url
          "#{@host_url}/api/#{@api_version}"
        end

        def base_url
          "#{host_with_api_url}/#{@source}/#{CGI.escape(@source_id.to_s)}/#{@resource_type}"
        end

        def params_string
          "?" << @params.map do |k, v|
            "#{k}=#{v}"
          end.join("&")
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
gitlab-triage-0.14.1 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.14.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.13.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.12.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.11.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.10.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.9.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.8.1 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.8.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.7.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.6.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.5.0 lib/gitlab/triage/url_builders/url_builder.rb
gitlab-triage-0.4.0 lib/gitlab/triage/url_builders/url_builder.rb