holoserve-connector 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +9 -8
- data/lib/holoserve/connector/bucket.rb +5 -1
- data/lib/holoserve/connector/fixtures.rb +42 -0
- data/lib/holoserve/connector/history.rb +3 -3
- data/lib/holoserve/connector/pairs.rb +43 -0
- data/lib/holoserve/connector/situation.rb +22 -0
- data/lib/holoserve/connector/tool/uploader.rb +40 -0
- data/lib/holoserve/connector/tool.rb +6 -0
- data/lib/holoserve/connector.rb +10 -3
- metadata +16 -12
- data/lib/holoserve/connector/layout.rb +0 -59
data/README.rdoc
CHANGED
@@ -9,15 +9,16 @@ test suite. See {holoserve}[https://github.com/skrill/holoserve] for details abo
|
|
9
9
|
require 'holoserve/connector'
|
10
10
|
require 'transport'
|
11
11
|
|
12
|
-
holoserve = Holoserve::Connector.new :host => "localhost"
|
12
|
+
holoserve = Holoserve::Connector.new :host => "localhost"
|
13
13
|
|
14
|
-
holoserve.
|
15
|
-
holoserve.
|
14
|
+
holoserve.fixtures.upload "./fixtures/*.json"
|
15
|
+
holoserve.pairs.upload "./pairs/*.yaml"
|
16
|
+
holoserve.situation.name = "one"
|
16
17
|
|
17
18
|
Transport::HTTP.request :post, "/test" # handled in test layout one
|
18
19
|
Transport::HTTP.request :delete, "/test" # unhandled
|
19
20
|
|
20
|
-
holoserve.history.
|
21
|
+
holoserve.history.pair_ids
|
21
22
|
# => [ "test_requested" ]
|
22
23
|
|
23
24
|
holoserve.bucket.requsts
|
@@ -32,13 +33,13 @@ test suite. See {holoserve}[https://github.com/skrill/holoserve] for details abo
|
|
32
33
|
describe "RSpec matchers" do
|
33
34
|
|
34
35
|
before :all do
|
35
|
-
@client = Holoserve::
|
36
|
-
@client.
|
37
|
-
@client.
|
36
|
+
@client = Holoserve::Connector.new
|
37
|
+
@client.pairs.upload File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "pairs", "test.yaml"))
|
38
|
+
@client.situation.name = "one"
|
38
39
|
end
|
39
40
|
|
40
41
|
it "should test if holoserve received a specified request" do
|
41
|
-
Transport::HTTP.request :post, "http://localhost:
|
42
|
+
Transport::HTTP.request :post, "http://localhost:4250/test", :expected_status_code => 201
|
42
43
|
@client.should have_received("test_request")
|
43
44
|
end
|
44
45
|
|
@@ -6,7 +6,11 @@ class Holoserve::Connector::Bucket
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def requests
|
9
|
-
Transport::JSON.request :get, "#{@client.url}/bucket
|
9
|
+
Transport::JSON.request :get, "#{@client.url}/bucket"
|
10
|
+
end
|
11
|
+
|
12
|
+
def clear!
|
13
|
+
Transport::JSON.request :delete, "#{@client.url}/bucket"
|
10
14
|
end
|
11
15
|
|
12
16
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
class Holoserve::Connector::Fixtures
|
3
|
+
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def upload(pattern)
|
9
|
+
Dir[ pattern ].each do |filename|
|
10
|
+
upload_file filename
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def download(id)
|
15
|
+
response = Transport::HTTP.request :get,
|
16
|
+
"#{@client.url}/fixtures/#{id}.yaml",
|
17
|
+
:expected_status_code => 200
|
18
|
+
YAML.load response
|
19
|
+
rescue Transport::UnexpectedStatusCodeError => error
|
20
|
+
raise Holoserve::Connector::Error, error.message unless error.status_code == 404
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def clear!
|
25
|
+
Transport::JSON.request :delete, "#{@client.url}/fixtures"
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def upload_file(filename)
|
31
|
+
uploader = Holoserve::Connector::Tool::Uploader.new filename,
|
32
|
+
:post,
|
33
|
+
"#{@client.url}/fixtures",
|
34
|
+
:expected_status_code => 200
|
35
|
+
uploader.upload
|
36
|
+
true
|
37
|
+
rescue Transport::UnexpectedStatusCodeError => error
|
38
|
+
raise Holoserve::Connector::Error, error.message unless error.status_code == 400
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -9,8 +9,8 @@ class Holoserve::Connector::History
|
|
9
9
|
Transport::JSON.request :delete, "#{@client.url}/history"
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
Transport::JSON.request :get, "#{@client.url}/history
|
12
|
+
def pair_ids
|
13
|
+
Transport::JSON.request :get, "#{@client.url}/history"
|
14
14
|
end
|
15
15
|
|
16
|
-
end
|
16
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
class Holoserve::Connector::Pairs
|
4
|
+
|
5
|
+
def initialize(client)
|
6
|
+
@client = client
|
7
|
+
end
|
8
|
+
|
9
|
+
def upload(pattern)
|
10
|
+
Dir[ pattern ].each do |filename|
|
11
|
+
upload_file filename
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def download(id)
|
16
|
+
response = Transport::HTTP.request :get,
|
17
|
+
"#{@client.url}/pairs/#{id}.yaml",
|
18
|
+
:expected_status_code => 200
|
19
|
+
YAML.load response
|
20
|
+
rescue Transport::UnexpectedStatusCodeError => error
|
21
|
+
raise Holoserve::Connector::Error, error.message unless error.status_code == 404
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def clear!
|
26
|
+
Transport::JSON.request :delete, "#{@client.url}/pairs"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def upload_file(filename)
|
32
|
+
uploader = Holoserve::Connector::Tool::Uploader.new filename,
|
33
|
+
:post,
|
34
|
+
"#{@client.url}/pairs",
|
35
|
+
:expected_status_code => 200
|
36
|
+
uploader.upload
|
37
|
+
true
|
38
|
+
rescue Transport::UnexpectedStatusCodeError => error
|
39
|
+
raise Holoserve::Connector::Error, error.message unless error.status_code == 400
|
40
|
+
false
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
class Holoserve::Connector::Situation
|
3
|
+
|
4
|
+
def initialize(client)
|
5
|
+
@client = client
|
6
|
+
end
|
7
|
+
|
8
|
+
def name=(value)
|
9
|
+
Transport::JSON.request :put, "#{@client.url}/situation", :parameters => { :name => value }
|
10
|
+
end
|
11
|
+
|
12
|
+
def name
|
13
|
+
response = Transport::JSON.request :get, "#{@client.url}/situation"
|
14
|
+
name = response["name"]
|
15
|
+
name == "" ? nil : name
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear!
|
19
|
+
Transport::JSON.request :put, "#{@client.url}/situation", :parameters => { :name => nil }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'transport'
|
2
|
+
|
3
|
+
class Holoserve::Connector::Tool::Uploader
|
4
|
+
|
5
|
+
def initialize(filename, http_method, url, options = { })
|
6
|
+
@filename, @http_method, @url, @options = filename, http_method, url, options
|
7
|
+
end
|
8
|
+
|
9
|
+
def upload
|
10
|
+
Transport::HTTP.request @http_method, @url, @options.merge(:headers => headers, :body => body)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def headers
|
16
|
+
{ "Content-Type" => "multipart/form-data, boundary=#{boundary}" }
|
17
|
+
end
|
18
|
+
|
19
|
+
def body
|
20
|
+
"--#{boundary}\r\n" +
|
21
|
+
"Content-Disposition: form-data; name=\"file\"; filename=\"#{File.basename(@filename)}\"\r\n" +
|
22
|
+
"Content-Type: #{content_type}\r\n" +
|
23
|
+
"\r\n" +
|
24
|
+
File.read(@filename) +
|
25
|
+
"\r\n" +
|
26
|
+
"--#{boundary}--\r\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
def content_type
|
30
|
+
{
|
31
|
+
"yaml" => "application/x-yaml",
|
32
|
+
"json" => "application/json"
|
33
|
+
}[ File.extname(@filename) ] || "text/plain"
|
34
|
+
end
|
35
|
+
|
36
|
+
def boundary
|
37
|
+
"xxx12345xxx"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/holoserve/connector.rb
CHANGED
@@ -2,26 +2,33 @@
|
|
2
2
|
class Holoserve::Connector
|
3
3
|
|
4
4
|
autoload :Bucket, File.join(File.dirname(__FILE__), "connector", "bucket")
|
5
|
+
autoload :Fixtures, File.join(File.dirname(__FILE__), "connector", "fixtures")
|
5
6
|
autoload :History, File.join(File.dirname(__FILE__), "connector", "history")
|
6
|
-
autoload :
|
7
|
+
autoload :Pairs, File.join(File.dirname(__FILE__), "connector", "pairs")
|
8
|
+
autoload :Situation, File.join(File.dirname(__FILE__), "connector", "situation")
|
9
|
+
autoload :Tool, File.join(File.dirname(__FILE__), "connector", "tool")
|
7
10
|
|
8
11
|
class Error < StandardError; end
|
9
12
|
|
10
13
|
attr_reader :host
|
11
14
|
attr_reader :port
|
12
15
|
|
13
|
-
attr_reader :layout
|
14
16
|
attr_reader :bucket
|
17
|
+
attr_reader :fixtures
|
15
18
|
attr_reader :history
|
19
|
+
attr_reader :pairs
|
20
|
+
attr_reader :situation
|
16
21
|
|
17
22
|
def initialize(options = { })
|
18
23
|
@host, @port = *options.values_at(:host, :port)
|
19
24
|
@host ||= "localhost"
|
20
25
|
@port ||= 4250
|
21
26
|
|
22
|
-
@layout = Layout.new self
|
23
27
|
@bucket = Bucket.new self
|
28
|
+
@fixtures = Fixtures.new self
|
24
29
|
@history = History.new self
|
30
|
+
@pairs = Pairs.new self
|
31
|
+
@situation = Situation.new self
|
25
32
|
end
|
26
33
|
|
27
34
|
def url
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: holoserve-connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: transport
|
16
|
-
requirement: &
|
16
|
+
requirement: &70096261721080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70096261721080
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: holoserve
|
27
|
-
requirement: &
|
27
|
+
requirement: &70096261720480 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70096261720480
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: cucumber
|
38
|
-
requirement: &
|
38
|
+
requirement: &70096261736180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70096261736180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70096261735580 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70096261735580
|
58
58
|
description: Provides a client for the control interface of holoserve and some RSpec
|
59
59
|
matchers.
|
60
60
|
email: philipp.bruell@skrill.com
|
@@ -67,8 +67,12 @@ files:
|
|
67
67
|
- LICENSE
|
68
68
|
- Rakefile
|
69
69
|
- lib/holoserve/connector/bucket.rb
|
70
|
+
- lib/holoserve/connector/fixtures.rb
|
70
71
|
- lib/holoserve/connector/history.rb
|
71
|
-
- lib/holoserve/connector/
|
72
|
+
- lib/holoserve/connector/pairs.rb
|
73
|
+
- lib/holoserve/connector/situation.rb
|
74
|
+
- lib/holoserve/connector/tool/uploader.rb
|
75
|
+
- lib/holoserve/connector/tool.rb
|
72
76
|
- lib/holoserve/connector.rb
|
73
77
|
- lib/rspec/holoserve.rb
|
74
78
|
- spec/helper.rb
|
@@ -88,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
92
|
version: '0'
|
89
93
|
segments:
|
90
94
|
- 0
|
91
|
-
hash:
|
95
|
+
hash: -1743870002252913970
|
92
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
97
|
none: false
|
94
98
|
requirements:
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'transport'
|
2
|
-
|
3
|
-
class Holoserve::Connector::Layout
|
4
|
-
|
5
|
-
def initialize(client)
|
6
|
-
@client = client
|
7
|
-
|
8
|
-
@boundary = "xxx12345xxx"
|
9
|
-
end
|
10
|
-
|
11
|
-
def clear!
|
12
|
-
Transport::JSON.request :delete,
|
13
|
-
"#{@client.url}/layout",
|
14
|
-
:expected_status_code => 200
|
15
|
-
end
|
16
|
-
|
17
|
-
def upload_yaml(filename)
|
18
|
-
Transport::HTTP.request :post,
|
19
|
-
"#{@client.url}/layout.yaml",
|
20
|
-
:body => upload_yaml_file_request_body(filename),
|
21
|
-
:headers => {
|
22
|
-
"Content-Type" => "multipart/form-data, boundary=#{@boundary}"
|
23
|
-
},
|
24
|
-
:expected_status_code => 200
|
25
|
-
true
|
26
|
-
rescue Transport::UnexpectedStatusCodeError => error
|
27
|
-
raise Holoserve::Connector::Error, error.message
|
28
|
-
end
|
29
|
-
|
30
|
-
def download_yaml
|
31
|
-
response = Transport::HTTP.request :get,
|
32
|
-
"#{@client.url}/layout.yaml",
|
33
|
-
:expected_status_code => 200
|
34
|
-
YAML.load response
|
35
|
-
rescue Transport::UnexpectedStatusCodeError => error
|
36
|
-
raise Holoserve::Connector::Error, error.message
|
37
|
-
end
|
38
|
-
|
39
|
-
def situation=(value)
|
40
|
-
Transport::JSON.request :put, "#{@client.url}/situation/#{value}"
|
41
|
-
end
|
42
|
-
|
43
|
-
def situation
|
44
|
-
Transport::HTTP.request :get, "#{@client.url}/situation"
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def upload_yaml_file_request_body(filename)
|
50
|
-
"--#{@boundary}\r\n" +
|
51
|
-
"Content-Disposition: form-data; name=\"file\"; filename=\"#{File.basename(filename)}\"\r\n" +
|
52
|
-
"Content-Type: application/x-yaml\r\n" +
|
53
|
-
"\r\n" +
|
54
|
-
File.read(filename) +
|
55
|
-
"\r\n" +
|
56
|
-
"--#{@boundary}--\r\n"
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|