Sha256: 5173e2ddb347267f0b484a7c6dd2dd422c661f7cc2e79db726ff03519a9ec651

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require "voltos/version"

require "curb"
require "json"

module Voltos
  class << self
    attr_accessor :configuration
  end

  def self.configure
    self.configuration ||= Configuration.new
    yield(configuration)
  end
  
  def self.load
    json_str = Curl.get("https://voltos.online/v1/credentials") do |http|
      http.headers["Authorization"] = "Token token=#{Voltos.configuration.api_key}"
    end
    Voltos.configuration.json_creds = JSON.parse(json_str.body_str)
    Voltos.configuration.status  = Voltos.configuration.json_creds["status"]
    Voltos.configuration.message = Voltos.configuration.json_creds["message"]
  end
  
  def self.bundles
    Voltos.configuration.json_creds["data"]["bundles"].keys
  end
  
  def self.key(bundle_name, env_key)
    if not bundle_name.empty?
      Voltos.configuration.json_creds["data"]["bundles"][bundle_name][env_key]
    else
      Voltos.configuration.json_creds["data"]["unbundled"][env_key]
    end
  end
  
  def self.status
    return Voltos.configuration.status
  end
  
  def self.message
    return Voltos.configuration.message
  end
  
  class Configuration
    attr_accessor :api_key
    attr_accessor :json_creds
    attr_accessor :status
    attr_accessor :message

    def initialize
      @api_key = ""
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
voltos-0.0.93 lib/voltos.rb
voltos-0.0.91 lib/voltos.rb