Class: Vertebrae::Configuration
- Inherits:
-
Object
- Object
- Vertebrae::Configuration
- Includes:
- ActiveSupport::Inflector, Authorization, Constants
- Defined in:
- lib/vertebrae/configuration.rb
Constant Summary collapse
- VALID_OPTIONS_KEYS =
[ :prefix, :ssl, :mime_type, :user_agent, :host, :username, :password, :connection_options, :content_type, :scheme, :port, :additional_headers ].freeze
- DEFAULT_SCHEME =
The default HTTP scheme configuration
'https'
- DEFAULT_SSL =
The default SSL configuration
{}
- DEFAULT_PORT =
by default do not set a port so that it is not specified on endpoint
nil
- DEFAULT_MIME_TYPE =
By default the
Accept
header will make a request forJSON
: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
- DEFAULT_ADDITIONAL_HEADERS =
{}.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
-
#default_options ⇒ Object
Returns the value of attribute default_options.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #adapter ⇒ Object
- #adapter=(value) ⇒ Object
- #endpoint ⇒ Object
- #faraday_options ⇒ Object
-
#initialize(options) ⇒ Configuration
constructor
A new instance of Configuration.
-
#process_basic_auth(auth) ⇒ Object
Extract login and password from basic_auth parameter.
Methods included from Authorization
#authenticated?, #authentication, #basic_auth, #password?, #username?
Constructor Details
#initialize(options) ⇒ Configuration
Returns a new instance of Configuration.
84 85 86 87 88 89 90 91 |
# File 'lib/vertebrae/configuration.rb', line 84 def initialize() self. = self. = {} VALID_OPTIONS_KEYS.each do |key| [key] = "Vertebrae::Configuration::DEFAULT_#{key.to_s.upcase}".constantize end end |
Instance Attribute Details
#default_options ⇒ Object
Returns the value of attribute default_options.
82 83 84 |
# File 'lib/vertebrae/configuration.rb', line 82 def @default_options end |
#options ⇒ Object
Returns the value of attribute options.
81 82 83 |
# File 'lib/vertebrae/configuration.rb', line 81 def @options end |
Instance Method Details
#adapter ⇒ Object
73 74 75 |
# File 'lib/vertebrae/configuration.rb', line 73 def adapter [:adapter] || ::Faraday.default_adapter end |
#adapter=(value) ⇒ Object
77 78 79 |
# File 'lib/vertebrae/configuration.rb', line 77 def adapter=(value) [:adapter] = value end |
#endpoint ⇒ Object
119 120 121 |
# File 'lib/vertebrae/configuration.rb', line 119 def endpoint "#{self.scheme}://#{self.host}#{self.port.present? ? ":#{self.port}" : ''}#{self.prefix}" end |
#faraday_options ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vertebrae/configuration.rb', line 93 def { :headers => { ACCEPT => "application/json;q=0.1", ACCEPT_CHARSET => "utf-8", USER_AGENT => user_agent, CONTENT_TYPE => content_type }.merge(additional_headers), :ssl => ssl, :url => endpoint }.merge() end |
#process_basic_auth(auth) ⇒ Object
Extract login and password from basic_auth parameter
109 110 111 112 113 114 115 116 117 |
# File 'lib/vertebrae/configuration.rb', line 109 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 |