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.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 5 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)
34 35 36 37 38 39 40 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 34 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
20 21 22 23 24 25 26 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 20 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)
30 31 32 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 30 def host_with_api_url "#{@host_url}/api/#{@api_version}" end |
#params_string ⇒ Object (private)
42 43 44 45 46 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 42 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)
48 49 50 |
# File 'lib/gitlab/triage/url_builders/url_builder.rb', line 48 def percent_encode(str) CGI.escape(str).gsub('+', '%20') end |