turntabler 0.0.1

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.
Files changed (48) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/.yardopts +7 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE +20 -0
  7. data/README.md +383 -0
  8. data/Rakefile +11 -0
  9. data/examples/Gemfile +3 -0
  10. data/examples/Gemfile.lock +29 -0
  11. data/examples/autobop.rb +13 -0
  12. data/examples/autofan.rb +13 -0
  13. data/examples/blacklist.rb +16 -0
  14. data/examples/bop.rb +15 -0
  15. data/examples/bopcount.rb +20 -0
  16. data/examples/chat_bot.rb +16 -0
  17. data/examples/modlist.rb +19 -0
  18. data/examples/switch.rb +40 -0
  19. data/examples/time_afk_list.rb +46 -0
  20. data/lib/turntabler/assertions.rb +36 -0
  21. data/lib/turntabler/authorized_user.rb +217 -0
  22. data/lib/turntabler/avatar.rb +34 -0
  23. data/lib/turntabler/boot.rb +22 -0
  24. data/lib/turntabler/client.rb +457 -0
  25. data/lib/turntabler/connection.rb +176 -0
  26. data/lib/turntabler/digest_helpers.rb +13 -0
  27. data/lib/turntabler/error.rb +5 -0
  28. data/lib/turntabler/event.rb +239 -0
  29. data/lib/turntabler/handler.rb +67 -0
  30. data/lib/turntabler/loggable.rb +11 -0
  31. data/lib/turntabler/message.rb +24 -0
  32. data/lib/turntabler/playlist.rb +50 -0
  33. data/lib/turntabler/preferences.rb +70 -0
  34. data/lib/turntabler/resource.rb +194 -0
  35. data/lib/turntabler/room.rb +377 -0
  36. data/lib/turntabler/room_directory.rb +133 -0
  37. data/lib/turntabler/snag.rb +16 -0
  38. data/lib/turntabler/song.rb +247 -0
  39. data/lib/turntabler/sticker.rb +48 -0
  40. data/lib/turntabler/sticker_placement.rb +25 -0
  41. data/lib/turntabler/user.rb +274 -0
  42. data/lib/turntabler/version.rb +9 -0
  43. data/lib/turntabler/vote.rb +19 -0
  44. data/lib/turntabler.rb +102 -0
  45. data/spec/spec_helper.rb +7 -0
  46. data/spec/turntabler_spec.rb +4 -0
  47. data/turntable.gemspec +24 -0
  48. metadata +173 -0
data/lib/turntabler.rb ADDED
@@ -0,0 +1,102 @@
1
+ require 'logger'
2
+ require 'em-synchrony'
3
+
4
+ # Turntable.FM API for Ruby
5
+ module Turntabler
6
+ autoload :Client, 'turntabler/client'
7
+
8
+ class << self
9
+ # The logger to use for all Turntable messages. By default, everything is
10
+ # logged to STDOUT.
11
+ # @return [Logger]
12
+ attr_accessor :logger
13
+
14
+ # Whether this is going to be used in an interactive console such as IRB.
15
+ # If this is enabled then EventMachine will run in a separate thread. This
16
+ # will allow IRB to continue to actually be interactive.
17
+ #
18
+ # @note You must continue to run all commands on a client through Turntabler#run.
19
+ # @example
20
+ # require 'turntabler'
21
+ #
22
+ # Turntabler.interactive
23
+ # Turntabler.run do
24
+ # @client = Turntabler::Client.new(...)
25
+ # @client.start
26
+ # end
27
+ #
28
+ # # ...later on after the connection has started and you want to interact with it
29
+ # Turntabler.run do
30
+ # @client.user.load
31
+ # # ...
32
+ # end
33
+ def interactive
34
+ Thread.new { EM.run }.abort_on_exception = true
35
+ end
36
+
37
+ # Sets up the proper EventMachine reactor / Fiber to run commands against a
38
+ # client. If this is not in interactive mode, then the block won't return
39
+ # until the EventMachine reactor is stopped.
40
+ #
41
+ # @note If you're already running within an EventMachine reactor *and* a
42
+ # Fiber, then there's no need to call this method prior to interacting with
43
+ # a Turntabler::Client instance.
44
+ # @example
45
+ # # Non-interactive, not in reactor / fiber
46
+ # Turntabler.run do
47
+ # client = Turntabler::Client.new(...)
48
+ # client.room.become_dj
49
+ # # ...
50
+ # end
51
+ #
52
+ # # Interactive, not in reactor / fiber
53
+ # Turntabler.run do
54
+ # client.room.become_dj
55
+ # # ...
56
+ # end
57
+ #
58
+ # # Non-interactive, already in reactor / fiber
59
+ # client = Turntabler::Client(...)
60
+ # client.room.become_dj
61
+ #
62
+ # @example DSL
63
+ # # Takes the same arguments as Turntabler::Client
64
+ # Turntabler.run(USER, AUTH, :room => ROOM) do
65
+ # room.become_dj
66
+ # on :user_enter do
67
+ # # ...
68
+ # end
69
+ # end
70
+ #
71
+ # == Exception handling
72
+ #
73
+ # Any exceptions that occur within the block will be automatically caught
74
+ # and logged. This prevents the EventMachine reactor from dying.
75
+ def run(*args, &block)
76
+ if EM.reactor_running?
77
+ EM.next_tick do
78
+ EM.synchrony do
79
+ begin
80
+ if args.any?
81
+ # Run the block within a client
82
+ Client.new(*args, &block)
83
+ else
84
+ # Just run the block within a fiber
85
+ block.call
86
+ end
87
+ rescue Exception => ex
88
+ logger.error(([ex.message] + ex.backtrace) * "\n")
89
+ end
90
+ end
91
+ end
92
+ else
93
+ EM.synchrony { run(*args, &block) }
94
+ end
95
+ end
96
+ end
97
+
98
+ @logger = Logger.new(STDOUT)
99
+ end
100
+
101
+ # Provide a simple alias (akin to EM / EventMachine)
102
+ TT = Turntabler
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH << File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'turntabler'
4
+
5
+ RSpec.configure do |config|
6
+ config.order = 'random'
7
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Turntabler do
4
+ end
data/turntable.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ require 'turntabler/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "turntabler"
6
+ s.version = Turntabler::Version::STRING
7
+ s.authors = ["Aaron Pfeifer"]
8
+ s.email = "aaron.pfeifer@gmail.com"
9
+ s.homepage = "http://github.com/obrie/turntabler"
10
+ s.description = "Turntable.FM API for Ruby"
11
+ s.summary = "Turntable.FM API for Ruby"
12
+ s.require_paths = ["lib"]
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- test/*`.split("\n")
15
+ s.rdoc_options = %w(--line-numbers --inline-source --title turntabler --main README.md)
16
+ s.extra_rdoc_files = %w(README.md CHANGELOG.md LICENSE)
17
+
18
+ s.add_runtime_dependency("em-synchrony")
19
+ s.add_runtime_dependency("em-http-request")
20
+ s.add_runtime_dependency("faye-websocket")
21
+ s.add_development_dependency("rake")
22
+ s.add_development_dependency("rspec", "~> 2.11")
23
+ s.add_development_dependency("simplecov")
24
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turntabler
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Pfeifer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-11-20 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: em-synchrony
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: em-http-request
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: faye-websocket
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: "2.11"
68
+ type: :development
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov
72
+ prerelease: false
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ version_requirements: *id006
81
+ description: Turntable.FM API for Ruby
82
+ email: aaron.pfeifer@gmail.com
83
+ executables: []
84
+
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - README.md
89
+ - CHANGELOG.md
90
+ - LICENSE
91
+ files:
92
+ - .gitignore
93
+ - .rspec
94
+ - .yardopts
95
+ - CHANGELOG.md
96
+ - Gemfile
97
+ - LICENSE
98
+ - README.md
99
+ - Rakefile
100
+ - examples/Gemfile
101
+ - examples/Gemfile.lock
102
+ - examples/autobop.rb
103
+ - examples/autofan.rb
104
+ - examples/blacklist.rb
105
+ - examples/bop.rb
106
+ - examples/bopcount.rb
107
+ - examples/chat_bot.rb
108
+ - examples/modlist.rb
109
+ - examples/switch.rb
110
+ - examples/time_afk_list.rb
111
+ - lib/turntabler.rb
112
+ - lib/turntabler/assertions.rb
113
+ - lib/turntabler/authorized_user.rb
114
+ - lib/turntabler/avatar.rb
115
+ - lib/turntabler/boot.rb
116
+ - lib/turntabler/client.rb
117
+ - lib/turntabler/connection.rb
118
+ - lib/turntabler/digest_helpers.rb
119
+ - lib/turntabler/error.rb
120
+ - lib/turntabler/event.rb
121
+ - lib/turntabler/handler.rb
122
+ - lib/turntabler/loggable.rb
123
+ - lib/turntabler/message.rb
124
+ - lib/turntabler/playlist.rb
125
+ - lib/turntabler/preferences.rb
126
+ - lib/turntabler/resource.rb
127
+ - lib/turntabler/room.rb
128
+ - lib/turntabler/room_directory.rb
129
+ - lib/turntabler/snag.rb
130
+ - lib/turntabler/song.rb
131
+ - lib/turntabler/sticker.rb
132
+ - lib/turntabler/sticker_placement.rb
133
+ - lib/turntabler/user.rb
134
+ - lib/turntabler/version.rb
135
+ - lib/turntabler/vote.rb
136
+ - spec/spec_helper.rb
137
+ - spec/turntabler_spec.rb
138
+ - turntable.gemspec
139
+ homepage: http://github.com/obrie/turntabler
140
+ licenses: []
141
+
142
+ post_install_message:
143
+ rdoc_options:
144
+ - --line-numbers
145
+ - --inline-source
146
+ - --title
147
+ - turntabler
148
+ - --main
149
+ - README.md
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: "0"
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: "0"
164
+ requirements: []
165
+
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.24
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Turntable.FM API for Ruby
171
+ test_files: []
172
+
173
+ has_rdoc: