devicedb_comms 0.1.0
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/MIT-LICENSE +20 -0
- data/lib/devicedb_comms.rb +26 -0
- data/lib/devicedb_comms/configuration.rb +11 -0
- data/lib/devicedb_comms/device.rb +71 -0
- data/lib/devicedb_comms/hive.rb +19 -0
- data/lib/devicedb_comms/queue.rb +18 -0
- data/lib/devicedb_comms/shared.rb +76 -0
- data/lib/devicedb_comms/version.rb +3 -0
- data/lib/tasks/devicedb_comms_tasks.rake +4 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae8dde10e410d3e9f6fde02046869a42ecf33c89
|
4
|
+
data.tar.gz: 94e0e1c23a353f949756c627c5a232f6ca7081c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51c3fc592c37081e0b7d65ad40417dff195c2f2b170f4ebfd7f625367c292f10bb05290b0e3f2fb6ab8b602bcdfa81ba53eef0ae179768857c615dd97b6a3462
|
7
|
+
data.tar.gz: 8995c8b8387cc8fe60981bbfd7ad3fcf7242aba9ab283f399937711440faa000b7e78726dcbb850188adf3ba1df95143554329651cdbfbdb0d6d5d478eaebb14
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
require 'devicedb_comms/queue'
|
4
|
+
require 'devicedb_comms/device'
|
5
|
+
require 'devicedb_comms/hive'
|
6
|
+
require 'devicedb_comms/configuration'
|
7
|
+
|
8
|
+
module DeviceDBComms
|
9
|
+
class << self
|
10
|
+
# TODO Add this accessor when the configuration method is removed
|
11
|
+
#attr_accessor :configuration
|
12
|
+
|
13
|
+
def configure
|
14
|
+
# TODO Possibly change to this when configuration method removed
|
15
|
+
#self.configuration = Configuration.new
|
16
|
+
@configuration = Configuration.new
|
17
|
+
yield(configuration)
|
18
|
+
end
|
19
|
+
|
20
|
+
# For backward compatibility
|
21
|
+
# TODO Remove this as the configure method must be called
|
22
|
+
def configuration
|
23
|
+
@configuration ||= Configuration.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module DeviceDBComms
|
2
|
+
class Configuration
|
3
|
+
include Virtus.model
|
4
|
+
|
5
|
+
attribute :url, String
|
6
|
+
attribute :pem_file, String
|
7
|
+
# Backward compatibility with version <= 0.0.14
|
8
|
+
# TODO Change default to VERIFY_PEER
|
9
|
+
attribute :ssl_verify_mode, Integer, default: OpenSSL::SSL::VERIFY_NONE
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'devicedb_comms/shared'
|
2
|
+
|
3
|
+
module DeviceDBComms
|
4
|
+
class Device < DeviceDBComms::Shared
|
5
|
+
|
6
|
+
# Backward compatibility with version <= 0.0.14
|
7
|
+
# TODO Remove arguments
|
8
|
+
def initialize(url = nil, pem_path = nil)
|
9
|
+
@applications = {}
|
10
|
+
super(url, pem_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(device_id)
|
14
|
+
get("/devices/#{device_id}")
|
15
|
+
end
|
16
|
+
|
17
|
+
def register(device_params)
|
18
|
+
post("/devices/register", device_params)
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit(device_id, device_params)
|
22
|
+
put("/devices/#{device_id}", device: device_params)
|
23
|
+
end
|
24
|
+
|
25
|
+
def poll(device_id, status=nil)
|
26
|
+
params = {}
|
27
|
+
if @applications[device_id]
|
28
|
+
params['application'] = @applications[device_id]
|
29
|
+
end
|
30
|
+
post("/devices/#{device_id}/poll" + ( "/#{status}" unless status.nil? ).to_s, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_application(device_id, name=nil)
|
34
|
+
@applications[device_id] = name
|
35
|
+
poll(device_id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def clear_application(device_id)
|
39
|
+
set_application(device_id, nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_application(device_id)
|
43
|
+
get("/devices/#{device_id}/application")['application']
|
44
|
+
end
|
45
|
+
|
46
|
+
def hive_connect(device_id, hive_id)
|
47
|
+
post("/hives/#{hive_id}/devices/#{device_id}/connect")
|
48
|
+
end
|
49
|
+
|
50
|
+
def hive_disconnect(device_id)
|
51
|
+
put("/hives/devices/#{device_id}/disconnect")
|
52
|
+
end
|
53
|
+
|
54
|
+
def action(device_id, type, body, tries = 1)
|
55
|
+
rtn = { 'error' => 'No tries' }
|
56
|
+
n = 0
|
57
|
+
while n < tries && rtn.has_key?('error')
|
58
|
+
rtn = post("/devices/#{device_id}/new_action", { action_type: type, action_body: body })
|
59
|
+
n += 1
|
60
|
+
end
|
61
|
+
rtn
|
62
|
+
end
|
63
|
+
|
64
|
+
def find_disconnected_by_type(type)
|
65
|
+
{
|
66
|
+
'devices' => []
|
67
|
+
}.merge(post("/devices/search", { device_type: type, hive_id: -1, status: 'idle' }))
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'devicedb_comms/shared'
|
2
|
+
|
3
|
+
module DeviceDBComms
|
4
|
+
class Hive < DeviceDBComms::Shared
|
5
|
+
|
6
|
+
def find(hive_id)
|
7
|
+
get("/hives/#{hive_id}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def register(hive_name, mac_address, ip_address)
|
11
|
+
post("/hives/register", { hive: { hostname: hive_name, mac: mac_address, ip_address: ip_address }})
|
12
|
+
end
|
13
|
+
|
14
|
+
def poll(hive_id)
|
15
|
+
post("/hives/#{hive_id}/poll")
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'devicedb_comms/shared'
|
2
|
+
|
3
|
+
module DeviceDBComms
|
4
|
+
class Queue < DeviceDBComms::Shared
|
5
|
+
|
6
|
+
def find_by_name(name)
|
7
|
+
get("/queues/by_name/#{name.gsub(/\./, '%2E' )}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(id)
|
11
|
+
get("/queues/#{id}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def register(queue_params)
|
15
|
+
post("/queues", queue_params)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'active_support/core_ext/object/to_query'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
module DeviceDBComms
|
6
|
+
class Shared
|
7
|
+
|
8
|
+
# Backward compatibility with version <= 0.0.14
|
9
|
+
# TODO Remove arguments
|
10
|
+
def initialize(url = nil, pem_path = nil)
|
11
|
+
url ||= DeviceDBComms.configuration.url
|
12
|
+
pem_path ||= DeviceDBComms.configuration.pem_file
|
13
|
+
|
14
|
+
if url
|
15
|
+
uri = URI.parse(url)
|
16
|
+
|
17
|
+
@http = Net::HTTP.new(uri.host, uri.port)
|
18
|
+
|
19
|
+
if pem_path
|
20
|
+
pem = File.read(pem_path)
|
21
|
+
@http.use_ssl = true if uri.scheme == 'https'
|
22
|
+
@http.cert = OpenSSL::X509::Certificate.new(pem)
|
23
|
+
@http.key = OpenSSL::PKey::RSA.new(pem)
|
24
|
+
@http.verify_mode = DeviceDBComms.configuration.ssl_verify_mode
|
25
|
+
end
|
26
|
+
else
|
27
|
+
@http = nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(call)
|
32
|
+
if @http
|
33
|
+
begin
|
34
|
+
parse_response @http.request_get(call + '.json')
|
35
|
+
rescue StandardError => e
|
36
|
+
{ 'error' => "GET failed: #{e.message}" }
|
37
|
+
end
|
38
|
+
else
|
39
|
+
{ 'error' => "No DeviceDB connection" }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def post(call, params={})
|
44
|
+
if @http
|
45
|
+
begin
|
46
|
+
parse_response @http.request_post(call + '.json', to_query(params))
|
47
|
+
rescue StandardError => e
|
48
|
+
{ 'error' => "POST failed: #{e.message}" }
|
49
|
+
end
|
50
|
+
else
|
51
|
+
{ 'error' => "No DeviceDB connection" }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def put(call, params={})
|
56
|
+
if @http
|
57
|
+
begin
|
58
|
+
parse_response @http.request_put(call + '.json', to_query(params))
|
59
|
+
rescue StandardError => e
|
60
|
+
{ 'error' => "PUT failed: #{e.message}" }
|
61
|
+
end
|
62
|
+
else
|
63
|
+
{ 'error' => "No DeviceDB connection" }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_response(response)
|
68
|
+
JSON.parse(response.body)
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_query(params_hash)
|
72
|
+
params_hash.to_query
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devicedb_comms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joe Haig
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.20'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.20'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
83
|
+
description: Communication helper gem for talking to Device Database
|
84
|
+
email:
|
85
|
+
- joe.haig@bbc.co.uk
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- MIT-LICENSE
|
91
|
+
- lib/devicedb_comms.rb
|
92
|
+
- lib/devicedb_comms/configuration.rb
|
93
|
+
- lib/devicedb_comms/device.rb
|
94
|
+
- lib/devicedb_comms/hive.rb
|
95
|
+
- lib/devicedb_comms/queue.rb
|
96
|
+
- lib/devicedb_comms/shared.rb
|
97
|
+
- lib/devicedb_comms/version.rb
|
98
|
+
- lib/tasks/devicedb_comms_tasks.rake
|
99
|
+
homepage: https://github.com/bbc/devicedb_comms
|
100
|
+
licenses: []
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.4.8
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: DeviceDB Comms Gem
|
122
|
+
test_files: []
|