class Contentful::Bootstrap::Commands::Base
Attributes
no_input[R]
options[R]
quiet[R]
space[R]
token[R]
Public Class Methods
new(token, space, options = {})
click to toggle source
# File lib/contentful/bootstrap/commands/base.rb, line 12 def initialize(token, space, options = {}) trigger_oauth = options.fetch(:trigger_oauth, true) @token = token @options = options @quiet = options.fetch(:quiet, false) @no_input = options.fetch(:no_input, false) configuration if trigger_oauth client if trigger_oauth @space = space end
Public Instance Methods
client()
click to toggle source
# File lib/contentful/bootstrap/commands/base.rb, line 29 def client @client ||= ::Contentful::Management::Client.new( @token.read, default_locale: options.fetch(:locale, 'en-US'), raise_errors: true, application_name: 'bootstrap', application_version: ::Contentful::Bootstrap::VERSION ) end
run()
click to toggle source
# File lib/contentful/bootstrap/commands/base.rb, line 25 def run raise 'must implement' end
Protected Instance Methods
output(text = nil)
click to toggle source
# File lib/contentful/bootstrap/commands/base.rb, line 41 def output(text = nil) Support.output(text, @quiet) end
Private Instance Methods
configuration()
click to toggle source
# File lib/contentful/bootstrap/commands/base.rb, line 47 def configuration if @token.present? output 'OAuth token found, moving on!' return end Support.input('OAuth Token not found, do you want to create a new configuration file? (Y/n): ', no_input) do |answer| if answer.casecmp('n').zero? output 'Exiting!' exit end end raise 'OAuth token required to proceed' if no_input output "Configuration will be saved on #{@token.filename}" output 'A new tab on your browser will open for requesting OAuth permissions' token_server output end
token_server()
click to toggle source
# File lib/contentful/bootstrap/commands/base.rb, line 68 def token_server Support.silence_stderr do # Don't show any WEBrick related stuff server = Contentful::Bootstrap::Server.new(@token) server.start sleep(1) until server.running? # Wait for Server Init Net::HTTP.get(URI('http://localhost:5123')) sleep(1) until @token.present? # Wait for User to do OAuth cycle server.stop end end