class MdNotes::Configuration

All configuration including auth info and base URI for the API access are configured in this class.

Constants

ENVIRONMENTS

All the environments the SDK can run in.

Attributes

environments[R]
backoff_factor[R]
environment[R]
http_client[R]

The attribute readers for properties.

max_retries[R]
o_auth_client_id[R]
o_auth_client_secret[R]
o_auth_password[R]
o_auth_username[R]
retry_interval[R]
retry_methods[R]
retry_statuses[R]
timeout[R]

Public Class Methods

new(timeout: 60, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put], environment: Environment::PRODUCTION, o_auth_client_id: 'TODO: Replace', o_auth_client_secret: 'TODO: Replace', o_auth_username: 'TODO: Replace', o_auth_password: 'TODO: Replace', o_auth_token: nil) click to toggle source
# File lib/md_notes/configuration.rb, line 50
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
               backoff_factor: 2,
               retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
               retry_methods: %i[get put],
               environment: Environment::PRODUCTION,
               o_auth_client_id: 'TODO: Replace',
               o_auth_client_secret: 'TODO: Replace',
               o_auth_username: 'TODO: Replace',
               o_auth_password: 'TODO: Replace', o_auth_token: nil)
  # The value to use for connection timeout
  @timeout = timeout

  # The number of times to retry an endpoint call if it fails
  @max_retries = max_retries

  # Pause in seconds between retries
  @retry_interval = retry_interval

  # The amount to multiply each successive retry's interval amount
  # by in order to provide backoff
  @backoff_factor = backoff_factor

  # A list of HTTP statuses to retry
  @retry_statuses = retry_statuses

  # A list of HTTP methods to retry
  @retry_methods = retry_methods

  # Current API environment
  @environment = String(environment)

  # OAuth 2 Client ID
  @o_auth_client_id = o_auth_client_id

  # OAuth 2 Client Secret
  @o_auth_client_secret = o_auth_client_secret

  # OAuth 2 Resource Owner Username
  @o_auth_username = o_auth_username

  # OAuth 2 Resource Owner Password
  @o_auth_password = o_auth_password

  # Object for storing information about the OAuth token
  @o_auth_token = if o_auth_token.is_a? OAuthToken
                    OAuthToken.from_hash o_auth_token.to_hash
                  else
                    o_auth_token
                  end

  # The Http Client to use for making requests.
  @http_client = create_http_client
end

Public Instance Methods

clone_with(timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, environment: nil, o_auth_client_id: nil, o_auth_client_secret: nil, o_auth_username: nil, o_auth_password: nil, o_auth_token: nil) click to toggle source
# File lib/md_notes/configuration.rb, line 104
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
               backoff_factor: nil, retry_statuses: nil, retry_methods: nil,
               environment: nil, o_auth_client_id: nil,
               o_auth_client_secret: nil, o_auth_username: nil,
               o_auth_password: nil, o_auth_token: nil)
  timeout ||= self.timeout
  max_retries ||= self.max_retries
  retry_interval ||= self.retry_interval
  backoff_factor ||= self.backoff_factor
  retry_statuses ||= self.retry_statuses
  retry_methods ||= self.retry_methods
  environment ||= self.environment
  o_auth_client_id ||= self.o_auth_client_id
  o_auth_client_secret ||= self.o_auth_client_secret
  o_auth_username ||= self.o_auth_username
  o_auth_password ||= self.o_auth_password
  o_auth_token ||= self.o_auth_token

  Configuration.new(timeout: timeout, max_retries: max_retries,
                    retry_interval: retry_interval,
                    backoff_factor: backoff_factor,
                    retry_statuses: retry_statuses,
                    retry_methods: retry_methods, environment: environment,
                    o_auth_client_id: o_auth_client_id,
                    o_auth_client_secret: o_auth_client_secret,
                    o_auth_username: o_auth_username,
                    o_auth_password: o_auth_password,
                    o_auth_token: o_auth_token)
end
create_http_client() click to toggle source
# File lib/md_notes/configuration.rb, line 134
def create_http_client
  FaradayClient.new(timeout: timeout, max_retries: max_retries,
                    retry_interval: retry_interval,
                    backoff_factor: backoff_factor,
                    retry_statuses: retry_statuses,
                    retry_methods: retry_methods)
end
get_base_uri(server = Server::DEFAULT) click to toggle source

Generates the appropriate base URI for the environment and the server. @param [Configuration::Server] The server enum for which the base URI is required. @return [String] The base URI.

# File lib/md_notes/configuration.rb, line 153
def get_base_uri(server = Server::DEFAULT)
  ENVIRONMENTS[environment][server].clone
end
o_auth_token() click to toggle source
# File lib/md_notes/configuration.rb, line 38
def o_auth_token
  if @o_auth_token.is_a? OAuthToken
    OAuthToken.from_hash @o_auth_token.to_hash
  else
    @o_auth_token
  end
end