Class: SpotifyWeb::Restriction
- 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
-
#countries_allowed ⇒ String
readonly
The countries allowed to access the data.
-
#countries_forbidden ⇒ String
readonly
The countries forbidden to access the data.
Attributes inherited from Resource
Instance Method Summary collapse
-
#permitted? ⇒ Boolean
Whether the user is permitted to access data based on this restriction.
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_allowed ⇒ String (readonly)
The countries allowed to access the data
8 9 10 |
# File 'lib/spotify_web/restriction.rb', line 8 attribute :countries_allowed do |countries| countries.scan(/.{2}/) end |
#countries_forbidden ⇒ String (readonly)
The countries forbidden to access the data
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
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 |