vayacondios-client 0.2.1 → 0.2.2
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.
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'gorillib/logger/log'
|
2
2
|
require 'net/http'
|
3
3
|
require 'multi_json'
|
4
|
+
require_relative 'config'
|
5
|
+
require_relative '../legacy_switch'
|
4
6
|
|
5
7
|
class Vayacondios
|
6
8
|
class Client
|
@@ -15,7 +17,7 @@ class Vayacondios
|
|
15
17
|
|
16
18
|
def fetch organization=nil, topic=nil, id=nil
|
17
19
|
resp = execute_request(_req(:fetch, nil, organization, topic, id)) and
|
18
|
-
resp
|
20
|
+
Vayacondios.legacy_switch.extract_response(resp)
|
19
21
|
end
|
20
22
|
|
21
23
|
def update ary, organization=nil, topic=nil, id=nil
|
@@ -70,7 +72,10 @@ class Vayacondios
|
|
70
72
|
when :remove then Net::HTTP::Delete
|
71
73
|
else raise ArgumentError.new("invalid type: #{type}")
|
72
74
|
end.new(the_path, headers).tap do |req|
|
73
|
-
|
75
|
+
unless type == :fetch
|
76
|
+
req.body =
|
77
|
+
MultiJson.encode(Vayacondios.legacy_switch.wrap_contents(ary))
|
78
|
+
end
|
74
79
|
end
|
75
80
|
end
|
76
81
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../../lib/vayacondios/legacy_switch'
|
3
|
+
|
4
|
+
require 'multi_json'
|
5
|
+
|
6
|
+
require_relative '../../lib/vayacondios/client/itemset'
|
7
|
+
|
8
|
+
describe Vayacondios::Client::ItemSet do
|
9
|
+
context "after instantiation in legacy mode" do
|
10
|
+
itemset = Vayacondios::Client::ItemSet.new("foohost", 9999, "fooorg", "footopic", "fooid")
|
11
|
+
ary = ["foo", "bar", "baz"]
|
12
|
+
|
13
|
+
# testing internals here to avoid shimming up HTTP libraries.
|
14
|
+
|
15
|
+
it "generates a put request without a patch header when asked to create" do
|
16
|
+
Vayacondios.force_legacy_mode true
|
17
|
+
|
18
|
+
req = itemset.instance_eval{_req(:create, ary)}
|
19
|
+
|
20
|
+
req.method.should eql('PUT')
|
21
|
+
req.body.should eql(MultiJson.encode(ary))
|
22
|
+
req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
|
23
|
+
req.each_header.to_a.should_not include(["x_method", "PATCH"])
|
24
|
+
end
|
25
|
+
|
26
|
+
it "generates a put request with a patch header when asked to update" do
|
27
|
+
Vayacondios.force_legacy_mode true
|
28
|
+
|
29
|
+
req = itemset.instance_eval{_req(:update, ary)}
|
30
|
+
|
31
|
+
req.method.should eql('PUT')
|
32
|
+
req.body.should eql(MultiJson.encode(ary))
|
33
|
+
req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
|
34
|
+
req.each_header.to_a.should include(["x-method", "PATCH"])
|
35
|
+
end
|
36
|
+
|
37
|
+
it "generates a get request when asked to fetch" do
|
38
|
+
req = itemset.instance_eval{_req(:fetch)}
|
39
|
+
|
40
|
+
req.method.should eql('GET')
|
41
|
+
req.body.should be_nil
|
42
|
+
req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "generates a delete request when asked to remove" do
|
46
|
+
Vayacondios.force_legacy_mode true
|
47
|
+
|
48
|
+
req = itemset.instance_eval{_req(:remove, ary)}
|
49
|
+
|
50
|
+
req.method.should eql('DELETE')
|
51
|
+
req.body.should eql(MultiJson.encode(ary))
|
52
|
+
req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/client/itemset_spec.rb
CHANGED
@@ -12,13 +12,14 @@ describe Vayacondios::Client::ItemSet do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
context "after instantiation" do
|
15
|
-
|
16
15
|
itemset = Vayacondios::Client::ItemSet.new("foohost", 9999, "fooorg", "footopic", "fooid")
|
17
16
|
ary = ["foo", "bar", "baz"]
|
18
17
|
|
19
18
|
# testing internals here to avoid shimming up HTTP libraries.
|
20
19
|
|
21
20
|
it "generates a put request without a patch header when asked to create" do
|
21
|
+
Vayacondios.force_legacy_mode false
|
22
|
+
|
22
23
|
req = itemset.instance_eval{_req(:create, ary)}
|
23
24
|
|
24
25
|
req.method.should eql('PUT')
|
@@ -28,6 +29,8 @@ describe Vayacondios::Client::ItemSet do
|
|
28
29
|
end
|
29
30
|
|
30
31
|
it "generates a put request with a patch header when asked to update" do
|
32
|
+
Vayacondios.force_legacy_mode false
|
33
|
+
|
31
34
|
req = itemset.instance_eval{_req(:update, ary)}
|
32
35
|
|
33
36
|
req.method.should eql('PUT')
|
@@ -45,6 +48,8 @@ describe Vayacondios::Client::ItemSet do
|
|
45
48
|
end
|
46
49
|
|
47
50
|
it "generates a delete request when asked to remove" do
|
51
|
+
Vayacondios.force_legacy_mode false
|
52
|
+
|
48
53
|
req = itemset.instance_eval{_req(:remove, ary)}
|
49
54
|
|
50
55
|
req.method.should eql('DELETE')
|
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.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -118,12 +118,14 @@ extensions: []
|
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
120
|
- lib/vayacondios-client.rb
|
121
|
+
- lib/vayacondios/client/config.rb
|
121
122
|
- lib/vayacondios/client/configliere.rb
|
122
123
|
- lib/vayacondios/client/cube_client.rb
|
123
124
|
- lib/vayacondios/client/http_client.rb
|
124
125
|
- lib/vayacondios/client/itemset.rb
|
125
126
|
- lib/vayacondios/client/notifier.rb
|
126
127
|
- lib/vayacondios/client/zabbix_client.rb
|
128
|
+
- spec/client/itemset_legacy_spec.rb
|
127
129
|
- spec/client/itemset_spec.rb
|
128
130
|
- spec/client/notifier_spec.rb
|
129
131
|
homepage: https://github.com/infochimps-labs/vayacondios
|
@@ -140,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
140
142
|
version: '0'
|
141
143
|
segments:
|
142
144
|
- 0
|
143
|
-
hash: -
|
145
|
+
hash: -3011077076674901928
|
144
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
147
|
none: false
|
146
148
|
requirements:
|
@@ -149,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
151
|
version: '0'
|
150
152
|
segments:
|
151
153
|
- 0
|
152
|
-
hash: -
|
154
|
+
hash: -3011077076674901928
|
153
155
|
requirements: []
|
154
156
|
rubyforge_project:
|
155
157
|
rubygems_version: 1.8.25
|
@@ -157,6 +159,7 @@ signing_key:
|
|
157
159
|
specification_version: 3
|
158
160
|
summary: Data goes in. The right thing happens
|
159
161
|
test_files:
|
162
|
+
- spec/client/itemset_legacy_spec.rb
|
160
163
|
- spec/client/itemset_spec.rb
|
161
164
|
- spec/client/notifier_spec.rb
|
162
165
|
has_rdoc:
|