Sha256: 797998d994e97aadbf37881a73d081b298eabd65a2dc6a50fa4a42b7c1f00b90

Contents?: true

Size: 853 Bytes

Versions: 3

Compression:

Stored size: 853 Bytes

Contents

module Buildbox
  class Auth
    def login(options)
      if Buildbox.configuration.api_key
        error "You have already authentication. To unauthenticate, run `buildbox auth:logout`"
      end

      key = options[:api_key]
      api = Buildbox::API.new(:api_key => key)

      if api.login.success?
        Buildbox.configuration.update :api_key, key
        info "Authentication successful"
      end
    end

    def logout
      if Buildbox.configuration.api_key.nil?
        error "You are currently not logged in. To authenticate, run: `buildbox auth:login`"
      end

      Buildbox.configuration.update :api_key, nil
      info "You have successfuly logged out"
    end

    private

    def info(message)
      Buildbox.logger.info message
    end

    def error(message)
      Buildbox.logger.error message
      exit 1
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
buildbox-0.0.4 lib/buildbox/auth.rb
buildbox-0.0.3 lib/buildbox/auth.rb
buildbox-0.0.2 lib/buildbox/auth.rb