Class: Drum::UserSpotify

Inherits:
Struct
  • Object
show all
Defined in:
lib/drum/model/user.rb

Overview

Spotify-specific metadata about the user.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idString

Returns The id of the artist on Spotify.

Returns:

  • (String)

    The id of the artist on Spotify



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/drum/model/user.rb', line 46

UserSpotify = Struct.new(
  :id,
  :image_url,
  keyword_init: true
) do
  # Parses Spotify metadata from a Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [UserSpotify] The parsed user
  def self.deserialize(h)
    UserSpotify.new(
      id: h['id'],
      image_url: h['image_url']
    )
  end

  # Serializes the metadata to a Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'id' => self.id,
      'image_url' => self.image_url
    }.compact
  end
end

#image_urloptional, String

Returns The profile image of the user.

Returns:

  • (optional, String)

    The profile image of the user



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/drum/model/user.rb', line 46

UserSpotify = Struct.new(
  :id,
  :image_url,
  keyword_init: true
) do
  # Parses Spotify metadata from a Hash that uses string keys.
  #
  # @param [Hash<String, Object>] h The Hash to be parsed
  # @return [UserSpotify] The parsed user
  def self.deserialize(h)
    UserSpotify.new(
      id: h['id'],
      image_url: h['image_url']
    )
  end

  # Serializes the metadata to a Hash that uses string keys.
  #
  # @return [Hash<String, Object>] The serialized representation
  def serialize
    {
      'id' => self.id,
      'image_url' => self.image_url
    }.compact
  end
end

Class Method Details

.deserialize(h) ⇒ UserSpotify

Parses Spotify metadata from a Hash that uses string keys.

Parameters:

Returns:



55
56
57
58
59
60
# File 'lib/drum/model/user.rb', line 55

def self.deserialize(h)
  UserSpotify.new(
    id: h['id'],
    image_url: h['image_url']
  )
end

Instance Method Details

#serializeHash<String, Object>

Serializes the metadata to a Hash that uses string keys.

Returns:



65
66
67
68
69
70
# File 'lib/drum/model/user.rb', line 65

def serialize
  {
    'id' => self.id,
    'image_url' => self.image_url
  }.compact
end