class UniversalGitClient::Http::Base

Attributes

access_token[R]
base_url[R]
download_url[R]
private_token[R]

Public Class Methods

new(base_url:, download_url: nil, access_token: nil, private_token: nil) click to toggle source
# File lib/universal-git-client/http/base.rb, line 14
def initialize(base_url:, download_url: nil, access_token: nil, private_token: nil)
  if access_token && private_token
    raise ArgumentError, 'access_token and private_token params are mutually exclusive'
  end

  @base_url = base_url.chomp('/')
  @download_url = download_url
  @access_token = access_token
  @private_token = private_token
end

Private Instance Methods

default_elements_per_page() click to toggle source
# File lib/universal-git-client/http/base.rb, line 33
def default_elements_per_page
  UniversalGitClient.config.default_pagination
end
default_options() click to toggle source
# File lib/universal-git-client/http/base.rb, line 49
def default_options
  {
    logger: logger,
    log_level: log_level,
    log_format: log_format,
    base_uri: base_url,
    headers: {
      'Accept' => 'application/json',
      'Content-Type' => 'application/json',
      'Authorization' => (access_token ? "Bearer #{access_token}" : nil),
      'Private-Token' => private_token,
      'User-Agent' => user_agent,
    }.compact,
  }
end
down_default_options() click to toggle source
# File lib/universal-git-client/http/base.rb, line 65
def down_default_options
  options = default_options[:headers].reject { |k, _v| %w[Accept Content-Type].include?(k) }
  options.reject { |k, _v| %i[base_uri logger log_level log_format].include?(k) }
  # By default Down allows 2 redirections before raising.
  # We're cranking this up as Bitbucket seems to do more redirects
  # when a project has moved.
  options.merge(max_redirects: 5)
end
log_format() click to toggle source
# File lib/universal-git-client/http/base.rb, line 45
def log_format
  UniversalGitClient.config.log_format
end
log_level() click to toggle source
# File lib/universal-git-client/http/base.rb, line 41
def log_level
  UniversalGitClient.config.log_level
end
logger() click to toggle source
# File lib/universal-git-client/http/base.rb, line 37
def logger
  UniversalGitClient.config.logger
end
user_agent() click to toggle source
# File lib/universal-git-client/http/base.rb, line 29
def user_agent
  UniversalGitClient.config.user_agent
end