Module: Octokit::Default

Defined in:
lib/octokit/default.rb

Overview

Default configuration options for Client

Constant Summary collapse

API_ENDPOINT =

Default API endpoint

'https://api.github.com'
USER_AGENT =

Default User Agent header string

"Octokit Ruby Gem #{Octokit::VERSION}"
MEDIA_TYPE =

Default media type

'application/vnd.github.v3+json'
WEB_ENDPOINT =

Default WEB endpoint

'https://github.com'
MIDDLEWARE =

Default Faraday middleware stack

Faraday::RackBuilder.new do |builder|
  # In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem
  # so we use it only when it's available.
  if defined?(Faraday::Request::Retry)
    builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError]
  elsif defined?(Faraday::Retry::Middleware)
    builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError]
  end

  builder.use Octokit::Middleware::FollowRedirects
  builder.use Octokit::Response::RaiseError
  builder.use Octokit::Response::FeedParser
  builder.adapter Faraday.default_adapter
end

Class Method Summary collapse

Class Method Details

.access_tokenString

Default access token from ENV

Returns:

  • (String)

57
58
59
# File 'lib/octokit/default.rb', line 57

def access_token
  ENV.fetch('OCTOKIT_ACCESS_TOKEN', nil)
end

.api_endpointString

Default API endpoint from ENV or API_ENDPOINT

Returns:

  • (String)

63
64
65
# File 'lib/octokit/default.rb', line 63

def api_endpoint
  ENV.fetch('OCTOKIT_API_ENDPOINT') { API_ENDPOINT }
end

.auto_paginateString

Default pagination preference from ENV

Returns:

  • (String)

69
70
71
# File 'lib/octokit/default.rb', line 69

def auto_paginate
  ENV.fetch('OCTOKIT_AUTO_PAGINATE', nil)
end

.bearer_tokenString

Default bearer token from ENV

Returns:

  • (String)

75
76
77
# File 'lib/octokit/default.rb', line 75

def bearer_token
  ENV.fetch('OCTOKIT_BEARER_TOKEN', nil)
end

.client_idString

Default OAuth app key from ENV

Returns:

  • (String)

81
82
83
# File 'lib/octokit/default.rb', line 81

def client_id
  ENV.fetch('OCTOKIT_CLIENT_ID', nil)
end

.client_secretString

Default OAuth app secret from ENV

Returns:

  • (String)

87
88
89
# File 'lib/octokit/default.rb', line 87

def client_secret
  ENV.fetch('OCTOKIT_SECRET', nil)
end

.connection_optionsHash

Default options for Faraday::Connection

Returns:

  • (Hash)

105
106
107
108
109
110
111
112
# File 'lib/octokit/default.rb', line 105

def connection_options
  {
    headers: {
      accept: default_media_type,
      user_agent: user_agent
    }
  }
end

.default_media_typeString

Default media type from ENV or MEDIA_TYPE

Returns:

  • (String)

116
117
118
# File 'lib/octokit/default.rb', line 116

def default_media_type
  ENV.fetch('OCTOKIT_DEFAULT_MEDIA_TYPE') { MEDIA_TYPE }
end

.loginString

Default GitHub username for Basic Auth from ENV

Returns:

  • (String)

122
123
124
# File 'lib/octokit/default.rb', line 122

def 
  ENV.fetch('OCTOKIT_LOGIN', nil)
end

.management_console_endpointString

Default management console endpoint from ENV

Returns:

  • (String)

99
100
101
# File 'lib/octokit/default.rb', line 99

def management_console_endpoint
  ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT', nil)
end

.management_console_passwordString

Default management console password from ENV

Returns:

  • (String)

93
94
95
# File 'lib/octokit/default.rb', line 93

def management_console_password
  ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD', nil)
end

.middlewareFaraday::RackBuilder or Faraday::Builder

Default middleware stack for Faraday::Connection from MIDDLEWARE

Returns:

  • (Faraday::RackBuilder or Faraday::Builder)

129
130
131
# File 'lib/octokit/default.rb', line 129

def middleware
  MIDDLEWARE
end

.netrcBoolean

Default behavior for reading .netrc file

Returns:

  • (Boolean)

176
177
178
# File 'lib/octokit/default.rb', line 176

def netrc
  ENV.fetch('OCTOKIT_NETRC', false)
end

.netrc_fileString

Default path for .netrc file

Returns:

  • (String)

182
183
184
# File 'lib/octokit/default.rb', line 182

def netrc_file
  ENV.fetch('OCTOKIT_NETRC_FILE') { File.join(Dir.home.to_s, '.netrc') }
end

.optionsHash

Configuration options

Returns:

  • (Hash)

51
52
53
# File 'lib/octokit/default.rb', line 51

def options
  Octokit::Configurable.keys.map { |key| [key, send(key)] }.to_h
end

.passwordString

Default GitHub password for Basic Auth from ENV

Returns:

  • (String)

135
136
137
# File 'lib/octokit/default.rb', line 135

def password
  ENV.fetch('OCTOKIT_PASSWORD', nil)
end

.per_pageInteger

Default pagination page size from ENV

Returns:

  • (Integer)

    Page size


141
142
143
144
145
# File 'lib/octokit/default.rb', line 141

def per_page
  page_size = ENV.fetch('OCTOKIT_PER_PAGE', nil)

  page_size&.to_i
end

.proxyString

Default proxy server URI for Faraday connection from ENV

Returns:

  • (String)

149
150
151
# File 'lib/octokit/default.rb', line 149

def proxy
  ENV.fetch('OCTOKIT_PROXY', nil)
end

.ssl_verify_modeInteger

Default SSL verify mode from ENV

Returns:

  • (Integer)

155
156
157
158
159
160
# File 'lib/octokit/default.rb', line 155

def ssl_verify_mode
  # 0 is OpenSSL::SSL::VERIFY_NONE
  # 1 is OpenSSL::SSL::SSL_VERIFY_PEER
  # the standard default for SSL is SSL_VERIFY_PEER which requires a server certificate check on the client
  ENV.fetch('OCTOKIT_SSL_VERIFY_MODE', 1).to_i
end

.user_agentString

Default User-Agent header string from ENV or USER_AGENT

Returns:

  • (String)

164
165
166
# File 'lib/octokit/default.rb', line 164

def user_agent
  ENV.fetch('OCTOKIT_USER_AGENT') { USER_AGENT }
end

.web_endpointString

Default web endpoint from ENV or WEB_ENDPOINT

Returns:

  • (String)

170
171
172
# File 'lib/octokit/default.rb', line 170

def web_endpoint
  ENV.fetch('OCTOKIT_WEB_ENDPOINT') { WEB_ENDPOINT }
end