Class: Contentful::Bootstrap::Commands::GenerateToken
- Defined in:
- lib/contentful/bootstrap/commands/generate_token.rb
Instance Attribute Summary collapse
-
#token_name ⇒ Object
readonly
Returns the value of attribute token_name.
Attributes inherited from Base
#no_input, #options, #quiet, #space, #token
Instance Method Summary collapse
- #fetch_access_token ⇒ Object
- #fetch_space ⇒ Object
-
#initialize(token, space, options = {}) ⇒ GenerateToken
constructor
A new instance of GenerateToken.
- #run ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(token, space, options = {}) ⇒ GenerateToken
Returns a new instance of GenerateToken.
12 13 14 15 16 |
# File 'lib/contentful/bootstrap/commands/generate_token.rb', line 12 def initialize(token, space, = {}) @token_name = .fetch(:token_name, 'Bootstrap Token') super(token, space, ) end |
Instance Attribute Details
#token_name ⇒ Object (readonly)
Returns the value of attribute token_name.
11 12 13 |
# File 'lib/contentful/bootstrap/commands/generate_token.rb', line 11 def token_name @token_name end |
Instance Method Details
#fetch_access_token ⇒ Object
44 45 46 47 48 49 |
# File 'lib/contentful/bootstrap/commands/generate_token.rb', line 44 def fetch_access_token @actual_space.api_keys.create( name: token_name, description: "Created with 'contentful_bootstrap.rb v#{Contentful::Bootstrap::VERSION}'" ).access_token end |
#fetch_space ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/contentful/bootstrap/commands/generate_token.rb', line 36 def fetch_space @actual_space = if @space.is_a?(String) client.spaces.find(@space) else @space end end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/contentful/bootstrap/commands/generate_token.rb', line 18 def run output 'Creating Delivery API Token' fetch_space access_token = fetch_access_token output "Token '#{token_name}' created! - '#{access_token}'" Support.input('Do you want to write the Delivery Token to your configuration file? (Y/n): ', no_input) do |answer| unless answer.casecmp('n').zero? @token.write_access_token(@actual_space.name, access_token) @token.write_space_id(@actual_space.name, @actual_space.id) end end access_token end |