Class: Gitlab::Triage::UrlBuilders::UrlBuilder
- Inherits:
-
Object
- Object
- Gitlab::Triage::UrlBuilders::UrlBuilder
- Defined in:
- lib/gitlab/triage/url_builders/url_builder.rb
Instance Method Summary collapse
- #base_url ⇒ Object private
- #build ⇒ Object
- #host_with_api_url ⇒ Object private
-
#initialize(options) ⇒ UrlBuilder
constructor
A new instance of UrlBuilder.
- #params_string ⇒ Object private
- #percent_encode(str) ⇒ Object private
Constructor Details
#initialize(options) ⇒ UrlBuilder
Returns a new instance of UrlBuilder.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 7 def initialize() @network_options = .fetch(:network_options) @host_url = @network_options.host_url @api_version = @network_options.api_version @all = .fetch(:all, false) @source = .fetch(:source, 'projects') @source_id = .fetch(:source_id) @resource_type = .fetch(:resource_type, nil) @sub_resource_type = .fetch(:sub_resource_type, nil) @resource_id = .fetch(:resource_id, nil) @params = .fetch(:params, []) @params = @params.merge(scope: :all) if @all end |
Instance Method Details
#base_url ⇒ Object (private)
36 37 38 39 40 41 42 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 36 def base_url url = host_with_api_url url << "/#{@source}/#{percent_encode(@source_id.to_s)}" unless @all url << "/repository" if @resource_type == 'branches' url << "/#{@resource_type}" if @resource_type url end |
#build ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 22 def build url = base_url url << "/#{percent_encode(@resource_id.to_s)}" if @resource_id url << "/#{@sub_resource_type}" if @sub_resource_type url << params_string if @params url end |
#host_with_api_url ⇒ Object (private)
32 33 34 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 32 def host_with_api_url "#{@host_url}/api/#{@api_version}" end |
#params_string ⇒ Object (private)
44 45 46 47 48 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 44 def params_string "?" << @params.map do |k, v| "#{percent_encode(k.to_s)}=#{percent_encode(v.to_s)}" end.join("&") end |
#percent_encode(str) ⇒ Object (private)
50 51 52 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 50 def percent_encode(str) CGI.escape(str).gsub('+', '%20') end |