Class: Bubbles::RestEnvironment
- Inherits:
-
Object
- Object
- Bubbles::RestEnvironment
- Defined in:
- lib/bubbles/rest_environment.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_key_name ⇒ String
Retrieve the name of the API key to be used.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#get_api_key_if_needed(endpoint) ⇒ String
Retrieve an API key from this
RestEnvironment
, but only if a specificEndpoint
requires it. -
#initialize(scheme = 'https', host = 'api.foamfactory.com', port = 443, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestEnvironment
constructor
Construct a new instance of
RestEnvironment
. -
#scheme ⇒ Symbol
Retrieve the scheme of the current
RestEnvironment
, as aSymbol
.
Constructor Details
#initialize(scheme = 'https', host = 'api.foamfactory.com', port = 443, api_key = nil, api_key_name = 'X-API-Key') ⇒ RestEnvironment
Construct a new instance of RestEnvironment
.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/bubbles/rest_environment.rb', line 3 def api_key @api_key end |
#api_key_name ⇒ String
Retrieve the name of the API key to be used.
This will be the “key” portion of the key-value of the API key header.
36 37 38 |
# File 'lib/bubbles/rest_environment.rb', line 36 def api_key_name @api_key_name end |
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/bubbles/rest_environment.rb', line 3 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/bubbles/rest_environment.rb', line 3 def port @port end |
Instance Method Details
#get_api_key_if_needed(endpoint) ⇒ String
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.
50 51 52 53 54 55 56 |
# 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 |
#scheme ⇒ Symbol
Retrieve the scheme of the current RestEnvironment
, as a Symbol
.
63 64 65 |
# File 'lib/bubbles/rest_environment.rb', line 63 def scheme @scheme.to_s end |