Class: SpotifyWeb::Restriction

Inherits:
Resource
  • Object
show all
Defined in:
lib/spotify_web/restriction.rb

Overview

Represents a country-based restriction on Spotify data

Constant Summary collapse

CATALOGUE_IDS =
{
  Schema::Metadata::Restriction::Catalogue::AD => [:free],
  Schema::Metadata::Restriction::Catalogue::SUBSCRIPTION => [:premium, :unlimited]
}

Constants inherited from Resource

SpotifyWeb::Resource::BASE62_CHARS

Instance Attribute Summary collapse

Attributes inherited from Resource

#gid, #id, #uri, #uri_id

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, #attributes=, from_search_result, #hash, #initialize, #load, #load_metadata, #loaded?, #metadata=, #metadata_uri, #pretty_print, #pretty_print_instance_variables

Methods included from Assertions

#assert_valid_keys, #assert_valid_values

Constructor Details

This class inherits a constructor from SpotifyWeb::Resource

Instance Attribute Details

#cataloguesArray<Symbol> (readonly)

The catalogues this song is a member of. This determines which accounts can play which songs

Returns:

  • (Array<Symbol>)

26
27
28
# File 'lib/spotify_web/restriction.rb', line 26

attribute :catalogues, :catalogue do |catalogues|
  catalogues.map {|id| CATALOGUE_IDS[id]}.compact.flatten
end

#countries_allowedString (readonly)

The countries allowed to access the data

Returns:

  • (String)

13
14
15
# File 'lib/spotify_web/restriction.rb', line 13

attribute :countries_allowed do |countries|
  countries.scan(/.{2}/)
end

#countries_forbiddenString (readonly)

The countries forbidden to access the data

Returns:

  • (String)

19
20
21
# File 'lib/spotify_web/restriction.rb', line 19

attribute :countries_forbidden do |countries|
  countries.scan(/.{2}/)
end

Instance Method Details

#permitted?(type = :all) ⇒ Boolean

Whether the user is permitted to access data based on this restriction

Parameters:

  • type (String) (defaults to: :all)
    :all

    The permission to check

Returns:

  • (Boolean)

34
35
36
37
38
39
40
41
42
# File 'lib/spotify_web/restriction.rb', line 34

def permitted?(type = :all)
  assert_valid_values(type, :all, :country, :catalogue)

  if type == :all
    permissions.values.all?
  else
    permissions[type]
  end
end