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
Instance Method Summary collapse
- #fetch_access_token ⇒ Object
- #fetch_space ⇒ Object
-
#initialize(token, space, token_name = 'Bootstrap Token', trigger_oauth = true) ⇒ GenerateToken
constructor
A new instance of GenerateToken.
- #run ⇒ Object
Methods included from Support
Constructor Details
#initialize(token, space, token_name = 'Bootstrap Token', trigger_oauth = true) ⇒ 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 = 'Bootstrap Token', trigger_oauth = true) super(token, space, trigger_oauth) @token_name = token_name @actual_space = space unless space.is_a?(String) 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
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/contentful/bootstrap/commands/generate_token.rb', line 39 def fetch_access_token response = Contentful::Management::Request.new( "/#{@actual_space.id}/api_keys", 'name' => token_name, 'description' => "Created with 'contentful_bootstrap.rb v#{Contentful::Bootstrap::VERSION}'" ).post fail response if response.object.is_a?(Contentful::Management::Error) response.object['accessToken'] end |
#fetch_space ⇒ Object
35 36 37 |
# File 'lib/contentful/bootstrap/commands/generate_token.rb', line 35 def fetch_space @actual_space ||= Contentful::Management::Space.find(@space) end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/contentful/bootstrap/commands/generate_token.rb', line 18 def run puts 'Creating Delivery API Token' fetch_space access_token = fetch_access_token puts "Token '#{token_name}' created! - '#{access_token}'" print 'Do you want to write the Delivery Token to your configuration file? (Y/n): ' unless gets.chomp.downcase == 'n' @token.write_access_token(@actual_space.name, access_token) @token.write_space_id(@actual_space.name, @actual_space.id) end access_token end |