Module: Hdcore

Defined in:
lib/hdcore/hdcore.rb,
lib/hdcore/request.rb,
lib/hdcore/version.rb

Defined Under Namespace

Classes: Request

Constant Summary collapse

VERSION =
"0.0.20"

Class Method Summary collapse

Class Method Details

.configObject

Current configuration hash


40
41
42
# File 'lib/hdcore/hdcore.rb', line 40

def config
  @config
end

.configure(opts = {}) ⇒ Object

Configure HDCore with an options hash.

Parameters:

  • opts (Hash) (defaults to: {})

    Configuration options hash

Options Hash (opts):

  • :api_endpoint (String) — default: 'core.hostdime.com/api/v1'

    The HDCore API endpoint URI

  • :public_key (String)

    Your HDCore public key

  • :private_key (String)

    Your HDCore private key


19
20
21
22
23
# File 'lib/hdcore/hdcore.rb', line 19

def configure opts = {}
  opts.each do |key, val|
    config[key.to_sym] = val if @valid_config_keys.include? key.to_sym
  end
end

.configure_with(path_to_yaml_file) ⇒ Object

Configure HDCore with an external yaml config file.

Parameters:

  • path_to_yaml_file (String)

    Absolute path to yaml config file


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hdcore/hdcore.rb', line 27

def configure_with path_to_yaml_file
  begin
    config = YAML::load(IO.read(path_to_yaml_file))
  rescue Errno::ENOENT
    log.warn "YAML config file not found: using defaults instead"; return
  rescue Psych::SyntaxError
    log.warn "YAML config file has invalid syntax: using defaults instead"; return
  end

  configure(config)
end

.logObject

For logging purposes


45
46
47
# File 'lib/hdcore/hdcore.rb', line 45

def log
  @log
end

.missing_config_valuesArray

Returns Configuration keys that have no assigned value.

Returns:

  • (Array)

    Configuration keys that have no assigned value.


55
56
57
# File 'lib/hdcore/hdcore.rb', line 55

def missing_config_values
  config.select{|k,v| v.nil?}.keys
end

.missing_config_values?Bool

Returns True if there are configuration keys that have no assigned value.

Returns:

  • (Bool)

    True if there are configuration keys that have no assigned value.


50
51
52
# File 'lib/hdcore/hdcore.rb', line 50

def missing_config_values?
  config.values.include? nil
end