Class: MindMeld
- Inherits:
-
Object
show all
- Defined in:
- lib/mind_meld.rb
Direct Known Subclasses
Device
Defined Under Namespace
Classes: Device, Hive, Tv
Instance Method Summary
collapse
Constructor Details
#initialize(options) ⇒ MindMeld
Returns a new instance of MindMeld.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/mind_meld.rb', line 8
def initialize options
if options[:url]
uri = URI.parse(options[:url])
@http = Net::HTTP.new(uri.host, uri.port)
if options.key?(:cert) and options[:cert]
type = options[:cert].split('/').last.split('.').last == "p12" ? "p12" : "pem"
if type == "pem"
pem = File.read(options[:cert])
@http.cert = OpenSSL::X509::Certificate.new(pem)
@http.key = OpenSSL::PKey::RSA.new(pem)
elsif type == "p12"
p12 = OpenSSL::PKCS12.new(File.binread(options[:cert]))
@http.cert = p12.certificate
@http.key = p12.key
end
@http.use_ssl = true if uri.scheme == 'https'
@http.ca_file = options[:ca_file] if options.key?(:ca_file)
@http.verify_mode = options[:verify_mode] if options.key?(:verify_mode)
elsif options.key?(:pem) and options[:pem]
warn "['DEPRECATION'] Key [:pem] is deprecated in Mind Meld. Use [:cert] instead."
pem = File.read(options[:pem])
@http.cert = OpenSSL::X509::Certificate.new(pem)
@http.key = OpenSSL::PKey::RSA.new(pem)
@http.use_ssl = true if uri.scheme == 'https'
@http.ca_file = options[:ca_file] if options.key?(:ca_file)
@http.verify_mode = options[:verify_mode] if options.key?(:verify_mode)
end
end
@statistics = []
end
|
Instance Method Details
#add_statistics(data) ⇒ Object
45
46
47
48
49
50
|
# File 'lib/mind_meld.rb', line 45
def add_statistics data
data = [ data ] if ! data.is_a? Array
verify_statistics_arguments data
@statistics.concat data
end
|
#devices ⇒ Object
41
42
43
|
# File 'lib/mind_meld.rb', line 41
def devices
request :get, 'devices'
end
|
#flush_statistics ⇒ Object
52
53
54
55
56
|
# File 'lib/mind_meld.rb', line 52
def flush_statistics
response = request :post, 'device_statistics/upload', { data: @statistics }
@statistics = [] if ! response.has_key? :error
response
end
|