Sha256: a3af07e331ad28e5b5f8b93f725987300855da3838c1e1199b29f7af0c90bb6b

Contents?: true

Size: 700 Bytes

Versions: 6

Compression:

Stored size: 700 Bytes

Contents

module Net
  class Authorization
    def initialize(options = {})
      @options = options

      if !basic? && !token?
        raise "Invalid arguments given for Authorization"
      end
    end

    def to_s
      if basic?
        base_64 = Base64.encode("#{username}:#{password}")
        return "Basic #{base_64}"
      end
      if token?
        return 'Token token="' + token + '"'
      end
    end

    def username
      @options.fetch(:username, false)
    end

    def password
      @options.fetch(:password, false)
    end

    def token
      @options.fetch(:token, false)
    end

    def basic?
      !!username && !!password
    end

    def token?
      !!token
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
motion-flow-0.1.8 flow/net/authorization.rb
motion-flow-0.1.7 flow/net/authorization.rb
motion-flow-0.1.6 flow/net/authorization.rb
motion-flow-0.1.5 flow/net/authorization.rb
motion-flow-0.1.4 flow/net/authorization.rb
motion-flow-0.1.3 flow/net/authorization.rb