Class: Contentful::Bootstrap::Token
- Inherits:
-
Object
- Object
- Contentful::Bootstrap::Token
- Defined in:
- lib/contentful/bootstrap/token.rb
Constant Summary collapse
- CONFIG_ENV =
"CONTENTFUL_ENV".freeze
- DEFAULT_SECTION =
"global".freeze
- DEFAULT_PATH =
".contentfulrc".freeze
- MANAGEMENT_TOKEN =
"CONTENTFUL_MANAGEMENT_ACCESS_TOKEN".freeze
- DELIVERY_TOKEN =
"CONTENTFUL_DELIVERY_ACCESS_TOKEN".freeze
- SPACE_ID =
"SPACE_ID".freeze
Class Method Summary collapse
- .config_file ⇒ Object
- .config_path ⇒ Object
- .config_section ⇒ Object
- .filename ⇒ Object
- .present? ⇒ Boolean
- .read ⇒ Object
- .set_path!(config_path = "") ⇒ Object
- .write(value, section = nil, key = MANAGEMENT_TOKEN) ⇒ Object
- .write_access_token(space_name, token) ⇒ Object
- .write_space_id(space_name, space_id) ⇒ Object
Class Method Details
.config_file ⇒ Object
54 55 56 |
# File 'lib/contentful/bootstrap/token.rb', line 54 def self.config_file File.exist?(filename) ? IniFile.load(filename) : IniFile.new(filename: filename) end |
.config_path ⇒ Object
58 59 60 |
# File 'lib/contentful/bootstrap/token.rb', line 58 def self.config_path @@config_path ||= "" end |
.config_section ⇒ Object
49 50 51 52 |
# File 'lib/contentful/bootstrap/token.rb', line 49 def self.config_section return ENV[CONFIG_ENV] if config_file.has_section? ENV[CONFIG_ENV] DEFAULT_SECTION end |
.filename ⇒ Object
44 45 46 47 |
# File 'lib/contentful/bootstrap/token.rb', line 44 def self.filename return config_path if File.exist?(config_path) File.join(ENV['HOME'], DEFAULT_PATH) end |
.present? ⇒ Boolean
17 18 19 20 |
# File 'lib/contentful/bootstrap/token.rb', line 17 def self.present? return false unless File.exists? filename config_file[config_section].has_key? MANAGEMENT_TOKEN end |
.read ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/contentful/bootstrap/token.rb', line 22 def self.read begin config_file[config_section].fetch(MANAGEMENT_TOKEN) rescue KeyError fail "Token not found" end end |
.set_path!(config_path = "") ⇒ Object
13 14 15 |
# File 'lib/contentful/bootstrap/token.rb', line 13 def self.set_path!(config_path = "") @@config_path = config_path end |
.write(value, section = nil, key = MANAGEMENT_TOKEN) ⇒ Object
30 31 32 33 34 |
# File 'lib/contentful/bootstrap/token.rb', line 30 def self.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) ⇒ Object
36 37 38 |
# File 'lib/contentful/bootstrap/token.rb', line 36 def self.write_access_token(space_name, token) write(token, space_name, DELIVERY_TOKEN) end |
.write_space_id(space_name, space_id) ⇒ Object
40 41 42 |
# File 'lib/contentful/bootstrap/token.rb', line 40 def self.write_space_id(space_name, space_id) write(space_id, space_name, SPACE_ID) end |