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

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=, #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

#countries_allowedString (readonly)

The countries allowed to access the data

Returns:

  • (String)


8
9
10
# File 'lib/spotify_web/restriction.rb', line 8

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

#countries_forbiddenString (readonly)

The countries forbidden to access the data

Returns:

  • (String)


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

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

Instance Method Details

#permitted?Boolean

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

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/spotify_web/restriction.rb', line 20

def permitted?
  country = client.user.settings['country']

  if countries_allowed
    countries_allowed.include?(country)
  elsif countries_forbidden
    !countries_forbidden.include?(country)
  else
    true
  end
end