vayacondios-client 0.2.2 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ require 'gorillib/logger/log'
2
2
  require 'net/http'
3
3
  require 'multi_json'
4
4
  require_relative 'config'
5
- require_relative '../legacy_switch'
5
+ require_relative 'legacy_switch'
6
6
 
7
7
  class Vayacondios
8
8
  class Client
@@ -0,0 +1,46 @@
1
+ require 'gorillib/logger/log'
2
+
3
+ class Vayacondios
4
+ # Are we operating on JSON Hashes (Vayacondios) or on JSON arrays
5
+ # (Vayacondios Legacy)? These classes determine which to use.
6
+
7
+ class StandardContentsHandler
8
+ def wrap_contents(contents) {contents: contents} end
9
+ def extract_contents(document) document['contents'] end
10
+ def extract_response(document) document['contents'] end
11
+ def proper_request(document)
12
+ document.is_a? Hash and document.fetch('_json', {}).is_a? Hash
13
+ end
14
+ end
15
+
16
+ class LegacyContentsHandler
17
+ def wrap_contents(contents) contents end
18
+ def extract_contents(document) document.fetch('_json', {}) end
19
+ def extract_response(document) document end
20
+ def proper_request(document)
21
+ document.is_a? Array or document.fetch('_json', {}).is_a? Array
22
+ end
23
+ end
24
+
25
+ @@legacy_switch = nil
26
+
27
+ def self.legacy_switch
28
+ legacy_mode_on = Settings[:vayacondios][:legacy]
29
+ if @@legacy_switch.nil?
30
+ @@legacy_switch = get_legacy_switch(legacy_mode_on)
31
+ Log.info("using #{legacy_mode_on ? 'legacy' : 'standard'} mode")
32
+ end
33
+ @@legacy_switch
34
+ end
35
+
36
+ def self.force_legacy_mode on
37
+ @@legacy_switch = get_legacy_switch on
38
+ end
39
+
40
+ private
41
+
42
+ def self.get_legacy_switch on
43
+ (on ? LegacyContentsHandler : StandardContentsHandler).new
44
+ end
45
+ end
46
+
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- require_relative '../../lib/vayacondios/legacy_switch'
2
+ require_relative '../../lib/vayacondios/server/legacy_switch'
3
3
 
4
4
  require 'multi_json'
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vayacondios-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -123,6 +123,7 @@ files:
123
123
  - lib/vayacondios/client/cube_client.rb
124
124
  - lib/vayacondios/client/http_client.rb
125
125
  - lib/vayacondios/client/itemset.rb
126
+ - lib/vayacondios/client/legacy_switch.rb
126
127
  - lib/vayacondios/client/notifier.rb
127
128
  - lib/vayacondios/client/zabbix_client.rb
128
129
  - spec/client/itemset_legacy_spec.rb
@@ -142,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
143
  version: '0'
143
144
  segments:
144
145
  - 0
145
- hash: -3011077076674901928
146
+ hash: -2113396052931375054
146
147
  required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  none: false
148
149
  requirements:
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  version: '0'
152
153
  segments:
153
154
  - 0
154
- hash: -3011077076674901928
155
+ hash: -2113396052931375054
155
156
  requirements: []
156
157
  rubyforge_project:
157
158
  rubygems_version: 1.8.25