Class: Bloomy::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/bloomy/configuration.rb

Overview

The Configuration class is responsible for managing the authentication

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Configuration

Initializes a new Configuration instance

Examples:

config = Bloomy::Configuration.new(api_key)

Parameters:

  • optional_parameter (String, nil)

    Pass an optional API key



17
18
19
# File 'lib/bloomy/configuration.rb', line 17

def initialize(api_key = nil)
  @api_key = api_key || ENV["BG_API_KEY"] || load_api_key
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



10
11
12
# File 'lib/bloomy/configuration.rb', line 10

def api_key
  @api_key
end

Instance Method Details

#configure_api_key(username, password, store_key: false) ⇒ void

Note:

This method only fetches and stores the API key if it is currently nil. It saves the key under ‘~/.bloomy/config.yaml’ if ‘store_key: true’ is passed.

This method returns an undefined value.

Configures the API key using the provided username and password

Examples:

config.configure_api_key("user", "pass", store_key: true)
config.api_key
# => 'xxxx...'

Parameters:

  • username (String)

    the username for authentication

  • password (String)

    the password for authentication

  • store_key (Boolean) (defaults to: false)

    whether to store the API key (default: false)



33
34
35
36
# File 'lib/bloomy/configuration.rb', line 33

def configure_api_key(username, password, store_key: false)
  @api_key = fetch_api_key(username, password)
  store_api_key if store_key
end