vayacondios-server 0.0.9 → 0.0.10
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.
data/app/http_shim.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
class Vayacondios
|
5
|
+
class Client
|
6
|
+
class ItemSet
|
7
|
+
def initialize host, port, organization, topic, id
|
8
|
+
@host = host
|
9
|
+
@port = port
|
10
|
+
|
11
|
+
@path = "/v1/#{organization}/itemset/#{topic}/#{id}"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Exposed for testing.
|
15
|
+
def _req type, ary = nil
|
16
|
+
case type
|
17
|
+
when :fetch then
|
18
|
+
req = Net::HTTP::Get.new(@path)
|
19
|
+
when :create then
|
20
|
+
(req = Net::HTTP::Put.new(@path)).body = MultiJson.encode(ary)
|
21
|
+
when :update then
|
22
|
+
(req = Net::HTTP::Put.new(@path, [["http_x_method", "PATCH"]])).body = MultiJson.encode(ary)
|
23
|
+
when :remove then
|
24
|
+
(req = Net::HTTP::Delete.new(@path)).body = MultiJson.encode(ary)
|
25
|
+
end
|
26
|
+
req
|
27
|
+
end
|
28
|
+
|
29
|
+
def fetch
|
30
|
+
execute_request(_req(:fetch))
|
31
|
+
end
|
32
|
+
|
33
|
+
def update ary
|
34
|
+
execute_request(_req(:update, ary))
|
35
|
+
end
|
36
|
+
|
37
|
+
def create ary
|
38
|
+
execute_request(_req(:create, ary))
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove ary
|
42
|
+
execute_request(_req(:remove, ary))
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def execute_request req
|
49
|
+
resp = Net::HTTP.start(@host, @port) do |http|
|
50
|
+
http.request(req)
|
51
|
+
end.body
|
52
|
+
result = MultiJson.decode(resp) unless resp.nil? or resp.empty?
|
53
|
+
(result.respond_to?(:has_key?) and result.has_key? "error") ? nil : result
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -46,6 +46,10 @@ class Vayacondios::ItemsetDocument < Vayacondios::Document
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def update(document)
|
49
|
+
if !document.is_a?(Array)
|
50
|
+
puts "not an array: #{document}"
|
51
|
+
end
|
52
|
+
|
49
53
|
raise Vayacondios::Error::BadRequest.new if !document.is_a?(Array)
|
50
54
|
|
51
55
|
@body = document
|
data/lib/vayacondios/version.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
require_relative '../../lib/vayacondios/client/itemset'
|
6
|
+
|
7
|
+
describe Vayacondios::Client::ItemSet do
|
8
|
+
context "when initialized" do
|
9
|
+
it "can be passed a host, port, organization, topic and id" do
|
10
|
+
Vayacondios::Client::ItemSet.new("foohost", 9999, "fooorg", "footopic", "fooid")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "after instantiation" do
|
15
|
+
|
16
|
+
itemset = Vayacondios::Client::ItemSet.new("foohost", 9999, "fooorg", "footopic", "fooid")
|
17
|
+
ary = ["foo", "bar", "baz"]
|
18
|
+
|
19
|
+
# Actually testing internals here to avoid
|
20
|
+
|
21
|
+
it "generates a put request without a patch header when asked to create" do
|
22
|
+
req = itemset._req :create, ary
|
23
|
+
|
24
|
+
req.method.should eql('PUT')
|
25
|
+
req.body.should eql(ary.to_json)
|
26
|
+
req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
|
27
|
+
req.each_header.to_a.should_not include(["http_x_method", "PATCH"])
|
28
|
+
end
|
29
|
+
|
30
|
+
it "generates a put request with a patch header when asked to update" do
|
31
|
+
req = itemset._req :update, ary
|
32
|
+
|
33
|
+
req.method.should eql('PUT')
|
34
|
+
req.body.should eql(ary.to_json)
|
35
|
+
req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
|
36
|
+
req.each_header.to_a.should include(["http_x_method", "PATCH"])
|
37
|
+
end
|
38
|
+
|
39
|
+
it "generates a get request when asked to fetch" do
|
40
|
+
req = itemset._req :fetch
|
41
|
+
|
42
|
+
req.method.should eql('GET')
|
43
|
+
req.body.should be_nil
|
44
|
+
req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
|
45
|
+
end
|
46
|
+
|
47
|
+
it "generates a delete request when asked to remove" do
|
48
|
+
req = itemset._req :remove, ary
|
49
|
+
|
50
|
+
req.method.should eql('DELETE')
|
51
|
+
req.body.should eql(ary.to_json)
|
52
|
+
req.path.should eql('/v1/fooorg/itemset/footopic/fooid')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vayacondios-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2012-09-
|
15
|
+
date: 2012-09-10 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: configliere
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- lib/vayacondios-server.rb
|
204
204
|
- lib/vayacondios/client/configliere.rb
|
205
205
|
- lib/vayacondios/client/http_client.rb
|
206
|
+
- lib/vayacondios/client/itemset.rb
|
206
207
|
- lib/vayacondios/client/notifier.rb
|
207
208
|
- lib/vayacondios/server/errors/bad_request.rb
|
208
209
|
- lib/vayacondios/server/errors/not_found.rb
|
@@ -222,6 +223,7 @@ files:
|
|
222
223
|
- scripts/s3_cataloger/buckets
|
223
224
|
- scripts/s3_cataloger/foreach_bucket
|
224
225
|
- scripts/s3_cataloger/parse_ls.py
|
226
|
+
- spec/client/itemset_spec.rb
|
225
227
|
- spec/client/notifier_spec.rb
|
226
228
|
- spec/server/config_spec.rb
|
227
229
|
- spec/server/event_spec.rb
|
@@ -245,7 +247,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
245
247
|
version: '0'
|
246
248
|
segments:
|
247
249
|
- 0
|
248
|
-
hash:
|
250
|
+
hash: -1252919032941517735
|
249
251
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
250
252
|
none: false
|
251
253
|
requirements:
|
@@ -254,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
256
|
version: '0'
|
255
257
|
segments:
|
256
258
|
- 0
|
257
|
-
hash:
|
259
|
+
hash: -1252919032941517735
|
258
260
|
requirements: []
|
259
261
|
rubyforge_project:
|
260
262
|
rubygems_version: 1.8.23
|
@@ -262,6 +264,7 @@ signing_key:
|
|
262
264
|
specification_version: 3
|
263
265
|
summary: Data goes in. The right thing happens
|
264
266
|
test_files:
|
267
|
+
- spec/client/itemset_spec.rb
|
265
268
|
- spec/client/notifier_spec.rb
|
266
269
|
- spec/server/config_spec.rb
|
267
270
|
- spec/server/event_spec.rb
|