Class: SpotifyWebApi::ContextObject

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/spotify_web_api/models/context_object.rb

Overview

ContextObject Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(type = SKIP, href = SKIP, external_urls = SKIP, uri = SKIP) ⇒ ContextObject

Returns a new instance of ContextObject.



54
55
56
57
58
59
# File 'lib/spotify_web_api/models/context_object.rb', line 54

def initialize(type = SKIP, href = SKIP, external_urls = SKIP, uri = SKIP)
  @type = type unless type == SKIP
  @href = href unless href == SKIP
  @external_urls = external_urls unless external_urls == SKIP
  @uri = uri unless uri == SKIP
end

Instance Attribute Details

#external_urlsExternalUrlObject

External URLs for this context.

Returns:



22
23
24
# File 'lib/spotify_web_api/models/context_object.rb', line 22

def external_urls
  @external_urls
end

#hrefString

A link to the Web API endpoint providing full details of the track.

Returns:

  • (String)


18
19
20
# File 'lib/spotify_web_api/models/context_object.rb', line 18

def href
  @href
end

#typeString

The object type, e.g. “artist”, “playlist”, “album”, “show”.

Returns:

  • (String)


14
15
16
# File 'lib/spotify_web_api/models/context_object.rb', line 14

def type
  @type
end

#uriString

The [Spotify URI](/documentation/web-api/concepts/spotify-uris-ids) for the context.

Returns:

  • (String)


27
28
29
# File 'lib/spotify_web_api/models/context_object.rb', line 27

def uri
  @uri
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/spotify_web_api/models/context_object.rb', line 62

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  type = hash.key?('type') ? hash['type'] : SKIP
  href = hash.key?('href') ? hash['href'] : SKIP
  external_urls = ExternalUrlObject.from_hash(hash['external_urls']) if hash['external_urls']
  uri = hash.key?('uri') ? hash['uri'] : SKIP

  # Create object from extracted values.
  ContextObject.new(type,
                    href,
                    external_urls,
                    uri)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
37
# File 'lib/spotify_web_api/models/context_object.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['type'] = 'type'
  @_hash['href'] = 'href'
  @_hash['external_urls'] = 'external_urls'
  @_hash['uri'] = 'uri'
  @_hash
end

.nullablesObject

An array for nullable fields



50
51
52
# File 'lib/spotify_web_api/models/context_object.rb', line 50

def self.nullables
  []
end

.optionalsObject

An array for optional fields



40
41
42
43
44
45
46
47
# File 'lib/spotify_web_api/models/context_object.rb', line 40

def self.optionals
  %w[
    type
    href
    external_urls
    uri
  ]
end