Class: DurableHuggingfaceHub::Types::User

Inherits:
Struct
  • Object
show all
Includes:
Loadable
Defined in:
lib/durable_huggingface_hub/types/user.rb

Overview

Information about a HuggingFace Hub user.

Examples:

Creating a User from API response

user = User.from_hash({
  "name" => "john_doe",
  "fullname" => "John Doe",
  "email" => "john@example.com",
  "isPro" => false
})

Accessing user information

user.name      # => "john_doe"
user.fullname  # => "John Doe"
user.pro?      # => false

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authHash? (readonly)

Returns Authentication information including token details.

Returns:

  • (Hash, nil)

    Authentication information including token details



58
# File 'lib/durable_huggingface_hub/types/user.rb', line 58

attribute :auth, Types::Hash.optional.default(nil)

#avatar_urlString? (readonly)

Returns Avatar image URL.

Returns:

  • (String, nil)

    Avatar image URL



46
# File 'lib/durable_huggingface_hub/types/user.rb', line 46

attribute :avatar_url, Types::OptionalString.default(nil)

#emailString? (readonly)

Returns Email address.

Returns:

  • (String, nil)

    Email address



42
# File 'lib/durable_huggingface_hub/types/user.rb', line 42

attribute :email, Types::OptionalString.default(nil)

#fullnameString? (readonly)

Returns Full display name.

Returns:

  • (String, nil)

    Full display name



38
# File 'lib/durable_huggingface_hub/types/user.rb', line 38

attribute :fullname, Types::OptionalString.default(nil)

#idString? (readonly)

Returns User ID.

Returns:

  • (String, nil)

    User ID



30
# File 'lib/durable_huggingface_hub/types/user.rb', line 30

attribute :id, Types::OptionalString.default(nil)

#is_proBoolean? (readonly)

Returns Whether user has Pro subscription.

Returns:

  • (Boolean, nil)

    Whether user has Pro subscription



50
# File 'lib/durable_huggingface_hub/types/user.rb', line 50

attribute :is_pro, Types::OptionalBool.default(nil)

#nameString (readonly)

Returns Username.

Returns:

  • (String)

    Username



34
# File 'lib/durable_huggingface_hub/types/user.rb', line 34

attribute :name, Types::String

#orgsArray<Hash>? (readonly)

Returns Organizations the user belongs to.

Returns:

  • (Array<Hash>, nil)

    Organizations the user belongs to



54
# File 'lib/durable_huggingface_hub/types/user.rb', line 54

attribute :orgs, Types::Array.of(Types::Hash).optional.default(nil)

#typeString? (readonly)

Returns User type (e.g., “user”).

Returns:

  • (String, nil)

    User type (e.g., “user”)



26
# File 'lib/durable_huggingface_hub/types/user.rb', line 26

attribute :type, Types::OptionalString.default(nil)

Class Method Details

.from_hash(data) ⇒ Object

Transform isPro from API to is_pro



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/durable_huggingface_hub/types/user.rb', line 61

def self.from_hash(data)
  transformed = data.dup
  if transformed.key?("isPro") && !transformed.key?("is_pro")
    transformed["is_pro"] = transformed.delete("isPro")
  elsif transformed.key?(:isPro) && !transformed.key?(:is_pro)
    transformed[:is_pro] = transformed.delete(:isPro)
  end

  if transformed.key?("avatarUrl") && !transformed.key?("avatar_url")
    transformed["avatar_url"] = transformed.delete("avatarUrl")
  elsif transformed.key?(:avatarUrl) && !transformed.key?(:avatar_url)
    transformed[:avatar_url] = transformed.delete(:avatarUrl)
  end

  # Filter out unknown keys to avoid dry-struct errors
  known_keys = [:type, :name, :fullname, :email, :avatar_url, :is_pro, :orgs,
                "type", "name", "fullname", "email", "avatar_url", "is_pro", "orgs"]
  transformed = transformed.select { |k, _| known_keys.include?(k) }

  new(transformed)
end

Instance Method Details

#display_nameString

Returns the display name (fullname if available, otherwise username).

Returns:

  • (String)

    Display name



93
94
95
# File 'lib/durable_huggingface_hub/types/user.rb', line 93

def display_name
  fullname || name
end

#inspectString

Returns a detailed inspection string.

Returns:

  • (String)

    Inspection string



107
108
109
# File 'lib/durable_huggingface_hub/types/user.rb', line 107

def inspect
  "#<#{self.class.name} name=#{name.inspect} fullname=#{fullname.inspect} pro=#{pro?}>"
end

#pro?Boolean

Checks if the user has a Pro subscription.

Returns:

  • (Boolean)

    True if Pro user



86
87
88
# File 'lib/durable_huggingface_hub/types/user.rb', line 86

def pro?
  is_pro == true
end

#to_sString

Returns a short description of the user.

Returns:

  • (String)

    Description string



100
101
102
# File 'lib/durable_huggingface_hub/types/user.rb', line 100

def to_s
  display_name
end