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.4.7 lib/engineyard/cli/api.rb
engineyard-1.4.6 lib/engineyard/cli/api.rb
engineyard-1.4.5 lib/engineyard/cli/api.rb
engineyard-1.4.4 lib/engineyard/cli/api.rb
engineyard-1.4.3 lib/engineyard/cli/api.rb
engineyard-1.4.2 lib/engineyard/cli/api.rb
engineyard-1.4.1 lib/engineyard/cli/api.rb
engineyard-1.4.0 lib/engineyard/cli/api.rb
engineyard-1.3.33 lib/engineyard/cli/api.rb
engineyard-1.3.32 lib/engineyard/cli/api.rb
engineyard-1.3.31 lib/engineyard/cli/api.rb
engineyard-1.3.30 lib/engineyard/cli/api.rb
engineyard-1.3.29 lib/engineyard/cli/api.rb
engineyard-1.3.28 lib/engineyard/cli/api.rb
engineyard-1.3.25 lib/engineyard/cli/api.rb
engineyard-1.3.22 lib/engineyard/cli/api.rb
engineyard-1.3.21 lib/engineyard/cli/api.rb
engineyard-1.3.20 lib/engineyard/cli/api.rb
engineyard-1.3.19 lib/engineyard/cli/api.rb
engineyard-1.3.18 lib/engineyard/cli/api.rb