Class: SpotifyWebApi::ChapterBase

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

Overview

ChapterBase Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(audio_preview_url = nil, chapter_number = nil, description = nil, html_description = nil, duration_ms = nil, explicit = nil, external_urls = nil, href = nil, id = nil, images = nil, is_playable = nil, languages = nil, name = nil, release_date = nil, release_date_precision = nil, type = nil, uri = nil, available_markets = SKIP, resume_point = SKIP, restrictions = SKIP) ⇒ ChapterBase

Returns a new instance of ChapterBase.



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/spotify_web_api/models/chapter_base.rb', line 144

def initialize(audio_preview_url = nil, chapter_number = nil,
               description = nil, html_description = nil, duration_ms = nil,
               explicit = nil, external_urls = nil, href = nil, id = nil,
               images = nil, is_playable = nil, languages = nil, name = nil,
               release_date = nil, release_date_precision = nil, type = nil,
               uri = nil, available_markets = SKIP, resume_point = SKIP,
               restrictions = SKIP)
  @audio_preview_url = audio_preview_url
  @available_markets = available_markets unless available_markets == SKIP
  @chapter_number = chapter_number
  @description = description
  @html_description = html_description
  @duration_ms = duration_ms
  @explicit = explicit
  @external_urls = external_urls
  @href = href
  @id = id
  @images = images
  @is_playable = is_playable
  @languages = languages
  @name = name
  @release_date = release_date
  @release_date_precision = release_date_precision
  @resume_point = resume_point unless resume_point == SKIP
  @type = type
  @uri = uri
  @restrictions = restrictions unless restrictions == SKIP
end

Instance Attribute Details

#audio_preview_urlString

A URL to a 30 second preview (MP3 format) of the chapter. ‘null` if not available.

Returns:

  • (String)


15
16
17
# File 'lib/spotify_web_api/models/chapter_base.rb', line 15

def audio_preview_url
  @audio_preview_url
end

#available_marketsArray[String]

A list of the countries in which the chapter can be played, identified by their [ISO 3166-1 alpha-2](en.wikipedia.org/wiki/ISO_3166-1_alpha-2) code.

Returns:

  • (Array[String])


21
22
23
# File 'lib/spotify_web_api/models/chapter_base.rb', line 21

def available_markets
  @available_markets
end

#chapter_numberInteger

The number of the chapter

Returns:

  • (Integer)


25
26
27
# File 'lib/spotify_web_api/models/chapter_base.rb', line 25

def chapter_number
  @chapter_number
end

#descriptionString

A description of the chapter. HTML tags are stripped away from this field, use ‘html_description` field in case HTML tags are needed.

Returns:

  • (String)


30
31
32
# File 'lib/spotify_web_api/models/chapter_base.rb', line 30

def description
  @description
end

#duration_msInteger

The chapter length in milliseconds.

Returns:

  • (Integer)


38
39
40
# File 'lib/spotify_web_api/models/chapter_base.rb', line 38

def duration_ms
  @duration_ms
end

#explicitTrueClass | FalseClass

Whether or not the chapter has explicit content (true = yes it does; false

no it does not OR unknown).

Returns:

  • (TrueClass | FalseClass)


43
44
45
# File 'lib/spotify_web_api/models/chapter_base.rb', line 43

def explicit
  @explicit
end

#external_urlsExternalUrlObject

External URLs for this chapter.

Returns:



47
48
49
# File 'lib/spotify_web_api/models/chapter_base.rb', line 47

def external_urls
  @external_urls
end

#hrefString

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

Returns:

  • (String)


51
52
53
# File 'lib/spotify_web_api/models/chapter_base.rb', line 51

def href
  @href
end

#html_descriptionString

A description of the chapter. This field may contain HTML tags.

Returns:

  • (String)


34
35
36
# File 'lib/spotify_web_api/models/chapter_base.rb', line 34

def html_description
  @html_description
end

#idString

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

Returns:

  • (String)


56
57
58
# File 'lib/spotify_web_api/models/chapter_base.rb', line 56

def id
  @id
end

#imagesArray[ImageObject]

The cover art for the chapter in various sizes, widest first.

Returns:



60
61
62
# File 'lib/spotify_web_api/models/chapter_base.rb', line 60

def images
  @images
end

#is_playableTrueClass | FalseClass

True if the chapter is playable in the given market. Otherwise false.

Returns:

  • (TrueClass | FalseClass)


64
65
66
# File 'lib/spotify_web_api/models/chapter_base.rb', line 64

def is_playable
  @is_playable
end

#languagesArray[String]

A list of the languages used in the chapter, identified by their [ISO 639-1](en.wikipedia.org/wiki/ISO_639) code.

Returns:

  • (Array[String])


69
70
71
# File 'lib/spotify_web_api/models/chapter_base.rb', line 69

def languages
  @languages
end

#nameString

The name of the chapter.

Returns:

  • (String)


73
74
75
# File 'lib/spotify_web_api/models/chapter_base.rb', line 73

def name
  @name
end

#release_dateString

The date the chapter was first released, for example ‘“1981-12-15”`. Depending on the precision, it might be shown as `“1981”` or `“1981-12”`.

Returns:

  • (String)


78
79
80
# File 'lib/spotify_web_api/models/chapter_base.rb', line 78

def release_date
  @release_date
end

#release_date_precisionReleaseDatePrecisionEnum

The precision with which ‘release_date` value is known.



82
83
84
# File 'lib/spotify_web_api/models/chapter_base.rb', line 82

def release_date_precision
  @release_date_precision
end

#restrictionsChapterRestrictionObject

Included in the response when a content restriction is applied.



100
101
102
# File 'lib/spotify_web_api/models/chapter_base.rb', line 100

def restrictions
  @restrictions
end

#resume_pointResumePointObject

The user’s most recent position in the chapter. Set if the supplied access token is a user token and has the scope ‘user-read-playback-position’.

Returns:



87
88
89
# File 'lib/spotify_web_api/models/chapter_base.rb', line 87

def resume_point
  @resume_point
end

#typeType8Enum

The object type.

Returns:



91
92
93
# File 'lib/spotify_web_api/models/chapter_base.rb', line 91

def type
  @type
end

#uriString

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

Returns:

  • (String)


96
97
98
# File 'lib/spotify_web_api/models/chapter_base.rb', line 96

def uri
  @uri
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/spotify_web_api/models/chapter_base.rb', line 174

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  audio_preview_url =
    hash.key?('audio_preview_url') ? hash['audio_preview_url'] : nil
  chapter_number =
    hash.key?('chapter_number') ? hash['chapter_number'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  html_description =
    hash.key?('html_description') ? hash['html_description'] : nil
  duration_ms = hash.key?('duration_ms') ? hash['duration_ms'] : nil
  explicit = hash.key?('explicit') ? hash['explicit'] : nil
  external_urls = ExternalUrlObject.from_hash(hash['external_urls']) if hash['external_urls']
  href = hash.key?('href') ? hash['href'] : nil
  id = hash.key?('id') ? hash['id'] : nil
  # Parameter is an array, so we need to iterate through it
  images = nil
  unless hash['images'].nil?
    images = []
    hash['images'].each do |structure|
      images << (ImageObject.from_hash(structure) if structure)
    end
  end

  images = nil unless hash.key?('images')
  is_playable = hash.key?('is_playable') ? hash['is_playable'] : nil
  languages = hash.key?('languages') ? hash['languages'] : nil
  name = hash.key?('name') ? hash['name'] : nil
  release_date = hash.key?('release_date') ? hash['release_date'] : nil
  release_date_precision =
    hash.key?('release_date_precision') ? hash['release_date_precision'] : nil
  type = hash.key?('type') ? hash['type'] : nil
  uri = hash.key?('uri') ? hash['uri'] : nil
  available_markets =
    hash.key?('available_markets') ? hash['available_markets'] : SKIP
  resume_point = ResumePointObject.from_hash(hash['resume_point']) if hash['resume_point']
  restrictions = ChapterRestrictionObject.from_hash(hash['restrictions']) if
    hash['restrictions']

  # Create object from extracted values.
  ChapterBase.new(audio_preview_url,
                  chapter_number,
                  description,
                  html_description,
                  duration_ms,
                  explicit,
                  external_urls,
                  href,
                  id,
                  images,
                  is_playable,
                  languages,
                  name,
                  release_date,
                  release_date_precision,
                  type,
                  uri,
                  available_markets,
                  resume_point,
                  restrictions)
end

.namesObject

A mapping from model property names to API property names.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/spotify_web_api/models/chapter_base.rb', line 103

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['audio_preview_url'] = 'audio_preview_url'
  @_hash['available_markets'] = 'available_markets'
  @_hash['chapter_number'] = 'chapter_number'
  @_hash['description'] = 'description'
  @_hash['html_description'] = 'html_description'
  @_hash['duration_ms'] = 'duration_ms'
  @_hash['explicit'] = 'explicit'
  @_hash['external_urls'] = 'external_urls'
  @_hash['href'] = 'href'
  @_hash['id'] = 'id'
  @_hash['images'] = 'images'
  @_hash['is_playable'] = 'is_playable'
  @_hash['languages'] = 'languages'
  @_hash['name'] = 'name'
  @_hash['release_date'] = 'release_date'
  @_hash['release_date_precision'] = 'release_date_precision'
  @_hash['resume_point'] = 'resume_point'
  @_hash['type'] = 'type'
  @_hash['uri'] = 'uri'
  @_hash['restrictions'] = 'restrictions'
  @_hash
end

.nullablesObject

An array for nullable fields



138
139
140
141
142
# File 'lib/spotify_web_api/models/chapter_base.rb', line 138

def self.nullables
  %w[
    audio_preview_url
  ]
end

.optionalsObject

An array for optional fields



129
130
131
132
133
134
135
# File 'lib/spotify_web_api/models/chapter_base.rb', line 129

def self.optionals
  %w[
    available_markets
    resume_point
    restrictions
  ]
end