Class: RSpotify::Show

Inherits:
Base
  • Object
show all
Defined in:
lib/rspotify/show.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#external_urls, #href, #id, #type, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#complete!, #embed, #method_missing, #respond_to?

Constructor Details

#initialize(options = {}) ⇒ Show

Returns a new instance of Show.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rspotify/show.rb', line 47

def initialize(options = {})
  @available_markets = options['available_markets']
  @copyrights        = options['copyrights']
  @description       = options['description']
  @explicit          = options['explicit']
  @html_description  = options['html_description']
  @images            = options['images']
  @is_externally_hosted = options['is_externally_hosted']
  @languages         = options['languages']
  @media_type        = options['media_type']
  @name              = options['name']
  @publisher         = options['publisher']

  episodes = options['episodes']['items'] if options['episodes']

  @episodes_cache = if episodes
    episodes.map { |e| Episode.new e }
  end

  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RSpotify::Base

Instance Attribute Details

#available_marketsArray<String>

A list of the countries in which the show can be played, identified by their ISO 3166-1 alpha-2 code.

Returns:

  • (Array<String>)

    the current value of available_markets



14
15
16
# File 'lib/rspotify/show.rb', line 14

def available_markets
  @available_markets
end

#copyrightsArray<Hash>

The copyright statements of the show.

Returns:

  • (Array<Hash>)

    the current value of copyrights



14
15
16
# File 'lib/rspotify/show.rb', line 14

def copyrights
  @copyrights
end

#descriptionString

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

Returns:

  • (String)

    the current value of description



14
15
16
# File 'lib/rspotify/show.rb', line 14

def description
  @description
end

#explicitBoolean

Whether or not the show has explicit content (true = yes it does; false = no it does not OR unknown).

Returns:

  • (Boolean)

    the current value of explicit



14
15
16
# File 'lib/rspotify/show.rb', line 14

def explicit
  @explicit
end

#html_descriptionString

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

Returns:

  • (String)

    the current value of html_description



14
15
16
# File 'lib/rspotify/show.rb', line 14

def html_description
  @html_description
end

#imagesArray<Hash>

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

Returns:

  • (Array<Hash>)

    the current value of images



14
15
16
# File 'lib/rspotify/show.rb', line 14

def images
  @images
end

#is_externally_hostedBoolean

True if all of the show’s episodes are hosted outside of Spotify’s CDN. This field might be null in some cases.

Returns:

  • (Boolean)

    the current value of is_externally_hosted



14
15
16
# File 'lib/rspotify/show.rb', line 14

def is_externally_hosted
  @is_externally_hosted
end

#languagesArray<String>

A list of the languages used in the show, identified by their ISO 639 code.

Returns:

  • (Array<String>)

    the current value of languages



14
15
16
# File 'lib/rspotify/show.rb', line 14

def languages
  @languages
end

#media_typeString

The media type of the show.

Returns:

  • (String)

    the current value of media_type



14
15
16
# File 'lib/rspotify/show.rb', line 14

def media_type
  @media_type
end

#nameString

The name of the show.

Returns:

  • (String)

    the current value of name



14
15
16
# File 'lib/rspotify/show.rb', line 14

def name
  @name
end

#publisherString

The publisher of the show.

Returns:

  • (String)

    the current value of publisher



14
15
16
# File 'lib/rspotify/show.rb', line 14

def publisher
  @publisher
end

Class Method Details

.find(ids, market: nil) ⇒ Show+

Returns Show object(s) with id(s) provided

Examples:

show = RSpotify::Show.find('3Z6JdCS2d0eFEpXHKI6WqH')
show.class #=> RSpotify::Show
show.name  #=> "Consider This from NPR"

Parameters:

Returns:



26
27
28
# File 'lib/rspotify/show.rb', line 26

def self.find(ids, market: nil )
  super(ids, 'show', market: market)
end

.search(query, limit: 20, offset: 0, market: nil) ⇒ Array<Show>

Returns array of Show objects matching the query. It’s also possible to find the total number of search results for the query

Examples:

shows = RSpotify::Show.search('NPR')
shows = RSpotify::Show.search('NPR', market: 'US', limit: 10)

RSpotify::Show.search('NPR').total #=> 357

Parameters:

  • query (String)

    The search query’s keywords. See the q description in here for details.

  • limit (Integer) (defaults to: 20)

    Maximum number of shows to return. Maximum: 50. Default: 20.

  • offset (Integer) (defaults to: 0)

    The index of the first show to return. Use with limit to get the next set of shows. Default: 0.

  • market (String) (defaults to: nil)

Returns:



43
44
45
# File 'lib/rspotify/show.rb', line 43

def self.search(query, limit: 20, offset: 0, market: nil)
  super(query, 'show', limit: limit, offset: offset, market: market)
end

Instance Method Details

#episodes(limit: 20, offset: 0, market: nil) ⇒ Array<Episode>

Returns array of episodes from the show

Examples:

show = RSpotify::Show.find('3Z6JdCS2d0eFEpXHKI6WqH')
show.episodes.first.name #=> "Colin Powell's Complicated Legacy"

Parameters:

  • limit (Integer) (defaults to: 20)

    Maximum number of episodes to return. Maximum: 50. Default: 20.

  • offset (Integer) (defaults to: 0)

    The index of the first track to return. Use with limit to get the next set of objects. Default: 0.

  • market (String) (defaults to: nil)

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/rspotify/show.rb', line 79

def episodes(limit: 20, offset: 0, market: nil )
  last_episode = offset + limit - 1
  if @episodes_cache && last_episode < 20 && !RSpotify.raw_response
    return @episodes_cache[offset..last_episode]
  end

  url = "#{@href}/episodes?limit=#{limit}&offset=#{offset}"
  url << "&market=#{market}" if market

  response = RSpotify.get url

  json = RSpotify.raw_response ? JSON.parse(response) : response
  episodes = json['items']

  episodes.map! { |e| Episode.new e }
  @episodes_cache = episodes if limit == 20 && offset == 0
  return response if RSpotify.raw_response
  episodes
end