bravtroller 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +64 -0
- data/LICENSE +22 -0
- data/Rakefile +6 -0
- data/bravtroller.gemspec +30 -0
- data/lib/bravtroller/authenticator.rb +59 -0
- data/lib/bravtroller/client.rb +19 -0
- data/lib/bravtroller/remote.rb +67 -0
- data/lib/bravtroller/version.rb +3 -0
- data/lib/bravtroller.rb +4 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68dcd827b96c8dddcbf6723c1cfbc91f513b92c9
|
4
|
+
data.tar.gz: 675598aee283db134b67f3244133043379680341
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a39d66e9beaa1e7473078c9019472a7b869be43febbc88e08fae52c16e9c6498bad99bbf4a09a1101d6a8238f9a85cad19b651a9c27bacac16c413d05e7d8cf1
|
7
|
+
data.tar.gz: 83de2af313aec84fb0dafe33d53b23e986a22957e1d2acad2f9835683382b1eaa0a452048c8d62f4fd67426071d412a772448afde1bcbfd26ebf91781be8634f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bravtroller (0.1.0)
|
5
|
+
easy_upnp
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
akami (1.3.1)
|
11
|
+
gyoku (>= 0.4.0)
|
12
|
+
nokogiri
|
13
|
+
builder (3.2.2)
|
14
|
+
diff-lcs (1.2.5)
|
15
|
+
easy_upnp (0.1.5)
|
16
|
+
nokogiri (~> 1.6.6.2)
|
17
|
+
nori (~> 2.6.0)
|
18
|
+
rake
|
19
|
+
savon (~> 2.11.1)
|
20
|
+
gyoku (1.3.1)
|
21
|
+
builder (>= 2.1.2)
|
22
|
+
httpi (2.4.1)
|
23
|
+
rack
|
24
|
+
mini_portile (0.6.2)
|
25
|
+
nokogiri (1.6.6.2)
|
26
|
+
mini_portile (~> 0.6.0)
|
27
|
+
nori (2.6.0)
|
28
|
+
rack (1.6.4)
|
29
|
+
rake (10.4.2)
|
30
|
+
rspec (3.3.0)
|
31
|
+
rspec-core (~> 3.3.0)
|
32
|
+
rspec-expectations (~> 3.3.0)
|
33
|
+
rspec-mocks (~> 3.3.0)
|
34
|
+
rspec-core (3.3.1)
|
35
|
+
rspec-support (~> 3.3.0)
|
36
|
+
rspec-expectations (3.3.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.3.0)
|
39
|
+
rspec-mocks (3.3.1)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.3.0)
|
42
|
+
rspec-support (3.3.0)
|
43
|
+
savon (2.11.1)
|
44
|
+
akami (~> 1.2)
|
45
|
+
builder (>= 2.1.2)
|
46
|
+
gyoku (~> 1.2)
|
47
|
+
httpi (~> 2.3)
|
48
|
+
nokogiri (>= 1.4.0)
|
49
|
+
nori (~> 2.4)
|
50
|
+
wasabi (~> 3.4)
|
51
|
+
wasabi (3.5.0)
|
52
|
+
httpi (~> 2.0)
|
53
|
+
nokogiri (>= 1.4.2)
|
54
|
+
|
55
|
+
PLATFORMS
|
56
|
+
ruby
|
57
|
+
|
58
|
+
DEPENDENCIES
|
59
|
+
bravtroller!
|
60
|
+
rake
|
61
|
+
rspec (>= 3.0.0)
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
1.10.5
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Chris Mullins
|
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.
|
22
|
+
|
data/Rakefile
ADDED
data/bravtroller.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
require "bravtroller/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'bravtroller'
|
7
|
+
gem.version = Bravtroller::VERSION
|
8
|
+
|
9
|
+
gem.summary = "Controller for the Bravia KDL-50W700B"
|
10
|
+
|
11
|
+
gem.authors = ['Christopher Mullins']
|
12
|
+
gem.email = 'chris@sidoh.org'
|
13
|
+
gem.homepage = 'http://github.com/sidoh/bravtroller'
|
14
|
+
|
15
|
+
gem.add_dependency('easy_upnp')
|
16
|
+
|
17
|
+
gem.add_development_dependency('rspec', [">= 3.0.0"])
|
18
|
+
gem.add_development_dependency('rake')
|
19
|
+
|
20
|
+
ignores = File.readlines(".gitignore").grep(/\S+/).map(&:chomp)
|
21
|
+
dotfiles = %w[.gitignore]
|
22
|
+
|
23
|
+
all_files_without_ignores = Dir["**/*"].reject { |f|
|
24
|
+
File.directory?(f) || ignores.any? { |i| File.fnmatch(i, f) }
|
25
|
+
}
|
26
|
+
|
27
|
+
gem.files = (all_files_without_ignores + dotfiles).sort
|
28
|
+
|
29
|
+
gem.require_path = "lib"
|
30
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Bravtroller
|
6
|
+
class Authenticator
|
7
|
+
CLIENT_ID = 'bravtroller:de7cd7d5-a9a0-44a1-aba1-57d973a0ee8a'
|
8
|
+
|
9
|
+
AUTH_REQUEST_PARAMS =
|
10
|
+
{
|
11
|
+
method: 'actRegister',
|
12
|
+
params: [
|
13
|
+
{
|
14
|
+
clientid: CLIENT_ID,
|
15
|
+
nickname: 'Bravtroller',
|
16
|
+
level: 'private',
|
17
|
+
},
|
18
|
+
[
|
19
|
+
value: 'yes',
|
20
|
+
function: 'WOL'
|
21
|
+
]
|
22
|
+
],
|
23
|
+
id: 8,
|
24
|
+
version: '1.0'
|
25
|
+
}
|
26
|
+
|
27
|
+
def initialize(bravia_client)
|
28
|
+
@bravia_client = bravia_client
|
29
|
+
end
|
30
|
+
|
31
|
+
def authorized?
|
32
|
+
response = @bravia_client.post_request('/sony/accessControl', AUTH_REQUEST_PARAMS)
|
33
|
+
'200' == response.code
|
34
|
+
end
|
35
|
+
|
36
|
+
def authorize(&callback)
|
37
|
+
response = @bravia_client.post_request('/sony/accessControl', AUTH_REQUEST_PARAMS)
|
38
|
+
|
39
|
+
if response.code == '401'
|
40
|
+
challenge_value = callback.call(response)
|
41
|
+
auth_value = "Basic #{Base64.encode64(":#{challenge_value}")}"
|
42
|
+
headers = { 'Authorization' => auth_value }
|
43
|
+
|
44
|
+
auth_response = @bravia_client.post_request('/sony/accessControl', AUTH_REQUEST_PARAMS, headers)
|
45
|
+
|
46
|
+
extract_cookie(auth_response)
|
47
|
+
else
|
48
|
+
# Already authorized, but the Set-Cookie header should still be set
|
49
|
+
extract_cookie(response)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def extract_cookie(response)
|
56
|
+
response['Set-Cookie'].split(';').first
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Bravtroller
|
5
|
+
class Client
|
6
|
+
def initialize(bravia_address)
|
7
|
+
@bravia_address = bravia_address
|
8
|
+
end
|
9
|
+
|
10
|
+
def post_request(path, params = {}, headers = {})
|
11
|
+
json = JSON.generate(params)
|
12
|
+
uri = URI("http://#{@bravia_address}#{path}")
|
13
|
+
|
14
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
15
|
+
return http.post(path, json, headers)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'easy_upnp/ssdp_searcher'
|
2
|
+
|
3
|
+
require_relative 'authenticator'
|
4
|
+
require_relative 'client'
|
5
|
+
|
6
|
+
module Bravtroller
|
7
|
+
class Remote
|
8
|
+
IRCC_URN = 'urn:schemas-sony-com:service:IRCC:1'
|
9
|
+
|
10
|
+
LIST_METHODS_PARAMS = {
|
11
|
+
method: 'getRemoteControllerInfo',
|
12
|
+
params: [],
|
13
|
+
id: 10,
|
14
|
+
version: '1.0'
|
15
|
+
}
|
16
|
+
|
17
|
+
def self.create(bravia_client)
|
18
|
+
searcher = EasyUpnp::SsdpSearcher.new
|
19
|
+
results = searcher.search(IRCC_URN)
|
20
|
+
authenticator = Bravtroller::Authenticator.new(bravia_client)
|
21
|
+
|
22
|
+
if ! authenticator.authorized?
|
23
|
+
raise RuntimeError.new 'Not authorized yet. Please authorize Bravtroller using Bravtroller::Authenticator.'
|
24
|
+
end
|
25
|
+
|
26
|
+
if results.empty?
|
27
|
+
raise RuntimeError.new "Couldn't find any UPnP devices on the network that looks like a supported Sony device"
|
28
|
+
elsif results.count != 1
|
29
|
+
raise RuntimeError.new "Found more than one supported Sony device. Please construct Remote manually. Found devices: #{results.inspect}"
|
30
|
+
else
|
31
|
+
device = results.first
|
32
|
+
ircc_client = device.service(IRCC_URN, cookies: HTTPI::Cookie.new(authenticator.authorize {}))
|
33
|
+
|
34
|
+
Remote.new(ircc_client, bravia_client)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(ircc_client, bravia_client)
|
39
|
+
@ircc_client = ircc_client
|
40
|
+
@bravia_client = bravia_client
|
41
|
+
end
|
42
|
+
|
43
|
+
def press_button(button_key)
|
44
|
+
raise RuntimeError.new "Undefined buton: #{button_key}" if ircc_codes[button_key].nil?
|
45
|
+
|
46
|
+
@ircc_client.X_SendIRCC IRCCCode: ircc_codes[button_key]
|
47
|
+
end
|
48
|
+
|
49
|
+
def buttons
|
50
|
+
ircc_codes.keys
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def ircc_codes
|
56
|
+
return @ircc_codes unless @ircc_codes.nil?
|
57
|
+
|
58
|
+
response = JSON.parse(@bravia_client.post_request('/sony/system', LIST_METHODS_PARAMS).body)
|
59
|
+
|
60
|
+
action_code_pairs = response['result'][1].map do |action|
|
61
|
+
[ action['name'], action['value'] ]
|
62
|
+
end
|
63
|
+
|
64
|
+
Hash[ action_code_pairs ]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/bravtroller.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bravtroller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Mullins
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: easy_upnp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email: chris@sidoh.org
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- LICENSE
|
65
|
+
- Rakefile
|
66
|
+
- bravtroller.gemspec
|
67
|
+
- lib/bravtroller.rb
|
68
|
+
- lib/bravtroller/authenticator.rb
|
69
|
+
- lib/bravtroller/client.rb
|
70
|
+
- lib/bravtroller/remote.rb
|
71
|
+
- lib/bravtroller/version.rb
|
72
|
+
homepage: http://github.com/sidoh/bravtroller
|
73
|
+
licenses: []
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.0.14
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Controller for the Bravia KDL-50W700B
|
95
|
+
test_files: []
|