turntabler 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +15 -0
- data/README.md +118 -76
- data/examples/Gemfile.lock +1 -1
- data/examples/autobop.rb +4 -4
- data/examples/autofan.rb +4 -4
- data/examples/blacklist.rb +4 -4
- data/examples/bop.rb +4 -4
- data/examples/bopcount.rb +4 -4
- data/examples/chat_bot.rb +4 -4
- data/examples/modlist.rb +4 -4
- data/examples/switch.rb +4 -4
- data/examples/time_afk_list.rb +4 -4
- data/lib/turntabler/authorized_user.rb +47 -11
- data/lib/turntabler/boot.rb +1 -1
- data/lib/turntabler/client.rb +64 -20
- data/lib/turntabler/connection.rb +4 -4
- data/lib/turntabler/digest_helpers.rb +3 -1
- data/lib/turntabler/event.rb +25 -15
- data/lib/turntabler/handler.rb +16 -9
- data/lib/turntabler/loggable.rb +2 -0
- data/lib/turntabler/playlist.rb +1 -1
- data/lib/turntabler/preferences.rb +12 -11
- data/lib/turntabler/resource.rb +15 -13
- data/lib/turntabler/room.rb +19 -13
- data/lib/turntabler/room_directory.rb +6 -6
- data/lib/turntabler/song.rb +1 -1
- data/lib/turntabler/sticker.rb +2 -2
- data/lib/turntabler/sticker_placement.rb +1 -1
- data/lib/turntabler/user.rb +10 -11
- data/lib/turntabler/version.rb +2 -2
- data/lib/turntabler.rb +8 -4
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# master
|
2
2
|
|
3
|
+
## 0.1.0 / 2012-11-27
|
4
|
+
|
5
|
+
* Add :reconnected event for hooking in logic when a client reconnects
|
6
|
+
* Gracefully handle error cases where APIs are called from a root fiber
|
7
|
+
* Don't re-define the TT constant if it's already been defined
|
8
|
+
* Add Turntabler::Client#user_by_name for looking up users by their name instead of id
|
9
|
+
* Allow authentication via user ids / auth tokens if a password is unavailable
|
10
|
+
* Authenticate using emails / passwords instead of user ids / auth tokens
|
11
|
+
* Fix exceptions in callbacks not causing one-time callbacks to be unregistered
|
12
|
+
* Only catch StandardError, not Exception, in Turntabler#run
|
13
|
+
* Fix song votes being tracked with empty user ids
|
14
|
+
* Fix the current dj's points not getting updated on song_voted events
|
15
|
+
* Fix song_ended event never getting fired
|
16
|
+
* Fix laptop names not being able to be updated
|
17
|
+
|
3
18
|
## 0.0.1 / 2012-11-20
|
4
19
|
|
5
20
|
* Initial revision
|
data/README.md
CHANGED
@@ -53,8 +53,7 @@ Some brief, high-level features include:
|
|
53
53
|
|
54
54
|
Turntable features include management of:
|
55
55
|
|
56
|
-
* User status
|
57
|
-
* User profiles
|
56
|
+
* User status / profile
|
58
57
|
* Site preferences
|
59
58
|
* Avatars
|
60
59
|
* Laptops / stickers
|
@@ -63,8 +62,7 @@ Turntable features include management of:
|
|
63
62
|
* Buddies (Twitter / Facebook)
|
64
63
|
* Blocked users
|
65
64
|
* Private messages
|
66
|
-
* Advanced room listings
|
67
|
-
* Room search
|
65
|
+
* Advanced room search / listings
|
68
66
|
* Room favorites
|
69
67
|
* Room profiles
|
70
68
|
* Room chat
|
@@ -88,16 +86,16 @@ Below is an example of many of the features offered by this API, including:
|
|
88
86
|
```ruby
|
89
87
|
require 'turntabler'
|
90
88
|
|
91
|
-
|
92
|
-
|
89
|
+
EMAIL = ENV['EMAIL']
|
90
|
+
PASSWORD = ENV['PASSWORD']
|
93
91
|
|
94
92
|
Turntabler.run do
|
95
|
-
client = Turntabler::Client.new(
|
93
|
+
client = Turntabler::Client.new(EMAIL, PASSWORD)
|
96
94
|
|
97
95
|
# Events
|
98
96
|
client.on :user_entered do |user|
|
99
97
|
puts "#{user.name} entered the room"
|
100
|
-
user.become_fan
|
98
|
+
user.become_fan # => true
|
101
99
|
end
|
102
100
|
|
103
101
|
client.on :user_left do |user|
|
@@ -106,7 +104,7 @@ Turntabler.run do
|
|
106
104
|
|
107
105
|
client.on :user_spoke do |message|
|
108
106
|
if message.text =~ /bop/
|
109
|
-
client.room.current_song.vote
|
107
|
+
client.room.current_song.vote # => true
|
110
108
|
end
|
111
109
|
end
|
112
110
|
|
@@ -119,52 +117,59 @@ Turntabler.run do
|
|
119
117
|
end
|
120
118
|
|
121
119
|
# Authorized user interactions
|
122
|
-
user = client.user
|
123
|
-
user.fan_of
|
124
|
-
user.fans
|
125
|
-
user.playlist.songs
|
126
|
-
user.blocks
|
127
|
-
user.buddies
|
120
|
+
user = client.user # => #<Turntabler::AuthorizedUser:0x95631b0 @email="ben.zelano@gmail.com" ...>
|
121
|
+
user.fan_of # => [#<Turntabler::User:0x95ccb38 @id="d5616b31654e8b22a7a1eef0">, ...]
|
122
|
+
user.fans # => [#<Turntabler::User:0x95dd1cc @id="d5616b31654e8b22a7a1eef0">, ...]
|
123
|
+
user.playlist.songs # => [#<Turntabler::Song:0x9610b44 @album="Abbey Road" ...>, ...]
|
124
|
+
user.blocks # => [#<Turntabler::User:0x9792724 @id="19125d4da3b09562b2cf68b6">, ...]
|
125
|
+
user.buddies # => [#<Turntabler::User:0x9792580 @id="efff38aeb7b9334164c1b630">, ...]
|
128
126
|
|
129
127
|
# Room Directory
|
130
|
-
client.rooms.list(:favorites => true)
|
131
|
-
client.rooms.list(:genre => :rock)
|
128
|
+
client.rooms.list(:favorites => true) # => []
|
129
|
+
client.rooms.list(:genre => :rock) # => [#<Turntabler::Room:0x985d474 @id="4e4986bb14169c5f241318a6", ...>, ...]
|
132
130
|
client.rooms.list(:genre => :rock, :available_djs => true, :minimum_listeners => 5)
|
133
|
-
|
134
|
-
client.
|
131
|
+
# => [#<Turntabler::Room:0x91c1d04 @id="4f4a5874a3f75128aa006c17", ...>, ...]
|
132
|
+
client.rooms.with_friends # => [#<Turntabler::Room:0x9674c98 @id="50b4c1e2df5bcf4af666f876", ...>, ...]
|
133
|
+
client.room('4dff1eac14169c565800892e').listeners # => #<Set: {#<Turntabler::User:0x96340bc @id="4e1341e2a3f75114d003c591" ...>, ...}>
|
135
134
|
|
136
135
|
# Room interaction
|
137
|
-
|
138
|
-
room.
|
139
|
-
room.
|
140
|
-
room.
|
136
|
+
client.rooms.create("My Test Room #{rand}").enter # => true
|
137
|
+
room = client.room # => #<Turntabler::Room:0x99a16dc @name="My Test Room 0.24300857307298018" ...>
|
138
|
+
room.add_as_favorite # => true
|
139
|
+
room.become_dj # => true
|
140
|
+
room.say "Hey guys!" # => true
|
141
141
|
|
142
142
|
# User interaction
|
143
|
-
|
144
|
-
|
145
|
-
listener.
|
146
|
-
listener.
|
147
|
-
listener.
|
148
|
-
listener.
|
143
|
+
listeners = room.listeners # => #<Set: {#<Turntabler::User:0x95631b0 @id="309ba75b6385b83e110923bd" ..., ...}>
|
144
|
+
listeners.each do |listener|
|
145
|
+
listener.messages # => [#<Turntabler::Message:0x99aa1ec @content="Hey man!" ...>, ...]
|
146
|
+
listener.website # => "http://mypersonalwebsite.com"
|
147
|
+
listener.facebook_url # => "https://www.facebook.com/firstname.lastname"
|
148
|
+
listener.sticker_placements # => [#<Turntabler::StickerPlacement:0x9861024 @angle=0 ...>, ...]
|
149
|
+
listener.say "Welcome to the room!" # => true
|
149
150
|
end
|
150
151
|
|
151
152
|
# Songs
|
152
|
-
client.search_song('Rolling Stones')
|
153
|
-
|
153
|
+
songs = client.search_song('Rolling Stones') # => [#<Turntabler::Song:0x983c198 @album="Tattoo You (2009 Remaster)" ...>, ...]
|
154
|
+
songs.each do
|
155
|
+
song.enqueue # => true
|
154
156
|
end
|
155
157
|
end
|
156
158
|
```
|
157
159
|
|
158
|
-
The
|
160
|
+
The example above is just a very, very small subset of the possible things you
|
159
161
|
can do with turntabler. For a *complete* list, see the API documentation, especially:
|
160
162
|
|
161
|
-
* [Turntabler::AuthorizedUser](http://rdoc.info/github/obrie/turntabler/master/Turntabler/AuthorizedUser)
|
162
|
-
* [Turntabler::Client](http://rdoc.info/github/obrie/turntabler/master/Turntabler/Client)
|
163
|
-
* [Turntabler::Playlist](http://rdoc.info/github/obrie/turntabler/master/Turntabler/Playlist)
|
164
|
-
* [Turntabler::Room](http://rdoc.info/github/obrie/turntabler/master/Turntabler/Room)
|
165
|
-
* [Turntabler::RoomDirectory](http://rdoc.info/github/obrie/turntabler/master/Turntabler/RoomDirectory)
|
166
|
-
* [Turntabler::Song](http://rdoc.info/github/obrie/turntabler/master/Turntabler/Song)
|
167
|
-
* [Turntabler::User](http://rdoc.info/github/obrie/turntabler/master/Turntabler/User)
|
163
|
+
* [Turntabler::AuthorizedUser](http://rdoc.info/github/obrie/turntabler/master/frames/Turntabler/AuthorizedUser)
|
164
|
+
* [Turntabler::Client](http://rdoc.info/github/obrie/turntabler/master/frames/Turntabler/Client)
|
165
|
+
* [Turntabler::Playlist](http://rdoc.info/github/obrie/turntabler/master/frames/Turntabler/Playlist)
|
166
|
+
* [Turntabler::Room](http://rdoc.info/github/obrie/turntabler/master/frames/Turntabler/Room)
|
167
|
+
* [Turntabler::RoomDirectory](http://rdoc.info/github/obrie/turntabler/master/frames/Turntabler/RoomDirectory)
|
168
|
+
* [Turntabler::Song](http://rdoc.info/github/obrie/turntabler/master/frames/Turntabler/Song)
|
169
|
+
* [Turntabler::User](http://rdoc.info/github/obrie/turntabler/master/frames/Turntabler/User)
|
170
|
+
|
171
|
+
For additional examples, see the [examples](https://github.com/obrie/turntabler/tree/master/examples)
|
172
|
+
directory in the repository.
|
168
173
|
|
169
174
|
## Additional Topics
|
170
175
|
|
@@ -181,16 +186,49 @@ Existing implementations include:
|
|
181
186
|
* [ruby_ttapi](https://github.com/alaingilbert/Turntable-API)
|
182
187
|
* [TurntableBot](https://github.com/mrhazel/TurntableBot)
|
183
188
|
|
184
|
-
My personal
|
185
|
-
build libraries with in Ruby. Those include evented I/O, untangled
|
186
|
-
object-oriented APIs, external API consistency, internal state
|
187
|
-
auto lazy-loading, etc. Some of these libraries are also either
|
188
|
-
implementations, difficult to use / play around with, or generally
|
189
|
-
together as a script instead of
|
189
|
+
My personal belief is that none of these libraries reflect the simplicity that
|
190
|
+
you can build libraries with in Ruby. Those include evented I/O, untangled
|
191
|
+
callbacks, object-oriented APIs, external API consistency, internal state
|
192
|
+
management, auto lazy-loading, etc. Some of these libraries are also either
|
193
|
+
incomplete implementations, difficult to use / play around with, or generally
|
194
|
+
just put together as a script instead of an organized library.
|
190
195
|
|
191
196
|
However, by no means does that mean I'm attempting to belittle the efforts put
|
192
|
-
|
193
|
-
|
197
|
+
forth by these authors -- all of their work provided the foundation necessary to
|
198
|
+
build out this project.
|
199
|
+
|
200
|
+
### Authentication
|
201
|
+
|
202
|
+
By default, turntabler authenticates users with the e-mail address and password
|
203
|
+
associated with their account. For example:
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
TT.run do
|
207
|
+
client = TT::Client.new(EMAIL, PASSWORD)
|
208
|
+
# ...
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
However, older Turntable accounts do not have e-mail addresses or passwords
|
213
|
+
associated with them since they were initially created through a third-party
|
214
|
+
social network like Facebook or Twitter. If you're using an account like that,
|
215
|
+
you can do one of two things: (1) Add an e-mail / password through the
|
216
|
+
"Manage Accounts" link on Turntable or (2) configure the user's id / auth token
|
217
|
+
manually.
|
218
|
+
|
219
|
+
If you do not wish to set up an e-mail / password, you can generate your user id
|
220
|
+
and auth token via the directions @ http://alaingilbert.github.com/Turntable-API/bookmarklet.html.
|
221
|
+
Once generated, you can use them in turntabler like so:
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
TT.run do
|
225
|
+
client = TT::Client.new(EMAIL, PASSWORD, :user_id => USER_ID, :auth => AUTH)
|
226
|
+
# ...
|
227
|
+
end
|
228
|
+
```
|
229
|
+
|
230
|
+
In this example, `EMAIL` and `PASSWORD` can be any value since they won't need
|
231
|
+
to be used to generate the user id / auth token.
|
194
232
|
|
195
233
|
### Shortcuts
|
196
234
|
|
@@ -201,29 +239,32 @@ result, you can interact with the API like so:
|
|
201
239
|
|
202
240
|
```ruby
|
203
241
|
TT.run do
|
204
|
-
client = TT::Client.new(
|
242
|
+
client = TT::Client.new(EMAIL, PASSWORD, :room => ROOM)
|
205
243
|
client.room.become_dj
|
206
244
|
# ...
|
207
245
|
end
|
208
246
|
```
|
209
247
|
|
248
|
+
Note, however, that if `TT` is already defined when this library is loaded, then
|
249
|
+
the constant won't get redefined.
|
250
|
+
|
210
251
|
### Interactive Console
|
211
252
|
|
212
253
|
Typically it's difficult to debug or run simple tests within IRB when using
|
213
|
-
EventMachine. However, turntabler provides a
|
214
|
-
you can play around with the API interactively.
|
254
|
+
[EventMachine](http://rubyeventmachine.com/). However, turntabler provides a
|
255
|
+
few simple ways to do this so that you can play around with the API interactively.
|
215
256
|
|
216
257
|
For example:
|
217
258
|
|
218
259
|
```ruby
|
219
260
|
1.9.3-p286 :001 > require 'turntabler'
|
220
261
|
=> true
|
221
|
-
1.9.3-p286 :002 >
|
262
|
+
1.9.3-p286 :002 > Turntabler.interactive
|
222
263
|
=> true
|
223
264
|
1.9.3-p286 :003 > client = nil
|
224
265
|
=> nil
|
225
|
-
1.9.3-p286 :004 >
|
226
|
-
1.9.3-p286 :005 > client = Turntabler::Client.new(
|
266
|
+
1.9.3-p286 :004 > Turntabler.run do
|
267
|
+
1.9.3-p286 :005 > client = Turntabler::Client.new(EMAIL, PASSWORD)
|
227
268
|
1.9.3-p286 :006 > end
|
228
269
|
=> nil
|
229
270
|
D, [2012-11-20T08:36:08.025015 #21419] DEBUG -- : Socket opened
|
@@ -236,7 +277,7 @@ D, [2012-11-20T08:36:08.189158 #21419] DEBUG -- : Message sent: {:api=>"presence
|
|
236
277
|
D, [2012-11-20T08:36:08.266749 #21419] DEBUG -- : Message received: {"msgid"=>3, "success"=>true, ...}
|
237
278
|
|
238
279
|
# later on...
|
239
|
-
1.9.3-p286 :008 >
|
280
|
+
1.9.3-p286 :008 > Turntabler.run { puts client.user.fan_of.inspect }
|
240
281
|
=> nil
|
241
282
|
D, [2012-11-20T08:39:41.084693 #21419] DEBUG -- : Message sent: {:api=>"user.get_fan_of", ...}
|
242
283
|
D, [2012-11-20T08:39:41.159466 #21419] DEBUG -- : Message received: {"msgid"=>25, "success"=>true, ...}
|
@@ -245,32 +286,32 @@ D, [2012-11-20T08:39:41.159466 #21419] DEBUG -- : Message received: {"msgid"=>25
|
|
245
286
|
|
246
287
|
In this example, an instance of `Turntabler::Client` is created and tracked in
|
247
288
|
the console. Later on, we can then run a command on that client by evaluating
|
248
|
-
it within a `
|
249
|
-
this is for demonstration purposes only and can be turned off
|
250
|
-
the logging level of `Turntabler.logger`.
|
289
|
+
it within a `Turntabler.run` block. Note that additional debugging output is
|
290
|
+
displayed -- this is for demonstration purposes only and can be turned off
|
291
|
+
simply by changing the logging level of `Turntabler.logger`.
|
251
292
|
|
252
|
-
### DSL
|
293
|
+
### DSL syntax
|
253
294
|
|
254
295
|
turntabler has basic support for a DSL language in order to simplify some of the
|
255
296
|
scripts you may be writing. The DSL is essentially made available by executing
|
256
|
-
blocks within the context of a Turntabler::Client.
|
297
|
+
blocks within the context of a `Turntabler::Client` instance.
|
257
298
|
|
258
299
|
There are two ways to do this:
|
259
300
|
|
260
301
|
```ruby
|
261
|
-
# Using the
|
302
|
+
# Using the Turntabler.run shortcut:
|
262
303
|
|
263
|
-
|
304
|
+
Turntabler.run(EMAIL, PASSWORD, :room => ROOM) do
|
264
305
|
room.dj
|
265
306
|
on :user_entered do
|
266
307
|
# ...
|
267
308
|
end
|
268
309
|
end
|
269
310
|
|
270
|
-
#
|
311
|
+
# Passing a block into Turntabler::Client:
|
271
312
|
|
272
|
-
|
273
|
-
Turntabler::Client.new(
|
313
|
+
Turntabler.run do
|
314
|
+
Turntabler::Client.new(EMAIL, PASSWORD, :room => ROOM) do
|
274
315
|
room.dj
|
275
316
|
on :user_entered do
|
276
317
|
# ...
|
@@ -279,15 +320,15 @@ TT.run do
|
|
279
320
|
end
|
280
321
|
```
|
281
322
|
|
282
|
-
*Note* that you will likely not want to use the first example (using the
|
283
|
-
shortcut when running in the context of a web request in a
|
284
|
-
because it will start a new Fiber.
|
323
|
+
*Note* that you will likely not want to use the first example (using the
|
324
|
+
`Turntabler.run` shortcut) when running in the context of a web request in a
|
325
|
+
web server, simply because it will start a new Fiber.
|
285
326
|
|
286
327
|
The equivalent, non-DSL example looks like so:
|
287
328
|
|
288
329
|
```ruby
|
289
|
-
|
290
|
-
client = Turntabler::Client.new(
|
330
|
+
Turntabler.run do
|
331
|
+
client = Turntabler::Client.new(EMAIL, PASSWORD, :room => ROOM)
|
291
332
|
client.room.dj
|
292
333
|
client.on :user_entered do
|
293
334
|
# ...
|
@@ -296,8 +337,10 @@ end
|
|
296
337
|
```
|
297
338
|
|
298
339
|
Notice that in this example the syntax is essentially the same except that we're
|
299
|
-
one level out and need to interact directly with the Turntabler::Client
|
300
|
-
itself.
|
340
|
+
one level out and need to interact directly with the `Turntabler::Client`
|
341
|
+
instance itself.
|
342
|
+
|
343
|
+
## Usage
|
301
344
|
|
302
345
|
### Web Server Usage
|
303
346
|
|
@@ -312,7 +355,7 @@ already running EventMachine and already executing code within a non-root Fiber
|
|
312
355
|
you can just run your block like normal:
|
313
356
|
|
314
357
|
```ruby
|
315
|
-
client = Turntabler::Client.new(
|
358
|
+
client = Turntabler::Client.new(EMAIL, PASSWORD, :room => ROOM)
|
316
359
|
songs = client.user.playlist.songs
|
317
360
|
# ...
|
318
361
|
```
|
@@ -328,14 +371,14 @@ keep attempting to re-open a connection when it's been closed.
|
|
328
371
|
For example:
|
329
372
|
|
330
373
|
```ruby
|
331
|
-
|
374
|
+
Turntabler.run(EMAIL, PASSWORD, :room => ROOM, :reconnect => true, :reconnect_wait => 60) do
|
332
375
|
# ...
|
333
376
|
end
|
334
377
|
```
|
335
378
|
|
336
379
|
In this example, turntabler will automatically attempt to reconnect if the socket
|
337
380
|
is ever closed by reasons other than you closing it yourself. However, rather
|
338
|
-
than constantly trying to hit Turntable's servers you can
|
381
|
+
than constantly trying to hit Turntable's servers you can configure a reconnect
|
339
382
|
wait timeout that will cause turntabler to wait a certain number of seconds before
|
340
383
|
attempting to open a connection. This will continue to happen until the connection
|
341
384
|
is successful. If you were previously in a room, this will also automatically
|
@@ -355,7 +398,7 @@ bundle exec rspec
|
|
355
398
|
The following caveats should be noted when using turntabler:
|
356
399
|
|
357
400
|
* Since this library uses EventMachine / Fibers it will only be compatible with
|
358
|
-
web servers that support those
|
401
|
+
web servers that support those technologies. Examples of such web servers include:
|
359
402
|
* [Thin](http://code.macournoyer.com/thin/)
|
360
403
|
* [Rainbows](http://rainbows.rubyforge.org/)
|
361
404
|
* [Goliath](http://postrank-labs.github.com/goliath/)
|
@@ -366,7 +409,6 @@ The following caveats should be noted when using turntabler:
|
|
366
409
|
## Things to do
|
367
410
|
|
368
411
|
* Add test coverage
|
369
|
-
* Expand on README and examples
|
370
412
|
|
371
413
|
## Contributions
|
372
414
|
|
data/examples/Gemfile.lock
CHANGED
data/examples/autobop.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# Each time a a new song starts, vote it up
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
|
-
TT.run(
|
9
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
10
10
|
on :song_started do |song|
|
11
11
|
song.vote
|
12
12
|
end
|
data/examples/autofan.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# Fan users who enter the room
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
|
-
TT.run(
|
9
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
10
10
|
on :user_entered do |user|
|
11
11
|
user.become_fan
|
12
12
|
end
|
data/examples/blacklist.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
# Boot users who are on a blacklist
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
9
|
# List of blacklisted user ids
|
10
10
|
blacklist = ['xxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxx']
|
11
11
|
|
12
|
-
TT.run(
|
12
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
13
13
|
on :user_entered do |user|
|
14
14
|
user.boot('You are on the blacklist.') if blacklist.include?(user.id)
|
15
15
|
end
|
data/examples/bop.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# Vote up a song when someone says "bop" in the chat
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
|
-
|
9
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
10
10
|
on :user_spoke do |message|
|
11
11
|
if message.text =~ /bop/
|
12
12
|
client.room.current_song.vote
|
data/examples/bopcount.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
# Vote up a song when 2 people say "bop" in the chat
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
9
|
bops_count = 0
|
10
10
|
|
11
|
-
|
11
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
12
12
|
on :user_spoke do |message|
|
13
13
|
bops_count += 1 if message.text =~ /bop/
|
14
14
|
room.current_song.vote if bops_count == 2
|
data/examples/chat_bot.rb
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# Response to users who say "/hello" in the chat
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
|
-
TT.run(
|
9
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
10
10
|
on :user_spoke do |message|
|
11
11
|
# Respond to "/hello" command
|
12
12
|
if (message.text =~ /^\/hello$/)
|
data/examples/modlist.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
# Moderator commands
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
9
|
# List of moderator ids
|
10
10
|
moderator_ids = ['xxxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxx']
|
11
11
|
|
12
|
-
TT.run(
|
12
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
13
13
|
on :user_spoke do |message|
|
14
14
|
# Response to "/mod" command
|
15
15
|
if moderator_ids.include?(message.sender.id) && message.text =~ /^\/mod$/
|
data/examples/switch.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
# On/Off bot switch
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
9
|
# Bot is on by default
|
10
10
|
is_on = true
|
11
11
|
|
12
|
-
TT.run(
|
12
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
13
13
|
on :user_spoke do |message|
|
14
14
|
if is_on
|
15
15
|
# The bot is on
|
data/examples/time_afk_list.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
# Keep the last activity timestamp of everyone in the room
|
3
3
|
require 'turntabler'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
ROOM = ENV['ROOM']
|
5
|
+
EMAIL = ENV['EMAIL'] # 'xxxxx@xxxxx.com'
|
6
|
+
PASSWORD = ENV['PASSWORD'] # 'xxxxx'
|
7
|
+
ROOM = ENV['ROOM'] # 'xxxxxxxxxxxxxxxxxxxxxxxx'
|
8
8
|
|
9
9
|
# Reset the users list
|
10
10
|
last_activity = {}
|
11
11
|
|
12
|
-
|
12
|
+
TT.run(EMAIL, PASSWORD, :room => ROOM) do
|
13
13
|
room.listeners.each do |user|
|
14
14
|
last_activity[user.id] = Time.now
|
15
15
|
end
|
@@ -6,13 +6,13 @@ require 'turntabler/sticker_placement'
|
|
6
6
|
module Turntabler
|
7
7
|
# Represents a user who has authorized with the Turntable service
|
8
8
|
class AuthorizedUser < User
|
9
|
-
# The
|
9
|
+
# The authentication token required to connect to the API
|
10
10
|
# @return [String]
|
11
|
-
attribute :
|
11
|
+
attribute :auth, :userauth
|
12
12
|
|
13
|
-
# The
|
13
|
+
# The current availability status of the user ("available", "unavailable", or "away")
|
14
14
|
# @return [String]
|
15
|
-
attribute :
|
15
|
+
attribute :status
|
16
16
|
|
17
17
|
# The user's unique identifier on Facebook
|
18
18
|
# @return [String]
|
@@ -22,14 +22,15 @@ module Turntabler
|
|
22
22
|
# @return [String]
|
23
23
|
attribute :twitter_id, :twitterid
|
24
24
|
|
25
|
-
# The e-mail address the user registered with on Turntable
|
25
|
+
# The e-mail address the user registered with on Turntable. This is
|
26
|
+
# typically only set if the user didn't log in via Facebook or Twitter.
|
26
27
|
# @return [String]
|
27
28
|
attribute :email
|
28
29
|
|
29
|
-
#
|
30
|
-
# typically only
|
31
|
-
# @return [
|
32
|
-
attribute :
|
30
|
+
# The password associated with the e-mail address registered with on Turntable.
|
31
|
+
# This is typically only set if the user didn't log in via Facebook or Twitter.
|
32
|
+
# @return [String]
|
33
|
+
attribute :password
|
33
34
|
|
34
35
|
# The user's current Turntable preferences
|
35
36
|
# @return [Turntabler::Preferences]
|
@@ -43,11 +44,46 @@ module Turntabler
|
|
43
44
|
super
|
44
45
|
end
|
45
46
|
|
46
|
-
#
|
47
|
+
# Gets the Turntable id associated with this user for use with API services.
|
48
|
+
# This will log the user in via email / password if it's not already set.
|
49
|
+
#
|
50
|
+
# @return [String]
|
51
|
+
# @raise [Turntabler::Error] if the command fails
|
52
|
+
def id
|
53
|
+
login unless @id
|
54
|
+
@id
|
55
|
+
end
|
56
|
+
|
57
|
+
# Gets the authentication token associated with this user for use with API
|
58
|
+
# services. This will log the user in via email / password if it's not already
|
59
|
+
# set.
|
60
|
+
#
|
61
|
+
# @return [String]
|
62
|
+
# @raise [Turntabler::Error] if the command fails
|
63
|
+
def auth
|
64
|
+
login unless @auth
|
65
|
+
@auth
|
66
|
+
end
|
67
|
+
|
68
|
+
# Logs the user in using the associated e-mail address / password. This will
|
69
|
+
# generate a user id / auth token for authentication with the API services.
|
47
70
|
#
|
71
|
+
# @api private
|
48
72
|
# @return [true]
|
49
73
|
# @raise [Turntabler::Error] if the command fails
|
74
|
+
def login
|
75
|
+
response = EventMachine::HttpRequest.new('https://turntable.fm/api/user.email_login').get(:query => {:email => email, :password => password, :client => client.id}).response
|
76
|
+
data = JSON.parse(response)
|
77
|
+
raise(Error, data[1]['err']) unless data[0]
|
78
|
+
self.attributes = data[1]
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
# Authenticates the current user with turntable.
|
83
|
+
#
|
50
84
|
# @api private
|
85
|
+
# @return [true]
|
86
|
+
# @raise [Turntabler::Error] if the command fails
|
51
87
|
def authenticate
|
52
88
|
api('user.authenticate')
|
53
89
|
true
|
@@ -201,7 +237,7 @@ module Turntabler
|
|
201
237
|
assert_valid_values(name, *%w(mac pc linux chrome iphone cake intel android))
|
202
238
|
|
203
239
|
api('user.modify', :laptop => name)
|
204
|
-
self.
|
240
|
+
self.attributes = {'laptop' => name}
|
205
241
|
true
|
206
242
|
end
|
207
243
|
|