Class: Auth
- Inherits:
-
Object
- Object
- Auth
- Defined in:
- lib/red_drop/auth.rb
Instance Method Summary collapse
-
#initialize ⇒ Auth
constructor
A new instance of Auth.
- #token ⇒ Object
Constructor Details
#initialize ⇒ Auth
Returns a new instance of Auth.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/red_drop/auth.rb', line 4 def initialize puts "loading..." file = File.open("secret.txt", "a+") @secret = file.read file.close @conn = Faraday.new( url: "https://api.digitalocean.com/v2/droplets", headers: {"Authorization" => "Bearer #{@secret}"}, ) @res = @conn.get end |
Instance Method Details
#token ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/red_drop/auth.rb', line 18 def token while @secret.empty? or not @res.success? puts "\nThere in no valid API token in memory,\nplease enter a valid API token." @secret = gets.chomp File.write("secret.txt", @secret) @conn.headers["Authorization"] = "Bearer #{@secret}" @res = @conn.get end @conn end |