Class: Turntabler::RoomDirectory
- Inherits:
-
Object
- Object
- Turntabler::RoomDirectory
- Includes:
- Assertions
- Defined in:
- lib/turntabler/room_directory.rb
Overview
Provides a set of helper methods for interacting with Turntable’s directory of rooms.
Instance Method Summary collapse
-
#all(options = {}) ⇒ Array<Turntabler::Room>
Gets the list of available rooms.
-
#create(name, attributes = {}) ⇒ Turntabler::Room
Creates a new room with the given name and configuration.
-
#find(query, options = {}) ⇒ Array<Turntabler::Room>
Finds rooms that match the given query string.
-
#initialize(client) ⇒ RoomDirectory
constructor
private
A new instance of RoomDirectory.
-
#with_friends ⇒ Array<Turntabler::Room>
Gets the rooms where the current user’s friends are currently listening.
Methods included from Assertions
#assert_valid_keys, #assert_valid_values
Constructor Details
#initialize(client) ⇒ RoomDirectory
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of RoomDirectory.
10 11 12 |
# File 'lib/turntabler/room_directory.rb', line 10 def initialize(client) @client = client end |
Instance Method Details
#all(options = {}) ⇒ Array<Turntabler::Room>
Gets the list of available rooms.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/turntabler/room_directory.rb', line 61 def all( = {}) assert_valid_keys(, :limit, :skip, :favorites, :available_djs, :genre, :minimum_listeners, :sort) assert_valid_values([:genre], :rock, :electronic, :indie, :hiphop, :pop, :dubstep) if [:genre] assert_valid_values([:sort], :created, :listeners, :random) if [:sort] = { :limit => 20, :skip => 0, :favorites => false, :available_djs => false, :minimum_listeners => 1, :sort => :listeners }.merge() constraints = [] constraints << :favorites if [:favorites] constraints << :available_djs if [:available_djs] constraints << :"has_people=#{options[:minimum_listeners]}" if [:genre] constraints << :"genre=#{options[:genre]}" [:sort] = "#{options[:sort]},genre:#{options[:genre]}" end data = api('room.directory_rooms', :section_aware => true, :limit => [:limit], :skip => [:skip], :constraints => constraints * ',', :sort => [:sort] ) data['rooms'].map {|attrs| Room.new(client, attrs)} end |
#create(name, attributes = {}) ⇒ Turntabler::Room
This will automatically enter the room when it is created
Creates a new room with the given name and configuration. This should only be used if the room doesn’t already exist.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/turntabler/room_directory.rb', line 28 def create(name, attributes = {}) assert_valid_keys(attributes, :privacy, :dj_capacity, :dj_minimum_points) attributes = {:privacy => 'public', :dj_capacity => 5, :dj_minimum_points => 0}.merge(attributes) # Convert attribute names over to their Turntable equivalent {:dj_capacity => :max_djs, :dj_minimum_points => :djthreshold}.each do |from, to| attributes[to] = attributes.delete(from) if attributes[from] end data = api('room.create', attributes.merge(:room_name => name)) room = Room.new(client, attributes.merge(:_id => data['roomid'], :shortcut => data['shortcut'], :name => name)) room.enter room end |
#find(query, options = {}) ⇒ Array<Turntabler::Room>
Finds rooms that match the given query string.
116 117 118 119 120 121 122 |
# File 'lib/turntabler/room_directory.rb', line 116 def find(query, = {}) assert_valid_keys(, :limit, :skip) = {:limit => 20, :skip => 0}.merge() data = api('room.search', :query => query, :skip => [:skip]) data['rooms'].map {|(attrs, *)| Room.new(client, attrs)} end |
#with_friends ⇒ Array<Turntabler::Room>
Gets the rooms where the current user’s friends are currently listening.
99 100 101 102 103 104 |
# File 'lib/turntabler/room_directory.rb', line 99 def with_friends data = api('room.directory_graph') data['rooms'].map do |(attrs, friends)| Room.new(client, attrs.merge(:friends => friends)) end end |