vayacondios-client 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.
@@ -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
@@ -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-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
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-07 00:00:00.000000000 Z
15
+ date: 2012-09-10 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: configliere
@@ -120,7 +120,9 @@ files:
120
120
  - lib/vayacondios-client.rb
121
121
  - lib/vayacondios/client/configliere.rb
122
122
  - lib/vayacondios/client/http_client.rb
123
+ - lib/vayacondios/client/itemset.rb
123
124
  - lib/vayacondios/client/notifier.rb
125
+ - spec/client/itemset_spec.rb
124
126
  - spec/client/notifier_spec.rb
125
127
  homepage: https://github.com/infochimps-labs/vayacondios
126
128
  licenses: []
@@ -136,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
138
  version: '0'
137
139
  segments:
138
140
  - 0
139
- hash: -4312748117429631966
141
+ hash: 489609352583290031
140
142
  required_rubygems_version: !ruby/object:Gem::Requirement
141
143
  none: false
142
144
  requirements:
@@ -145,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
147
  version: '0'
146
148
  segments:
147
149
  - 0
148
- hash: -4312748117429631966
150
+ hash: 489609352583290031
149
151
  requirements: []
150
152
  rubyforge_project:
151
153
  rubygems_version: 1.8.23
@@ -153,5 +155,6 @@ signing_key:
153
155
  specification_version: 3
154
156
  summary: Data goes in. The right thing happens
155
157
  test_files:
158
+ - spec/client/itemset_spec.rb
156
159
  - spec/client/notifier_spec.rb
157
160
  has_rdoc: