Sha256: 09fe9bf8b9dea700d574a8ee2f2357e909b4084956d9db4449c2066068c8983b

Contents?: true

Size: 978 Bytes

Versions: 49

Compression:

Stored size: 978 Bytes

Contents

module EY
  class CLI
    class API < EY::API

      def initialize(token = nil)
        @token = token
        @token ||= self.class.read_token
        @token ||= self.class.fetch_token
        raise EY::Error, "Sorry, we couldn't get your API token." unless @token
      end

      def request(*)
        begin
          super
        rescue EY::API::InvalidCredentials
          EY.ui.warn "Credentials rejected; please authenticate again."
          refresh
          retry
        end
      end

      def refresh
        @token = self.class.fetch_token
      end

      def self.fetch_token
        EY.ui.info("We need to fetch your API token; please log in.")
        begin
          email    = EY.ui.ask("Email: ")
          password = EY.ui.ask("Password: ", true)
          super(email, password)
        rescue EY::API::InvalidCredentials
          EY.ui.warn "Invalid username or password; please try again."
          retry
        end
      end

    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
engineyard-1.1.2 lib/engineyard/cli/api.rb
engineyard-1.1.1 lib/engineyard/cli/api.rb
engineyard-1.1.0 lib/engineyard/cli/api.rb
engineyard-1.0.2 lib/engineyard/cli/api.rb
engineyard-1.0.1 lib/engineyard/cli/api.rb
engineyard-1.0.0 lib/engineyard/cli/api.rb
engineyard-0.10.0 lib/engineyard/cli/api.rb
engineyard-0.9.0 lib/engineyard/cli/api.rb
engineyard-0.8.2 lib/engineyard/cli/api.rb