Class: Turntabler::Preferences

Inherits:
Resource
  • Object
show all
Defined in:
lib/turntabler/preferences.rb

Overview

Represents the site preferences for the authorized user

Instance Attribute Summary collapse

Attributes inherited from Resource

#id

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, #attributes=, #hash, #initialize, #loaded?, #pretty_print, #pretty_print_instance_variables

Methods included from Assertions

#assert_valid_keys, #assert_valid_values

Methods included from DigestHelpers

#digest

Constructor Details

This class inherits a constructor from Turntabler::Resource

Instance Attribute Details

#facebook_awesomeBoolean (readonly)

Publishes to facebook songs voted up in public rooms

Returns:

  • (Boolean)


24
# File 'lib/turntabler/preferences.rb', line 24

attribute :facebook_awesome

#facebook_djBoolean (readonly)

Publishes to facebook when DJing in a public room

Returns:

  • (Boolean)


32
# File 'lib/turntabler/preferences.rb', line 32

attribute :facebook_dj

#facebook_joinBoolean (readonly)

Publishes to facebook when a public room is joined

Returns:

  • (Boolean)


28
# File 'lib/turntabler/preferences.rb', line 28

attribute :facebook_join

#notify_djBoolean (readonly)

Send e-mails if a fan starts DJing

Returns:

  • (Boolean)


8
# File 'lib/turntabler/preferences.rb', line 8

attribute :notify_dj

#notify_fanBoolean (readonly)

Send e-mails when someone becomes a fan

Returns:

  • (Boolean)


12
# File 'lib/turntabler/preferences.rb', line 12

attribute :notify_fan

#notify_newsBoolean (readonly)

Sends infrequent e-mails about news

Returns:

  • (Boolean)


16
# File 'lib/turntabler/preferences.rb', line 16

attribute :notify_news

#notify_randomBoolean (readonly)

Sends e-mails at random times with a different subsection of the digits of pi

Returns:

  • (Boolean)


20
# File 'lib/turntabler/preferences.rb', line 20

attribute :notify_random

Instance Method Details

#loadtrue

Loads the user’s current Turntable preferences.

Examples:

preferences.load        # => true
preferences.notify_dj   # => false

Returns:

  • (true)

Raises:



41
42
43
44
45
46
47
48
# File 'lib/turntabler/preferences.rb', line 41

def load
  data = api('user.get_prefs')
  self.attributes = data['result'].inject({}) do |result, (preference, value, *)|
    result[preference] = value
    result
  end
  super
end

#update(attributes = {}) ⇒ true

Updates the user’s preferences.

Examples:

preferences.update(:notify_dj => false)   # => true

Parameters:

  • attributes (Hash) (defaults to: {})

    The attributes to update

Options Hash (attributes):

  • :notify_dj (Boolean)
  • :notify_fan (Boolean)
  • :notify_news (Boolean)
  • :notify_random (Boolean)
  • :facbeook_awesome (Boolean)
  • :facebook_join (Boolean)
  • :facebook_dj (Boolean)

Returns:

  • (true)

Raises:



64
65
66
67
68
69
# File 'lib/turntabler/preferences.rb', line 64

def update(attributes = {})
  assert_valid_values(attributes, :notify_dj, :notify_fan, :notify_news, :notify_random, :facebook_awesome, :facebook_join, :facebook_dj)
  api('user.edit_prefs', attributes)
  self.attributes = attributes
  true
end