class Contentful::Bootstrap::Token
Constants
- CONFIG_ENV
- DEFAULT_PATH
- DEFAULT_SECTION
- DELIVERY_TOKEN
- MANAGEMENT_TOKEN
- ORGANIZATION_ID
- SPACE_ID
Attributes
config_path[R]
Public Class Methods
new(config_path = '')
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 16 def initialize(config_path = '') @config_path = config_path end
Public Instance Methods
==(other)
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 20 def ==(other) return false unless other.is_a?(Contentful::Bootstrap::Token) other.config_path == @config_path end
config_file()
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 68 def config_file @config_file ||= ::File.exist?(filename) ? IniFile.load(filename) : IniFile.new(filename: filename) end
config_section()
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 63 def config_section return ENV[CONFIG_ENV] if config_file.has_section? ENV[CONFIG_ENV] DEFAULT_SECTION end
filename()
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 58 def filename return config_path unless config_path.empty? ::File.join(ENV['HOME'], DEFAULT_PATH) end
present?()
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 25 def present? return false unless ::File.exist? filename config_file[config_section].key? MANAGEMENT_TOKEN end
read()
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 30 def read config_file[config_section].fetch(MANAGEMENT_TOKEN) rescue KeyError raise 'Token not found' end
read_organization_id()
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 36 def read_organization_id config_file[config_section].fetch(ORGANIZATION_ID, nil) end
write(value, section = nil, key = MANAGEMENT_TOKEN)
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 40 def write(value, section = nil, key = MANAGEMENT_TOKEN) file = config_file file[section || config_section][key] = value file.save end
write_access_token(space_name, token)
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 50 def write_access_token(space_name, token) write(token, space_name, DELIVERY_TOKEN) end
write_organization_id(organization_id)
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 46 def write_organization_id(organization_id) write(organization_id, nil, ORGANIZATION_ID) end
write_space_id(space_name, space_id)
click to toggle source
# File lib/contentful/bootstrap/token.rb, line 54 def write_space_id(space_name, space_id) write(space_id, space_name, SPACE_ID) end