marantz 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.
- checksums.yaml +7 -0
- data/.gitignore +34 -0
- data/.travis.yml +5 -0
- data/LICENSE +21 -0
- data/README.rdoc +63 -0
- data/lib/marantz.rb +10 -0
- data/lib/marantz/client.rb +85 -0
- data/lib/marantz/config.rb +39 -0
- data/lib/marantz/exceptions.rb +5 -0
- data/lib/marantz/version.rb +3 -0
- data/marantz.gemspec +22 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c3c38dd30e2467aa2ea28ff83c96b8725fcb868
|
4
|
+
data.tar.gz: 6c1eba20f70240999351d430133d7b7dfd13894b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a7bd1e4258f8a2a58ad0de89fc9468e166ee108c8d9d79a1a5a8ae009531e2f322e3a5b632a1c1db37ab80eebd126f25173cc835032f8f62bb81d4aae7d6c79
|
7
|
+
data.tar.gz: ae3a8cf1f7d7646ff2120b31224a75374d17505c3f7dac14eadad4e7e2f318d7a11ea18fd661beb60062a28d80864b09144f09eb2d387c11e0d84da0ea78cb5a
|
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/.travis.yml
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Christopher Svensson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
= Marantz
|
2
|
+
|
3
|
+
Ruby client that uses Marantz web interface as an API.
|
4
|
+
|
5
|
+
|
6
|
+
== Supported versions
|
7
|
+
|
8
|
+
* Ruby 1.9.3, 2.0.0, 2.1.1
|
9
|
+
|
10
|
+
|
11
|
+
== Install
|
12
|
+
|
13
|
+
Put this line in your Gemfile:
|
14
|
+
gem 'marantz'
|
15
|
+
|
16
|
+
Then bundle:
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
|
20
|
+
== Usage
|
21
|
+
|
22
|
+
=== General configuration options
|
23
|
+
|
24
|
+
You need to configure the gem to fit your needs:
|
25
|
+
|
26
|
+
# Default values
|
27
|
+
Marantz.configure do |config|
|
28
|
+
config.host = '127.0.0.1'
|
29
|
+
config.max_volume = 50
|
30
|
+
end
|
31
|
+
|
32
|
+
=== Initiating client
|
33
|
+
|
34
|
+
avr = Marantz::Client.new
|
35
|
+
|
36
|
+
=== Power on/off
|
37
|
+
avr.on
|
38
|
+
avr.off
|
39
|
+
|
40
|
+
=== Change source
|
41
|
+
|
42
|
+
Currently the following sources are switchable: SAT/CBL, Internet Radio, Spotify
|
43
|
+
|
44
|
+
avr.source = :satellite
|
45
|
+
avr.source = :iradio
|
46
|
+
|
47
|
+
=== Volume
|
48
|
+
|
49
|
+
avr.volume = 35 # dB
|
50
|
+
avr.mute
|
51
|
+
avr.unmute
|
52
|
+
|
53
|
+
== Build Status {<img src="https://secure.travis-ci.org/stoffus/marantz-rb.png"/>}[http://travis-ci.org/stoffus/marantz-rb]
|
54
|
+
|
55
|
+
|
56
|
+
== Questions, Feedback
|
57
|
+
|
58
|
+
Feel free to message me on Github (stoffus).
|
59
|
+
|
60
|
+
|
61
|
+
== Copyright
|
62
|
+
|
63
|
+
Copyright (c) 2014 Christopher Svensson.
|
data/lib/marantz.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'xml'
|
2
|
+
|
3
|
+
module Marantz
|
4
|
+
class Client
|
5
|
+
def initialize
|
6
|
+
raise UnsupportedModel unless SUPPORTED_MODELS.values.include?(status[:model])
|
7
|
+
end
|
8
|
+
|
9
|
+
def source=(name)
|
10
|
+
perform(PATHS[:main_zone], COMMANDS[:source] % (SOURCES[name] or raise UnknownSource))
|
11
|
+
end
|
12
|
+
|
13
|
+
def source
|
14
|
+
status[:source]
|
15
|
+
end
|
16
|
+
|
17
|
+
def volume=(db)
|
18
|
+
db = db.to_f
|
19
|
+
raise VolumeTooHigh if db > Marantz.config.max_volume
|
20
|
+
path = PATHS[:main_zone]
|
21
|
+
perform(path, COMMANDS[:volume] % db_to_volume(db))
|
22
|
+
end
|
23
|
+
|
24
|
+
def volume
|
25
|
+
status[:volume]
|
26
|
+
end
|
27
|
+
|
28
|
+
def mute
|
29
|
+
toggle_mute(:on)
|
30
|
+
end
|
31
|
+
|
32
|
+
def unmute
|
33
|
+
toggle_mute(:off)
|
34
|
+
end
|
35
|
+
|
36
|
+
def on
|
37
|
+
toggle_power(:on)
|
38
|
+
end
|
39
|
+
|
40
|
+
def off
|
41
|
+
toggle_power(:off)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def toggle_mute(action)
|
47
|
+
perform(PATHS[:main_zone], COMMANDS[:mute] % action)
|
48
|
+
end
|
49
|
+
|
50
|
+
def toggle_power(action)
|
51
|
+
perform(PATHS[:main_zone], COMMANDS[:power] % action)
|
52
|
+
end
|
53
|
+
|
54
|
+
def db_to_volume(db)
|
55
|
+
(VOLUME_THRESHOLD - db.to_f)
|
56
|
+
end
|
57
|
+
|
58
|
+
def volume_to_db(volume)
|
59
|
+
(VOLUME_THRESHOLD + volume.to_f)
|
60
|
+
end
|
61
|
+
|
62
|
+
def status
|
63
|
+
uri = URI('http://' + Marantz.config.host + PATHS[:status])
|
64
|
+
uri.query = URI.encode_www_form({ _: Time.now.to_i * 1_000 })
|
65
|
+
response = Net::HTTP.get(uri)
|
66
|
+
parser = XML::Parser.string(response, encoding: XML::Encoding::UTF_8)
|
67
|
+
doc = parser.parse
|
68
|
+
{
|
69
|
+
power: doc.find('//Power').first.content,
|
70
|
+
source: SOURCES.key(doc.find('//NetFuncSelect').first.content) || :unknown,
|
71
|
+
volume: volume_to_db(doc.find('//MasterVolume').first.content),
|
72
|
+
model: SUPPORTED_MODELS[doc.find('//ModelId').first.content.to_i]
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def perform(path, commands)
|
77
|
+
commands = ([commands].flatten << 'aspMainZone_WebUpdateStatus')
|
78
|
+
params = {}.tap do |hash|
|
79
|
+
commands.each.with_index { |c, i| hash["cmd#{i}"] = c }
|
80
|
+
end
|
81
|
+
uri = URI('http://' + Marantz.config.host + path)
|
82
|
+
result = Net::HTTP.post_form(uri, params)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Marantz
|
2
|
+
extend self
|
3
|
+
VOLUME_THRESHOLD = 80.0
|
4
|
+
COMMANDS = {
|
5
|
+
volume: 'PutMasterVolumeSet/-%s',
|
6
|
+
source: 'PutZone_InputFunction/%s',
|
7
|
+
power: 'PutZone_OnOff/%s',
|
8
|
+
mute: 'PutVolumeMute/%s'
|
9
|
+
}
|
10
|
+
PATHS = {
|
11
|
+
main_zone: '/MainZone/index.put.asp',
|
12
|
+
status: '/goform/formMainZone_MainZoneXml.xml'
|
13
|
+
}
|
14
|
+
SOURCES = {
|
15
|
+
satellite: 'SAT/CBL',
|
16
|
+
iradio: 'IRADIO',
|
17
|
+
spotify: 'SPOTIFY'
|
18
|
+
}
|
19
|
+
SUPPORTED_MODELS = {
|
20
|
+
9 => 'SR5008'
|
21
|
+
}
|
22
|
+
|
23
|
+
def configure(&block)
|
24
|
+
yield @config ||= Configuration.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def config
|
28
|
+
@config
|
29
|
+
end
|
30
|
+
|
31
|
+
class Configuration
|
32
|
+
attr_accessor :host, :max_volume
|
33
|
+
end
|
34
|
+
|
35
|
+
configure do |config|
|
36
|
+
config.host = '10.0.1.21'
|
37
|
+
config.max_volume = 50.0
|
38
|
+
end
|
39
|
+
end
|
data/marantz.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'marantz/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.name = 'marantz'
|
7
|
+
s.version = Marantz::VERSION
|
8
|
+
s.author = 'Christopher Svensson'
|
9
|
+
s.email = 'stoffus@stoffus.com'
|
10
|
+
s.homepage = 'https://github.com/stoffus/marantz-rb'
|
11
|
+
s.summary = 'Ruby client for controlling Marantz AVRs.'
|
12
|
+
s.description = 'Ruby client that uses Marantz web interface as an API.'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.required_ruby_version = '>= 1.9.3'
|
16
|
+
s.required_rubygems_version = '>= 1.8.11'
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marantz
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Svensson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby client that uses Marantz web interface as an API.
|
14
|
+
email: stoffus@stoffus.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".gitignore"
|
20
|
+
- ".travis.yml"
|
21
|
+
- LICENSE
|
22
|
+
- README.rdoc
|
23
|
+
- lib/marantz.rb
|
24
|
+
- lib/marantz/client.rb
|
25
|
+
- lib/marantz/config.rb
|
26
|
+
- lib/marantz/exceptions.rb
|
27
|
+
- lib/marantz/version.rb
|
28
|
+
- marantz.gemspec
|
29
|
+
homepage: https://github.com/stoffus/marantz-rb
|
30
|
+
licenses:
|
31
|
+
- MIT
|
32
|
+
metadata: {}
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.9.3
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.8.11
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 2.2.2
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Ruby client for controlling Marantz AVRs.
|
53
|
+
test_files: []
|