Class: Helix::Config

Inherits:
Object show all
Includes:
BuildsUrls, HasSignatures, Paginates, Singleton
Defined in:
lib/helix/config.rb

Constant Summary collapse

DEFAULT_FILENAME =
'./helix.yml'

Constants included from Paginates

Paginates::ITEMS_PER_PAGE, Paginates::STARTING_PAGE

Constants included from HasSignatures

HasSignatures::REQUIRES_CONTRIBUTOR, HasSignatures::SIG_DURATION, HasSignatures::TIME_OFFSET, HasSignatures::VALID_SIG_TYPES

Constants included from BuildsUrls

BuildsUrls::SCOPES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Paginates

#get_aggregated_data_sets, #get_response

Methods included from HasSignatures

#clear_signatures!, #signature

Methods included from BuildsUrls

#add_sub_urls, #build_url, #get_base_url

Instance Attribute Details

#credentialsObject

local


23
24
25
# File 'lib/helix/config.rb', line 23

def credentials
  @credentials
end

#responseObject (readonly)

in Paginates


24
25
26
# File 'lib/helix/config.rb', line 24

def response
  @response
end

#signature_expiration_forObject (readonly)

in HasSignatures


25
26
27
# File 'lib/helix/config.rb', line 25

def signature_expiration_for
  @signature_expiration_for
end

#signature_forObject (readonly)

in HasSignatures


25
26
27
# File 'lib/helix/config.rb', line 25

def signature_for
  @signature_for
end

Class Method Details

.from_hash(desired_credentials) ⇒ Object


47
48
49
# File 'lib/helix/config.rb', line 47

def self.from_hash(desired_credentials)
  load_from_hash(desired_credentials)
end

.load(yaml_file_location = DEFAULT_FILENAME) ⇒ Object


68
69
70
# File 'lib/helix/config.rb', line 68

def self.load(yaml_file_location = DEFAULT_FILENAME)
  load_yaml_file(yaml_file_location)
end

.load_from_hash(desired_credentials) ⇒ Helix::Config

Creates a singleton of itself, setting the config based on the provided Hash argument.

Examples:

Helix::Config.load_from_hash(
  company: 'my-co-nickname',
  site:    'http://service-staging.twistage.com'
)
video = Helix::Video.find("8e0701c142ab1") #Uses my_yaml.yml

Parameters:

  • desired_credentials (Hash)

    the k/v pairs used for config

Returns:


39
40
41
42
43
44
45
# File 'lib/helix/config.rb', line 39

def self.load_from_hash(desired_credentials)
  config = self.instance
  desired_credentials = desired_credentials.symbolize_keys
  config.instance_variable_set(:@credentials, desired_credentials)
  RestClient.proxy = config.proxy
  config
end

.load_yaml_file(yaml_file_location = DEFAULT_FILENAME) ⇒ Helix::Config

Creates a singleton of itself, setting the config to a specified YAML file. If no file is specified the default helix.yml file is used.

Examples:

Helix::Config.load_yaml_file("/some/path/my_yaml.yml")
video = Helix::Video.find("8e0701c142ab1") #Uses my_yaml.yml

Parameters:

  • yaml_file_location (String) (defaults to: DEFAULT_FILENAME)

    the yaml file used for config

Returns:


61
62
63
64
65
66
# File 'lib/helix/config.rb', line 61

def self.load_yaml_file(yaml_file_location = DEFAULT_FILENAME)
  creds  = YAML.load(File.open(yaml_file_location))
  config = load_from_hash(creds)
  config.instance_variable_set(:@filename, yaml_file_location)
  config
end

Instance Method Details

#proxyObject


72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/helix/config.rb', line 72

def proxy
  if @credentials[:proxy_uri]
    protocol, uri = @credentials[:proxy_uri].split "://"
    user, pass    = @credentials[:proxy_username], @credentials[:proxy_password]
    proxy_str     = "#{protocol}://"
    proxy_str    += "#{user}:"  if user
    proxy_str    += "#{pass}"   if user && pass
    proxy_str    += '@'         if user
    proxy_str    += "#{uri}"
  elsif @credentials[:proxy_used] == true
    ENV['http_proxy']
  end
end