mind_meld 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mind_meld +28 -0
- data/lib/mind_meld/device.rb +50 -0
- data/lib/mind_meld/hive.rb +2 -2
- data/lib/mind_meld/tv.rb +18 -0
- data/lib/mind_meld.rb +8 -41
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7b9ee29cd21ea6c2e0ff1b017839b960b1d9af8
|
4
|
+
data.tar.gz: c82d8435c583863afd8a3f8b90235f77c928e82a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 999d3e342c8b79f74993fc1ad308781ae780fddd8d1fab752ac59fc5f7280ac4e92027b5b6b79bd718b7afef2143bd5c5dae2a4331bcbb525133a76e2212a58f
|
7
|
+
data.tar.gz: ced83fc98284262ee4c24f03302d2754246046a97b8ba11f1575ea390688adeb7e4188c02f85388ef1067a60e54cd38a93ef72b8b3046900f3c817bd7b132f82
|
data/bin/mind_meld
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path(
|
5
|
+
'../../Gemfile',
|
6
|
+
Pathname.new(__FILE__).realpath
|
7
|
+
)
|
8
|
+
|
9
|
+
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
10
|
+
require 'mind_meld'
|
11
|
+
|
12
|
+
url = ENV['HIVEMIND_URL'] || 'http://localhost:3000'
|
13
|
+
pem = ENV['HIVEMIND_PEM'] || nil
|
14
|
+
ca_file = ENV['HIVEMIND_CAFILE'] || nil
|
15
|
+
verify_mode = ENV['HIVEMIND_VERIFY_MODE'] || nil
|
16
|
+
|
17
|
+
mm = MindMeld.new(
|
18
|
+
url: url,
|
19
|
+
pem: pem,
|
20
|
+
ca_file: ca_file,
|
21
|
+
verify_mode: verify_mode
|
22
|
+
)
|
23
|
+
|
24
|
+
devs = mm.devices
|
25
|
+
|
26
|
+
devs.each do |dev|
|
27
|
+
puts "#{dev['id']}) #{dev['name']}"
|
28
|
+
end
|
data/lib/mind_meld/device.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require 'active_support/core_ext/object/to_query'
|
4
|
+
require 'mind_meld'
|
5
|
+
|
6
|
+
class MindMeld::Device < MindMeld
|
7
|
+
def initialize options
|
8
|
+
super
|
9
|
+
|
10
|
+
@device = options[:device]
|
11
|
+
# To trigger registration (is this needed?)
|
12
|
+
device_details
|
13
|
+
end
|
14
|
+
|
15
|
+
def id
|
16
|
+
device_details['id']
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
device_details['name']
|
21
|
+
end
|
22
|
+
|
23
|
+
def register options
|
24
|
+
request :post, 'devices/register', { device: options }
|
25
|
+
end
|
26
|
+
|
27
|
+
def poll *dev_ids
|
28
|
+
args = {
|
29
|
+
poll: dev_ids.length > 0 ? { id: self.id, devices: dev_ids } : { id: self.id }
|
30
|
+
}
|
31
|
+
response = request :put, 'devices/poll', args
|
32
|
+
if dev_ids.length == 0
|
33
|
+
@device_details = response
|
34
|
+
end
|
35
|
+
response
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_action options
|
39
|
+
response = request :put, 'devices/action', { device_action: { device_id: self.id }.merge(options) }
|
40
|
+
response
|
41
|
+
end
|
42
|
+
|
43
|
+
def device_details(refresh = false)
|
44
|
+
if refresh or not @device_details or @device_details.has_key? :error
|
45
|
+
@device_details = register(@device)
|
46
|
+
else
|
47
|
+
@device_details
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/mind_meld/hive.rb
CHANGED
data/lib/mind_meld/tv.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mind_meld/device'
|
2
|
+
|
3
|
+
class MindMeld::Tv < MindMeld::Device
|
4
|
+
def initialize options
|
5
|
+
options[:device][:device_type] ||= 'Tv'
|
6
|
+
super options
|
7
|
+
end
|
8
|
+
|
9
|
+
def set_application application
|
10
|
+
request :put, 'plugin/tv/set_application',
|
11
|
+
{
|
12
|
+
device: {
|
13
|
+
id: device_details['id'],
|
14
|
+
application: application
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
data/lib/mind_meld.rb
CHANGED
@@ -7,7 +7,7 @@ class MindMeld
|
|
7
7
|
if options[:url]
|
8
8
|
uri = URI.parse(options[:url])
|
9
9
|
@http = Net::HTTP.new(uri.host, uri.port)
|
10
|
-
if options.key?(:pem)
|
10
|
+
if options.key?(:pem) and options[:pem]
|
11
11
|
pem = File.read(options[:pem])
|
12
12
|
@http.use_ssl = true if uri.scheme == 'https'
|
13
13
|
@http.cert = OpenSSL::X509::Certificate.new(pem)
|
@@ -15,55 +15,22 @@ class MindMeld
|
|
15
15
|
@http.ca_file = options[:ca_file] if options.key?(:ca_file)
|
16
16
|
@http.verify_mode = options[:verify_mode] if options.key?(:verify_mode)
|
17
17
|
end
|
18
|
-
|
19
|
-
@device = options[:device]
|
20
|
-
|
21
|
-
# To trigger registration (is this needed?)
|
22
|
-
device_details
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def name
|
31
|
-
device_details['name']
|
32
|
-
end
|
33
|
-
|
34
|
-
def register options
|
35
|
-
request :post, 'devices/register', { device: options }
|
36
|
-
end
|
37
|
-
|
38
|
-
def poll *dev_ids
|
39
|
-
args = {
|
40
|
-
poll: dev_ids.length > 0 ? { id: self.id, devices: dev_ids } : { id: self.id }
|
41
|
-
}
|
42
|
-
response = request :put, 'devices/poll', args
|
43
|
-
if dev_ids.length == 0
|
44
|
-
@device_details = response
|
45
|
-
end
|
46
|
-
response
|
47
|
-
end
|
48
|
-
|
49
|
-
def create_action options
|
50
|
-
response = request :put, 'devices/action', { device_action: { device_id: self.id }.merge(options) }
|
51
|
-
response
|
52
|
-
end
|
53
|
-
|
54
|
-
def device_details(refresh = false)
|
55
|
-
if refresh or not @device_details or @device_details.has_key? :error
|
56
|
-
@device_details = register(@device)
|
57
|
-
else
|
58
|
-
@device_details
|
59
|
-
end
|
21
|
+
def devices
|
22
|
+
request :get, 'devices'
|
60
23
|
end
|
61
24
|
|
62
25
|
private
|
63
26
|
def request type, call, params = {}
|
64
27
|
if @http
|
65
28
|
begin
|
66
|
-
JSON.parse(@http.send(
|
29
|
+
JSON.parse(@http.send(
|
30
|
+
"request_#{type}",
|
31
|
+
"/api/#{call}.json",
|
32
|
+
type == :get ? params : params.to_query
|
33
|
+
).body)
|
67
34
|
rescue => e
|
68
35
|
{ error: e.message }
|
69
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mind_meld
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Haig
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -55,14 +55,17 @@ dependencies:
|
|
55
55
|
description: API for Hive Mind
|
56
56
|
email:
|
57
57
|
- joe.haig@bbc.co.uk
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- mind_meld
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
62
63
|
- README.md
|
64
|
+
- bin/mind_meld
|
63
65
|
- lib/mind_meld.rb
|
64
66
|
- lib/mind_meld/device.rb
|
65
67
|
- lib/mind_meld/hive.rb
|
68
|
+
- lib/mind_meld/tv.rb
|
66
69
|
homepage: https://github.org/bbc/mind_meld
|
67
70
|
licenses:
|
68
71
|
- MIT
|