eventmachine-swinsian 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +43 -0
- data/Rakefile +10 -0
- data/eventmachine-swinsian.gemspec +22 -0
- data/lib/eventmachine-swinsian.rb +41 -0
- data/lib/eventmachine-swinsian/version.rb +5 -0
- data/spec/eventmachine-swinsian_spec.rb +55 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/controller.rb +25 -0
- data/spec/support/watcher.rb +8 -0
- metadata +132 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 youpy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# eventmachine-swinsian
|
2
|
+
|
3
|
+
An [EventMachine](http://wiki.github.com/eventmachine/eventmachine/) extension to watch [Swinsian](http://swinsian.com/) play/pause/stop
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'eventmachine-swinsian'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install eventmachine-swinsian
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
module Watcher
|
23
|
+
def on_play(info)
|
24
|
+
puts 'now playing %s' % [info['artist'], info['title']].join(' - ')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
EM.run {
|
29
|
+
EM.watch_swinsian(Watcher)
|
30
|
+
}
|
31
|
+
```
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
40
|
+
|
41
|
+
## See also
|
42
|
+
|
43
|
+
- http://swinsian.com/support/developers.html
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/eventmachine-swinsian/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["youpy"]
|
6
|
+
gem.email = ["youpy@buycheapviagraonlinenow.com"]
|
7
|
+
gem.description = "An EventMachine extension to watch Swinsian"
|
8
|
+
gem.summary = "An EventMachine extension to watch Swinsian"
|
9
|
+
gem.homepage = "https://github.com/youpy/eventmachine-swinsian"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "eventmachine-swinsian"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Eventmachine::Swinsian::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency('json')
|
19
|
+
gem.add_dependency('eventmachine-distributed-notification', '>= 0.2.0')
|
20
|
+
gem.add_development_dependency('rspec', ['~> 2.8.0'])
|
21
|
+
gem.add_development_dependency('rake')
|
22
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'eventmachine-swinsian/version'
|
2
|
+
require 'eventmachine-distributed-notification'
|
3
|
+
|
4
|
+
module EventMachine
|
5
|
+
class SwinsianWatch < DistributedNotificationWatch
|
6
|
+
ACTION_PLAYING = 'com.swinsian.Swinsian-Track-Playing'
|
7
|
+
ACTION_PAUSED = 'com.swinsian.Swinsian-Track-Paused'
|
8
|
+
ACTION_STOPPED = 'com.swinsian.Swinsian-Track-Stopped'
|
9
|
+
|
10
|
+
def notify(name, user_info)
|
11
|
+
case name
|
12
|
+
when ACTION_PLAYING
|
13
|
+
on_play(user_info)
|
14
|
+
when ACTION_PAUSED
|
15
|
+
on_pause(user_info)
|
16
|
+
when ACTION_STOPPED
|
17
|
+
on_stop(user_info)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_play(user_info); end
|
22
|
+
def on_pause(user_info); end
|
23
|
+
def on_stop(user_info); end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.watch_swinsian(handler = nil, *args, &block)
|
27
|
+
args = [
|
28
|
+
[
|
29
|
+
SwinsianWatch::ACTION_PLAYING,
|
30
|
+
SwinsianWatch::ACTION_PAUSED,
|
31
|
+
SwinsianWatch::ACTION_STOPPED
|
32
|
+
],
|
33
|
+
*args
|
34
|
+
]
|
35
|
+
klass = klass_from_handler(EventMachine::SwinsianWatch, handler, *args);
|
36
|
+
c = klass.new(*args, &block)
|
37
|
+
c.start
|
38
|
+
yield c if block_given?
|
39
|
+
c
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'spec_helper'
|
5
|
+
require 'watcher'
|
6
|
+
require 'controller'
|
7
|
+
|
8
|
+
describe EventMachine::SwinsianWatch do
|
9
|
+
before do
|
10
|
+
@swinsian = Controller.new
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
@swinsian.pause
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should watch playing with class' do
|
18
|
+
watcher = nil
|
19
|
+
|
20
|
+
EM.run {
|
21
|
+
watcher = EM.watch_swinsian(Watcher)
|
22
|
+
@swinsian.play
|
23
|
+
|
24
|
+
EM::add_timer(3) {
|
25
|
+
EM.stop
|
26
|
+
watcher.stop
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
watcher.user_info['length'].should be_kind_of(Float)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should watch playing with block' do
|
34
|
+
result = nil
|
35
|
+
watcher = nil
|
36
|
+
|
37
|
+
EM.run {
|
38
|
+
watcher = EM.watch_swinsian {|c|
|
39
|
+
(class << c; self; end).send(:define_method, :on_play) {|info|
|
40
|
+
result = info
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
@swinsian.play
|
45
|
+
|
46
|
+
EM::add_timer(3) {
|
47
|
+
EM.stop
|
48
|
+
watcher.stop
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
result.should_not be_nil
|
53
|
+
result['length'].should be_kind_of(Float)
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'support'))
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'eventmachine-swinsian'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
config.filter_run :focus
|
12
|
+
|
13
|
+
# Run specs in random order to surface order dependencies. If you find an
|
14
|
+
# order dependency and want to debug it, you can fix the order by providing
|
15
|
+
# the seed, which is printed after each run.
|
16
|
+
# --seed 1234
|
17
|
+
config.order = 'random'
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Controller
|
2
|
+
def launch
|
3
|
+
execute('launch')
|
4
|
+
end
|
5
|
+
|
6
|
+
def play
|
7
|
+
execute('play')
|
8
|
+
end
|
9
|
+
|
10
|
+
def pause
|
11
|
+
execute('pause')
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def execute(script_fragment)
|
17
|
+
IO.popen('osascript -', 'w') do |f|
|
18
|
+
f.write(<<SCRIPT)
|
19
|
+
tell application "Swinsian"
|
20
|
+
#{script_fragment}
|
21
|
+
end tell
|
22
|
+
SCRIPT
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eventmachine-swinsian
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- youpy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: eventmachine-distributed-notification
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.2.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.2.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.8.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.8.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: An EventMachine extension to watch Swinsian
|
79
|
+
email:
|
80
|
+
- youpy@buycheapviagraonlinenow.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- .rspec
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- eventmachine-swinsian.gemspec
|
92
|
+
- lib/eventmachine-swinsian.rb
|
93
|
+
- lib/eventmachine-swinsian/version.rb
|
94
|
+
- spec/eventmachine-swinsian_spec.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/support/controller.rb
|
97
|
+
- spec/support/watcher.rb
|
98
|
+
homepage: https://github.com/youpy/eventmachine-swinsian
|
99
|
+
licenses: []
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: 1076190655359652210
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: 1076190655359652210
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.24
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: An EventMachine extension to watch Swinsian
|
128
|
+
test_files:
|
129
|
+
- spec/eventmachine-swinsian_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/support/controller.rb
|
132
|
+
- spec/support/watcher.rb
|