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,
].freeze
DEFAULT_ADAPTER =

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

:net_http
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

Returns a new instance of Configuration.



69
70
71
72
73
74
75
76
# File 'lib/configuration.rb', line 69

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.



67
68
69
# File 'lib/configuration.rb', line 67

def default_options
  @default_options
end

#optionsObject

Returns the value of attribute options.



66
67
68
# File 'lib/configuration.rb', line 66

def options
  @options
end

Instance Method Details

#endpointObject



106
107
108
# File 'lib/configuration.rb', line 106

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

#faraday_optionsObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/configuration.rb', line 79

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



95
96
97
98
99
100
101
102
103
# File 'lib/configuration.rb', line 95

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