turntabler 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,8 +3,7 @@ require 'em-synchrony/em-http'
3
3
  require 'turntabler/resource'
4
4
 
5
5
  module Turntabler
6
- # Represents an individual room in Turntable. The room must be explicitly
7
- # entered before being able to DJ.
6
+ # Represents an individual room in Turntable
8
7
  class Room < Resource
9
8
  # Allow the id to be set via the "roomid" attribute
10
9
  # @return [String]
@@ -55,8 +54,8 @@ module Turntabler
55
54
 
56
55
  # The host to connect to for joining this room
57
56
  # @return [String]
58
- attribute :host, :chatserver do |value|
59
- value[0]
57
+ attribute :host, :chatserver do |(host, *)|
58
+ host
60
59
  end
61
60
 
62
61
  # Whether this room is being featured by Turntable
@@ -86,7 +85,7 @@ module Turntabler
86
85
  attribute :moderators, :moderator_id do |ids|
87
86
  Set.new(ids.map {|id| build_user(:_id => id)})
88
87
  end
89
-
88
+
90
89
  # The current user's friends who are also known to be in the room. These
91
90
  # friends must be connected through a separate network like Facebook or Twitter.
92
91
  #
@@ -127,10 +126,11 @@ module Turntabler
127
126
  # @return [String]
128
127
  # @raise [Turntabler::Error] if the host lookup fails
129
128
  def host
130
- @host ||= begin
129
+ begin
131
130
  response = EventMachine::HttpRequest.new("http://turntable.fm/api/room.which_chatserver?roomid=#{id}").get.response
132
- JSON.parse(response)[1]['chatserver'][0]
133
- end
131
+ self.attributes = JSON.parse(response)[1]
132
+ end unless @host
133
+ @host
134
134
  end
135
135
 
136
136
  # Gets the configured chat url
@@ -147,6 +147,7 @@ module Turntabler
147
147
  # @param [Hash] options The configuration options
148
148
  # @option options [Boolean] :song_log (false) Whether to include the song log
149
149
  # @return [true]
150
+ # @raise [ArgumentError] if an invalid option is specified
150
151
  # @raise [Turntabler::Error] if the command fails
151
152
  # @example
152
153
  # room.load # => true
@@ -168,11 +169,12 @@ module Turntabler
168
169
  end
169
170
  end
170
171
 
171
- # Sets the current attributes for this room, ensures that the full list of
172
+ # Sets the current attributes for this room, ensuring that the full list of
172
173
  # listeners gets set first so that we can use those built users to then fill
173
174
  # out the collection of djs, moderators, etc.
174
175
  #
175
176
  # @api private
177
+ # @param [Hash] attrs The attributes to set
176
178
  def attributes=(attrs)
177
179
  if attrs
178
180
  super('users' => attrs.delete('users')) if attrs['users']
@@ -189,6 +191,7 @@ module Turntabler
189
191
  # @param [Hash] attributes The attributes to update
190
192
  # @option attributes [String] :description
191
193
  # @return [true]
194
+ # @raise [ArgumentError] if an invalid attribute is specified
192
195
  # @raise [Turntabler::Error] if the command fails
193
196
  # @example
194
197
  # room.update(:description => '...') # => true
@@ -202,6 +205,7 @@ module Turntabler
202
205
 
203
206
  # Enters the current room.
204
207
  #
208
+ # @note This will leave any room the user is already currently in (unless the same room is being entered)
205
209
  # @return [true]
206
210
  # @raise [Turntabler::Error] if the command fails
207
211
  # @example
@@ -210,7 +214,7 @@ module Turntabler
210
214
  if client.room != self
211
215
  # Leave the old room
212
216
  client.room.leave if client.room
213
-
217
+
214
218
  # Connect and register with this room
215
219
  client.connect(url)
216
220
  begin
@@ -222,11 +226,11 @@ module Turntabler
222
226
  raise
223
227
  end
224
228
  end
225
-
229
+
226
230
  true
227
231
  end
228
232
 
229
- # Leaves from the current room.
233
+ # Leaves from the room.
230
234
  #
231
235
  # @return [true]
232
236
  # @raise [Turntabler::Error] if the command fails
@@ -270,6 +274,8 @@ module Turntabler
270
274
  # get created.
271
275
  #
272
276
  # @api private
277
+ # @param [Hash] attrs The attributes representing the user
278
+ # @return [Turntabler::User]
273
279
  def build_user(attrs)
274
280
  user = User.new(client, attrs)
275
281
  user = if client.user == user
@@ -365,7 +371,7 @@ module Turntabler
365
371
  api('room.report', :roomid => id, :section => section, :reason => reason)
366
372
  true
367
373
  end
368
-
374
+
369
375
  private
370
376
  # Sets the sticker placements for each dj
371
377
  def sticker_placements=(user_placements)
@@ -46,12 +46,12 @@ module Turntabler
46
46
  # @option options [Fixnum] :limit (20) The total number of rooms to list
47
47
  # @option options [Fixnum] :skip (0) The number of rooms to skip when loading the list
48
48
  # @option options [Fixnum] :favorites (false) Whether to only include rooms marked as favorites
49
- # @option options [Fixnum] :available_djs (false) Whether to only include rooms that have dj spots available
50
- # @option options [Fixnum] :genre The genre of music being played in the room, . Possible values are +:rock+, +:electronica+, +:indie+, +:hiphop+, +:pop+, and +:dubstep+.
49
+ # @option options [Boolean] :available_djs (false) Whether to only include rooms that have dj spots available
50
+ # @option options [Symbol] :genre The genre of music being played in the room, . Possible values are +:rock+, +:electronica+, +:indie+, +:hiphop+, +:pop+, and +:dubstep+.
51
51
  # @option options [Fixnum] :minimum_listeners (1) The minimum number of listeners in the room
52
- # @option options [Fixnum] :sort (:listeners) The order to list rooms in. Possible values are +:created+, +:listeners+, and +:random+.
52
+ # @option options [Symbol] :sort (:listeners) The order to list rooms in. Possible values are +:created+, +:listeners+, and +:random+.
53
53
  # @return [Array<Turntabler::Room>]
54
- # @raise [ArgumentError] if an invalid option is specified
54
+ # @raise [ArgumentError] if an invalid option or value is specified
55
55
  # @raise [Turntabler::Error] if the command fails
56
56
  # @example
57
57
  # rooms.list # => [#<Turntabler::Room ...>, ...]
@@ -70,7 +70,7 @@ module Turntabler
70
70
  :minimum_listeners => 1,
71
71
  :sort => :listeners
72
72
  }.merge(options)
73
-
73
+
74
74
  constraints = []
75
75
  constraints << :favorites if options[:favorites]
76
76
  constraints << :available_djs if options[:available_djs]
@@ -90,7 +90,7 @@ module Turntabler
90
90
  data['rooms'].map {|attrs| Room.new(client, attrs)}
91
91
  end
92
92
 
93
- # Get the rooms where your friends are currently in.
93
+ # Gets the rooms where the current user's friends are currently listening.
94
94
  #
95
95
  # @return [Array<Turntabler::Room>]
96
96
  # @raise [Turntabler::Error] if the command fails
@@ -67,7 +67,7 @@ module Turntabler
67
67
  attribute :votes, :votelog, :load => false do |votes|
68
68
  votes.each do |(user_id, direction)|
69
69
  self.votes.delete_if {|vote| vote.user.id == user_id}
70
- self.votes << Vote.new(client, :userid => user_id, :direction => direction)
70
+ self.votes << Vote.new(client, :userid => user_id, :direction => direction) if user_id && !user_id.empty?
71
71
  end
72
72
  self.votes
73
73
  end
@@ -19,7 +19,7 @@ module Turntabler
19
19
  # @return [String]
20
20
  attribute :category
21
21
 
22
- # How much it costs to purchase this sticker for use
22
+ # The cost to purchase this sticker for use
23
23
  # @return [Fixnum]
24
24
  attribute :price
25
25
 
@@ -35,7 +35,7 @@ module Turntabler
35
35
  #
36
36
  # @param [Fixnum] top The y-coordinate of the sticker
37
37
  # @param [Fixnum] left The x-coordinate of the sticker
38
- # @param [Fixnum] angle The degree at which the sticker is angled
38
+ # @param [Float] angle The degree at which the sticker is angled
39
39
  # @return [true]
40
40
  # @raise [Turntabler::Error] if the command fails
41
41
  # @example
@@ -19,7 +19,7 @@ module Turntabler
19
19
  attribute :left
20
20
 
21
21
  # The degree at which the sticker is tilted
22
- # @return [Fixnum]
22
+ # @return [Float]
23
23
  attribute :angle
24
24
  end
25
25
  end
@@ -34,13 +34,13 @@ module Turntabler
34
34
  # @return [Fixnum]
35
35
  attribute :fans_count, :fans
36
36
 
37
- # The user's unique identifier on Facebook (only available if the user is
38
- # connected to the authorized user through Facebook)
37
+ # The user's unique identifier on Facebook
38
+ # @note This is only available if the user is connected to the authorized user through Facebook
39
39
  # @return [String]
40
40
  attribute :facebook_url, :facebook
41
41
 
42
- # The user's unique identifier on Twitter (only available if the user is
43
- # connected to the authorized user through Twitter)
42
+ # The user's unique identifier on Twitter
43
+ # @note This is only available if the user is connected to the authorized user through Twitter
44
44
  # @return [String]
45
45
  attribute :twitter_id, :twitter, :twitterid_lower
46
46
 
@@ -56,7 +56,7 @@ module Turntabler
56
56
  # @return [String]
57
57
  attribute :top_artists, :topartists
58
58
 
59
- # Whether on Turntable the user likes to hang out
59
+ # A description of the rooms on Turntable the user likes to hang out
60
60
  # @return [String]
61
61
  attribute :hangout
62
62
 
@@ -85,7 +85,7 @@ module Turntabler
85
85
  self.attributes = data
86
86
  super
87
87
  end
88
-
88
+
89
89
  # Gets the availability status for this user.
90
90
  #
91
91
  # @return [String] "available" / "unavailable"
@@ -97,7 +97,7 @@ module Turntabler
97
97
  data['presence']['status']
98
98
  end
99
99
 
100
- # Gets the stickers that are currently placed on the user.
100
+ # Gets the stickers that are currently placed on the user's laptop.
101
101
  #
102
102
  # @param [Boolean] reload Whether to forcefully reload the user's list of sticker placements
103
103
  # @return [Array<Turntabler::StickerPlacement>]
@@ -213,12 +213,11 @@ module Turntabler
213
213
  # Gets the location of the user.
214
214
  #
215
215
  # @note This will make the current user a fan of this user
216
- # @param [Boolean] all_info Whether full detailed information should be provided about the room and user
217
- # @return [Array<Turntabler::Room>]
216
+ # @return [Turntabler::Room]
218
217
  # @raise [Turntabler::Error] if the command fails
219
218
  # @example
220
- # user.stalk # => #<Turntabler::User ...>
221
- def stalk(all_info = false)
219
+ # user.stalk # => #<Turntabler::Room ...>
220
+ def stalk
222
221
  become_fan unless client.user.fan_of.include?(self)
223
222
  client.rooms.with_friends.detect do |room|
224
223
  room.listener(id)
@@ -2,8 +2,8 @@ module Turntabler
2
2
  # The current version of the library
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 0
6
- PATCH = 1
5
+ MINOR = 1
6
+ PATCH = 0
7
7
  STRING = [MAJOR, MINOR, PATCH].join(".")
8
8
  end
9
9
  end
data/lib/turntabler.rb CHANGED
@@ -50,8 +50,12 @@ module Turntabler
50
50
  # end
51
51
  #
52
52
  # # Interactive, not in reactor / fiber
53
+ # Turntabler.interactive
53
54
  # Turntabler.run do
54
- # client.room.become_dj
55
+ # @client = ...
56
+ # end
57
+ # Turntabler.run do
58
+ # @client.room.become_dj
55
59
  # # ...
56
60
  # end
57
61
  #
@@ -61,7 +65,7 @@ module Turntabler
61
65
  #
62
66
  # @example DSL
63
67
  # # Takes the same arguments as Turntabler::Client
64
- # Turntabler.run(USER, AUTH, :room => ROOM) do
68
+ # Turntabler.run(EMAIL, PASSWORD, :room => ROOM) do
65
69
  # room.become_dj
66
70
  # on :user_enter do
67
71
  # # ...
@@ -84,7 +88,7 @@ module Turntabler
84
88
  # Just run the block within a fiber
85
89
  block.call
86
90
  end
87
- rescue Exception => ex
91
+ rescue StandardError => ex
88
92
  logger.error(([ex.message] + ex.backtrace) * "\n")
89
93
  end
90
94
  end
@@ -99,4 +103,4 @@ module Turntabler
99
103
  end
100
104
 
101
105
  # Provide a simple alias (akin to EM / EventMachine)
102
- TT = Turntabler
106
+ TT = Turntabler unless defined?(TT)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: turntabler
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Aaron Pfeifer
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-11-20 00:00:00 Z
13
+ date: 2012-11-28 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: em-synchrony