Class: Vertebrae::Configuration

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::Inflector, Authorization, Constants
Defined in:
lib/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
    :adapter,
    :prefix,
    :ssl,
    :mime_type,
    :user_agent,
    :host,
    :username,
    :password,
    :connection_options,
    :content_type,
    :scheme,
].freeze
DEFAULT_ADAPTER =

Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test

:net_http
DEFAULT_SCHEME =

The default HTTP scheme configuration

'https'
DEFAULT_SSL =

The default SSL configuration

{}
DEFAULT_MIME_TYPE =

By default the Accept header will make a request for JSON

:json
DEFAULT_USER_AGENT =

The value sent in the http header for ‘User-Agent’ if none is set

"Vertebrae REST Gem".freeze
DEFAULT_HOST =

by default do not set a host. this is specific to AK instance

nil
DEFAULT_PREFIX =

The api endpoint used to connect to AK if none is set

'/'.freeze
DEFAULT_USERNAME =

By default, don’t set a user ame

nil
DEFAULT_PASSWORD =

By default, don’t set a user password

nil
DEFAULT_CONNECTION_OPTIONS =

By default uses the Faraday connection options if none is set

{}
DEFAULT_CONTENT_TYPE =
'application/json'.freeze

Constants included from Constants

Vertebrae::Constants::ACCEPT, Vertebrae::Constants::ACCEPT_CHARSET, Vertebrae::Constants::CACHE_CONTROL, Vertebrae::Constants::CONTENT_LENGTH, Vertebrae::Constants::CONTENT_TYPE, Vertebrae::Constants::DATE, Vertebrae::Constants::ETAG, Vertebrae::Constants::LOCATION, Vertebrae::Constants::RATELIMIT_LIMIT, Vertebrae::Constants::RATELIMIT_REMAINING, Vertebrae::Constants::SERVER, Vertebrae::Constants::USER_AGENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Authorization

#authenticated?, #authentication, #basic_auth, #password?, #username?

Constructor Details

#initialize(options) ⇒ Configuration



73
74
75
76
77
78
79
80
# File 'lib/configuration.rb', line 73

def initialize(options)
  self.options = options
  self.default_options = {}

  VALID_OPTIONS_KEYS.each do |key|
    default_options[key] = "Vertebrae::Configuration::DEFAULT_#{key.to_s.upcase}".constantize
  end
end

Instance Attribute Details

#default_optionsObject

Returns the value of attribute default_options.



71
72
73
# File 'lib/configuration.rb', line 71

def default_options
  @default_options
end

#optionsObject

Returns the value of attribute options.



70
71
72
# File 'lib/configuration.rb', line 70

def options
  @options
end

Instance Method Details

#endpointObject



110
111
112
# File 'lib/configuration.rb', line 110

def endpoint
  "#{self.scheme}://#{self.host}#{self.prefix}"
end

#faraday_optionsObject



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/configuration.rb', line 83

def faraday_options
  {
    :headers => {
      ACCEPT           => "application/json;q=0.1",
      ACCEPT_CHARSET   => "utf-8",
      USER_AGENT       => user_agent,
      CONTENT_TYPE     => content_type
    },
    :ssl =>  ssl,
    :url => endpoint
  }
end

#process_basic_auth(auth) ⇒ Object

Extract login and password from basic_auth parameter



99
100
101
102
103
104
105
106
107
# File 'lib/configuration.rb', line 99

def process_basic_auth(auth)
  case auth
    when String
      self.username, self.password = auth.split(':', 2)
    when Hash
      self.username = auth[:username]
      self.password = auth[:password]
  end
end