class Bubbles::RestEnvironment
Attributes
Public Class Methods
Construct a new instance of RestEnvironment
.
@param [String] scheme The scheme to use for communicating with the host. Currently, http and https are supported. @param [String] host The host to communicate with. @param [Integer] port The port on which the communication channel should operate. @param [String] api_key
(Optional) The API key to use to identify your client with the API. Defaults to nil
. @param [String] api_key_name
(Optional) The name of the header that will specify the API key. Defaults to +“X-API-Key”+.
# File lib/bubbles/rest_environment.rb, line 14 def initialize(scheme='https', host='api.foamfactory.com', port=443, api_key=nil, api_key_name='X-API-Key') @scheme = scheme @port = port if @scheme == 'http' && @port == nil @port = 80 elsif @scheme == 'https' && @port == nil @port = 443 end @host = host @api_key = api_key @api_key_name = api_key_name end
Public Instance Methods
Retrieve an API key from this RestEnvironment
, but only if a specific Endpoint
requires it.
If an Endpoint
has api_key_required
set to true
, this method will return the API for the current RestEnvironment
. If not, then it will return nil
, rather than just blindly returning the API key for every possible retrieval, even if the Endpoint
doesn't require it.
@return [String] The API key for this RestEnvironment
, if the specified Endpoint
requires it; nil
,
otherwise.
# File lib/bubbles/rest_environment.rb, line 50 def get_api_key_if_needed(endpoint) if endpoint.api_key_required? @api_key else nil end end
Retrieve the scheme of the current RestEnvironment
, as a Symbol
.
@return [Symbol] The scheme of the current RestEnvironment
, as a Symbol
.
# File lib/bubbles/rest_environment.rb, line 63 def scheme @scheme.to_s end