Class: Blitz::Command::API
- Inherits:
-
Blitz::Command
- Object
- Blitz::Command
- Blitz::Command::API
- Defined in:
- lib/blitz/command/api.rb
Overview
:nodoc:
Constant Summary
Constants inherited from Blitz::Command
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
Class Method Summary collapse
Instance Method Summary collapse
- #ask_for_credentials ⇒ Object
- #client ⇒ Object
- #cmd_init(argv) ⇒ Object
- #credentials_file ⇒ Object
- #get_credentials ⇒ Object
- #host ⇒ Object
- #password ⇒ Object
- #read_credentials ⇒ Object
- #save_credentials ⇒ Object
- #set_credentials_permissions ⇒ Object
- #user ⇒ Object
- #write_credentials ⇒ Object
Methods included from Utils
Methods included from Helper
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
4 5 6 |
# File 'lib/blitz/command/api.rb', line 4 def credentials @credentials end |
Class Method Details
.client ⇒ Object
86 87 88 |
# File 'lib/blitz/command/api.rb', line 86 def self.client self.instance.client end |
.instance ⇒ Object
82 83 84 |
# File 'lib/blitz/command/api.rb', line 82 def self.instance @instance ||= API.new end |
Instance Method Details
#ask_for_credentials ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/blitz/command/api.rb', line 50 def ask_for_credentials msg "Enter your blitz credentials. You can find this in #{green('Settings/API Key')}." print "User-ID: " user = ask print "API-Key: " apik = ask apik2 = Blitz::Client.new(user, apik, host).login['api_key'] if not apik2 error "Authentication failed" exit 1 end [ user, apik2 ] end |
#client ⇒ Object
14 15 16 17 |
# File 'lib/blitz/command/api.rb', line 14 def client get_credentials Blitz::Client.new(user, password, host) end |
#cmd_init(argv) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/blitz/command/api.rb', line 6 def cmd_init argv FileUtils.rm credentials_file rescue nil API.client msg "You are now ready to blitz!" msg "Try blitz help to learn more about the commands." end |
#credentials_file ⇒ Object
33 34 35 |
# File 'lib/blitz/command/api.rb', line 33 def credentials_file ENV['HOME'] + '/.blitz/credentials' end |
#get_credentials ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/blitz/command/api.rb', line 37 def get_credentials return if @credentials unless @credentials = read_credentials @credentials = ask_for_credentials save_credentials end @credentials end |
#host ⇒ Object
29 30 31 |
# File 'lib/blitz/command/api.rb', line 29 def host ENV['BLITZ_HOST'] || 'www.blitz.io' end |
#password ⇒ Object
24 25 26 27 |
# File 'lib/blitz/command/api.rb', line 24 def password get_credentials @credentials[1] end |
#read_credentials ⇒ Object
46 47 48 |
# File 'lib/blitz/command/api.rb', line 46 def read_credentials File.exists?(credentials_file) and File.read(credentials_file).split("\n") end |
#save_credentials ⇒ Object
65 66 67 |
# File 'lib/blitz/command/api.rb', line 65 def save_credentials write_credentials end |
#set_credentials_permissions ⇒ Object
77 78 79 80 |
# File 'lib/blitz/command/api.rb', line 77 def FileUtils.chmod 0700, File.dirname(credentials_file) FileUtils.chmod 0600, credentials_file end |
#user ⇒ Object
19 20 21 22 |
# File 'lib/blitz/command/api.rb', line 19 def user get_credentials @credentials[0] end |
#write_credentials ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/blitz/command/api.rb', line 69 def write_credentials FileUtils.mkdir_p(File.dirname(credentials_file)) File.open(credentials_file, 'w') do |f| f.puts self.credentials end end |