orchestrate 0.5
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.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +115 -0
- data/Rakefile +20 -0
- data/lib/orchestrate.rb +46 -0
- data/lib/orchestrate/api.rb +15 -0
- data/lib/orchestrate/api/errors.rb +57 -0
- data/lib/orchestrate/api/extensions.rb +14 -0
- data/lib/orchestrate/client.rb +410 -0
- data/lib/orchestrate/configuration.rb +53 -0
- data/lib/orchestrate/helpers.rb +22 -0
- data/lib/orchestrate/version.rb +3 -0
- data/orchestrate.gemspec +27 -0
- data/test/orchestrate/api/collections_test.rb +87 -0
- data/test/orchestrate/api/event_test.rb +133 -0
- data/test/orchestrate/api/graph_test.rb +44 -0
- data/test/orchestrate/api/key_value_test.rb +173 -0
- data/test/orchestrate/client_test.rb +40 -0
- data/test/orchestrate/configuration_test.rb +67 -0
- data/test/test_helper.rb +80 -0
- metadata +181 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
require "logger"
|
2
|
+
|
3
|
+
module Orchestrate
|
4
|
+
|
5
|
+
#
|
6
|
+
# Represents the configuration for the Orchestrate library, including
|
7
|
+
# values for the api key, base url and other settings.
|
8
|
+
#
|
9
|
+
# An instance of this class is always available at Orchestrate.config.
|
10
|
+
# You should not
|
11
|
+
# instantiate instances of this class, instead, you should configure the
|
12
|
+
# library with the Orchestrate.configure method.
|
13
|
+
#
|
14
|
+
# === Example
|
15
|
+
#
|
16
|
+
# Orchestrate.configure do |config|
|
17
|
+
# config.api_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
class Configuration
|
21
|
+
|
22
|
+
#
|
23
|
+
# The api key for your app, from the Orchestrate Dashboard.
|
24
|
+
#
|
25
|
+
attr_accessor :api_key
|
26
|
+
|
27
|
+
#
|
28
|
+
# The url to the Orchestrate API. Defaults to \https://api.orchestrate.io/v0.
|
29
|
+
#
|
30
|
+
attr_accessor :base_url
|
31
|
+
|
32
|
+
#
|
33
|
+
# The logger instances to send messages to. Defaults to +STDOUT+.
|
34
|
+
#
|
35
|
+
attr_accessor :logger
|
36
|
+
|
37
|
+
# for faraday, here temporarily
|
38
|
+
#
|
39
|
+
attr_accessor :faraday
|
40
|
+
|
41
|
+
#
|
42
|
+
# Initialize and return a new instance of Configuration.
|
43
|
+
#
|
44
|
+
def initialize(options = {}) # :nodoc:
|
45
|
+
@api_key = options[:api_key]
|
46
|
+
@base_url = options[:base_url] || "https://api.orchestrate.io"
|
47
|
+
@logger = options[:logger] || Logger.new(STDOUT)
|
48
|
+
@faraday = options[:faraday]
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Orchestrate
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
extend self
|
5
|
+
|
6
|
+
# * required: type, params={}
|
7
|
+
#
|
8
|
+
# Given a params object such as { start: ..., end: ... } and a type such as 'event',
|
9
|
+
# will return a hash with those parameters formatted for the Orchestrate API, f.e.:
|
10
|
+
# { 'startEvent' => ..., 'endEvent' => ... }
|
11
|
+
def range_keys!(type, params)
|
12
|
+
type = type.capitalize
|
13
|
+
[:start, :end, :before, :after].each do |key|
|
14
|
+
if params[key]
|
15
|
+
params["#{key}#{type}"] = params[key]
|
16
|
+
params.delete(key)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/orchestrate.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'orchestrate/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'orchestrate'
|
7
|
+
s.version = Orchestrate::VERSION
|
8
|
+
s.authors = ['Matthew Lyon', 'Justin Mecham', 'James Carrasquer']
|
9
|
+
s.email = ['matthew@lyonheart.us', 'justin@mecham.me', 'jimcar@aracnet.com']
|
10
|
+
s.summary = 'Ruby client for Orchestrate.io'
|
11
|
+
s.description = 'Client for the Orchestrate REST API'
|
12
|
+
s.homepage = 'https://github.com/orchestrate-io/orchestrate-ruby'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files -z`.split("\x0")
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_dependency "faraday", "~> 0.9"
|
21
|
+
s.add_dependency "faraday_middleware", "~> 0.9", ">= 0.9.1"
|
22
|
+
s.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
s.add_development_dependency "typhoeus"
|
25
|
+
s.add_development_dependency "em-http-request"
|
26
|
+
s.add_development_dependency "em-synchrony"
|
27
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class CollectionTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@collection = 'test'
|
6
|
+
@client, @stubs, @basic_auth = make_client_and_artifacts
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_deletes_collection
|
10
|
+
@stubs.delete("/v0/#{@collection}") do |env|
|
11
|
+
assert_authorization @basic_auth, env
|
12
|
+
assert_equal "true", env.params["force"]
|
13
|
+
headers = response_headers
|
14
|
+
headers.delete('Content-Type')
|
15
|
+
[204, headers, '']
|
16
|
+
end
|
17
|
+
|
18
|
+
response = @client.delete_collection(@collection)
|
19
|
+
assert_equal 204, response.status
|
20
|
+
assert_equal '', response.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_lists_collection_without_params
|
24
|
+
body = {"count" => 0, "results" => [], "next" => ""}
|
25
|
+
|
26
|
+
@stubs.get("/v0/#{@collection}") do |env|
|
27
|
+
assert_authorization @basic_auth, env
|
28
|
+
assert_accepts_json env
|
29
|
+
[200, response_headers, body.to_json]
|
30
|
+
end
|
31
|
+
|
32
|
+
response = @client.list(@collection)
|
33
|
+
assert_equal 200, response.status
|
34
|
+
assert_equal body, response.body
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_lists_collections_with_params_passes_them
|
38
|
+
body = {"count" => 0, "results" => [], "next" => ""}
|
39
|
+
@stubs.get("/v0/#{@collection}") do |env|
|
40
|
+
assert_authorization @basic_auth, env
|
41
|
+
assert_accepts_json env
|
42
|
+
assert_equal "1", env.params['limit']
|
43
|
+
assert_equal "foo", env.params['startKey']
|
44
|
+
assert_equal ['limit', 'startKey'], env.params.keys
|
45
|
+
[ 200, response_headers, body.to_json]
|
46
|
+
end
|
47
|
+
|
48
|
+
response = @client.list(@collection, {limit:1, start: 'foo'})
|
49
|
+
assert_equal 200, response.status
|
50
|
+
assert_equal body, response.body
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_search_with_simple_query
|
54
|
+
query = 'text:"The Right Way" and go'
|
55
|
+
body = { "results" => [], "count" => 0, "total_count" => 10, "next" => "", "prev" => "" }
|
56
|
+
|
57
|
+
@stubs.get("/v0/#{@collection}") do |env|
|
58
|
+
assert_authorization @basic_auth, env
|
59
|
+
assert_accepts_json env
|
60
|
+
assert_equal query, env.params['query']
|
61
|
+
[ 200, response_headers, body.to_json]
|
62
|
+
end
|
63
|
+
|
64
|
+
response = @client.search(@collection, query)
|
65
|
+
assert_equal 200, response.status
|
66
|
+
assert_equal body, response.body
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_search_with_extra_params
|
70
|
+
query = 'text:"The Right Way" and go'
|
71
|
+
body = { "results" => [], "count" => 0, "total_count" => 10, "next" => "", "prev" => "" }
|
72
|
+
|
73
|
+
@stubs.get("/v0/#{@collection}") do |env|
|
74
|
+
assert_authorization @basic_auth, env
|
75
|
+
assert_accepts_json env
|
76
|
+
assert_equal query, env.params['query']
|
77
|
+
assert_equal '3', env.params['offset']
|
78
|
+
assert_equal '10', env.params['limit']
|
79
|
+
[ 200, response_headers, body.to_json]
|
80
|
+
end
|
81
|
+
|
82
|
+
response = @client.search(@collection, query, {offset: 3, limit: 10})
|
83
|
+
assert_equal 200, response.status
|
84
|
+
assert_equal body, response.body
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class EventTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@collection = 'tests'
|
7
|
+
@key = 'instance'
|
8
|
+
@client, @stubs, @basic_auth = make_client_and_artifacts
|
9
|
+
@event_type = "commits"
|
10
|
+
@timestamp = (Time.now.to_f * 1000).to_i
|
11
|
+
@ordinal = 5
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_event
|
15
|
+
body = { "path" => {}, "value" => {"msg" => "hello"}, "timestamp" => @timestamp, "ordinal" => @ordinal }
|
16
|
+
@stubs.get("/v0/#{@collection}/#{@key}/events/#{@event_type}/#{@timestamp}/#{@ordinal}") do |env|
|
17
|
+
assert_authorization @basic_auth, env
|
18
|
+
assert_accepts_json env
|
19
|
+
[200, response_headers, body.to_json]
|
20
|
+
end
|
21
|
+
|
22
|
+
response = @client.get_event(@collection, @key, @event_type, @timestamp, @ordinal)
|
23
|
+
assert_equal 200, response.status
|
24
|
+
assert_equal body, response.body
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_post_event_without_timestamp
|
28
|
+
event = {"msg" => "hello"}
|
29
|
+
@stubs.post("/v0/#{@collection}/#{@key}/events/#{@event_type}") do |env|
|
30
|
+
assert_authorization @basic_auth, env
|
31
|
+
assert_equal event.to_json, env.body
|
32
|
+
[204, response_headers, '']
|
33
|
+
end
|
34
|
+
|
35
|
+
response = @client.post_event(@collection, @key, @event_type, event)
|
36
|
+
assert_equal 204, response.status
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_post_event_with_timestamp
|
40
|
+
event = {"msg" => "hello"}
|
41
|
+
@stubs.post("/v0/#{@collection}/#{@key}/events/#{@event_type}/#{@timestamp}") do |env|
|
42
|
+
assert_authorization @basic_auth, env
|
43
|
+
assert_equal event.to_json, env.body
|
44
|
+
[204, response_headers, '']
|
45
|
+
end
|
46
|
+
|
47
|
+
response = @client.post_event(@collection, @key, @event_type, event, @timestamp)
|
48
|
+
assert_equal 204, response.status
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_put_event_without_ref
|
52
|
+
event = {"msg" => "hello"}
|
53
|
+
@stubs.put("/v0/#{@collection}/#{@key}/events/#{@event_type}/#{@timestamp}/#{@ordinal}") do |env|
|
54
|
+
assert_authorization @basic_auth, env
|
55
|
+
assert_equal event.to_json, env.body
|
56
|
+
[204, response_headers, '']
|
57
|
+
end
|
58
|
+
response = @client.put_event(@collection, @key, @event_type, @timestamp, @ordinal, event)
|
59
|
+
assert_equal 204, response.status
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_put_event_with_ref
|
63
|
+
event = {"msg" => "hello"}
|
64
|
+
ref = "12345"
|
65
|
+
path = ['v0', @collection, @key, 'events', @event_type, @timestamp, @ordinal]
|
66
|
+
@stubs.put(path.join("/")) do |env|
|
67
|
+
assert_authorization @basic_auth, env
|
68
|
+
assert_header 'If-Match', "\"#{ref}\"", env
|
69
|
+
assert_equal event.to_json, env.body
|
70
|
+
[204, response_headers, '']
|
71
|
+
end
|
72
|
+
response = @client.put_event(@collection, @key, @event_type, @timestamp, @ordinal, event, ref)
|
73
|
+
assert_equal 204, response.status
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_purge_event_without_ref
|
77
|
+
path = ['v0', @collection, @key, 'events', @event_type, @timestamp, @ordinal]
|
78
|
+
@stubs.delete(path.join("/")) do |env|
|
79
|
+
assert_authorization @basic_auth, env
|
80
|
+
assert_equal 'true', env.params['purge']
|
81
|
+
[204, response_headers, '']
|
82
|
+
end
|
83
|
+
response = @client.purge_event(@collection, @key, @event_type, @timestamp, @ordinal)
|
84
|
+
assert_equal 204, response.status
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_purge_event_with_ref
|
88
|
+
path = ['v0', @collection, @key, 'events', @event_type, @timestamp, @ordinal]
|
89
|
+
ref = "12345"
|
90
|
+
@stubs.delete(path.join("/")) do |env|
|
91
|
+
assert_authorization @basic_auth, env
|
92
|
+
assert_header 'If-Match', "\"#{ref}\"", env
|
93
|
+
assert_equal 'true', env.params['purge']
|
94
|
+
[204, response_headers, '']
|
95
|
+
end
|
96
|
+
response = @client.purge_event(@collection, @key, @event_type, @timestamp, @ordinal, ref)
|
97
|
+
assert_equal 204, response.status
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_list_events_without_timestamp
|
101
|
+
body = { "results" => [], "count" => 0, "next" => "" }
|
102
|
+
@stubs.get("/v0/#{@collection}/#{@key}/events/#{@event_type}") do |env|
|
103
|
+
assert_authorization @basic_auth, env
|
104
|
+
assert_accepts_json env
|
105
|
+
[200, response_headers, body.to_json]
|
106
|
+
end
|
107
|
+
|
108
|
+
response = @client.list_events(@collection, @key, @event_type)
|
109
|
+
assert_equal 200, response.status
|
110
|
+
assert_equal body, response.body
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_list_events_with_timestamp
|
114
|
+
end_time = Time.now
|
115
|
+
start_time = end_time - (24 * 3600)
|
116
|
+
body = { "results" => [], "count" => 0, "next" => "" }
|
117
|
+
|
118
|
+
@stubs.get("/v0/#{@collection}/#{@key}/events/#{@event_type}") do |env|
|
119
|
+
assert_authorization @basic_auth, env
|
120
|
+
assert_accepts_json env
|
121
|
+
assert_equal start_time.to_i.to_s, env.params['startEvent']
|
122
|
+
assert_equal end_time.to_i.to_s, env.params['endEvent']
|
123
|
+
assert_equal ['startEvent', 'endEvent'].sort, env.params.keys.sort
|
124
|
+
[200, response_headers, body.to_json]
|
125
|
+
end
|
126
|
+
response = @client.list_events(@collection, @key, @event_type,
|
127
|
+
{ start: start_time.to_i, end: end_time.to_i }
|
128
|
+
)
|
129
|
+
assert_equal 200, response.status
|
130
|
+
assert_equal body, response.body
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
class GraphTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@collection = 'tests'
|
6
|
+
@key = 'instance'
|
7
|
+
@kind = 'link'
|
8
|
+
@client, @stubs, @basic_auth = make_client_and_artifacts
|
9
|
+
@target_collection = 'bucket'
|
10
|
+
@target_key = 'vez'
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_graph
|
14
|
+
body = { "count" => 0, "results" => [] }
|
15
|
+
@stubs.get("/v0/#{@collection}/#{@key}/relations/#{@kind}/#{@kind}") do |env|
|
16
|
+
assert_authorization @basic_auth, env
|
17
|
+
assert_accepts_json env
|
18
|
+
[200, response_headers, body.to_json]
|
19
|
+
end
|
20
|
+
|
21
|
+
response = @client.get_relations(@collection, @key, @kind, @kind)
|
22
|
+
assert_equal 200, response.status
|
23
|
+
assert_equal body, response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_put_graph
|
27
|
+
@stubs.put("/v0/#{@collection}/#{@key}/relation/#{@kind}/#{@target_collection}/#{@target_key}") do |env|
|
28
|
+
assert_authorization @basic_auth, env
|
29
|
+
[ 204, response_headers, '' ]
|
30
|
+
end
|
31
|
+
response = @client.put_relation(@collection, @key, @kind, @target_collection, @target_key)
|
32
|
+
assert_equal 204, response.status
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_delete_graph
|
36
|
+
@stubs.delete("/v0/#{@collection}/#{@key}/relation/#{@kind}/#{@target_collection}/#{@target_key}") do |env|
|
37
|
+
assert_authorization @basic_auth, env
|
38
|
+
assert_equal 'true', env.params['purge']
|
39
|
+
[ 204, response_headers, '' ]
|
40
|
+
end
|
41
|
+
response = @client.delete_relation(@collection, @key, @kind, @target_collection, @target_key)
|
42
|
+
assert_equal 204, response.status
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require_relative "../../test_helper"
|
2
|
+
|
3
|
+
class KeyValueTest < MiniTest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@collection = 'test'
|
6
|
+
@key = 'keyname'
|
7
|
+
@client, @stubs, @basic_auth = make_client_and_artifacts
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_gets_current_value_for_key_when_exists
|
11
|
+
ref = SecureRandom.hex(16)
|
12
|
+
ref_url = "/v0/#{@collection}/#{@key}/refs/#{ref}"
|
13
|
+
body = { "key" => "value" }
|
14
|
+
@stubs.get("/v0/#{@collection}/#{@key}") do |env|
|
15
|
+
assert_authorization @basic_auth, env
|
16
|
+
assert_accepts_json env
|
17
|
+
headers = {
|
18
|
+
'Content-Location' => ref_url,
|
19
|
+
'ETag' => "\"#{ref}\"",
|
20
|
+
}.merge(chunked_encoding_header)
|
21
|
+
[ 200, response_headers(headers), body.to_json]
|
22
|
+
end
|
23
|
+
|
24
|
+
response = @client.get(@collection, @key)
|
25
|
+
assert_equal 200, response.status
|
26
|
+
assert_equal body, response.body
|
27
|
+
|
28
|
+
assert_equal "\"#{ref}\"", response.headers['Etag']
|
29
|
+
assert_equal ref_url, response.headers['Content-Location']
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_gets_key_value_is_404_when_does_not_exist
|
33
|
+
@stubs.get("/v0/#{@collection}/#{@key}") do |env|
|
34
|
+
assert_authorization @basic_auth, env
|
35
|
+
assert_accepts_json env
|
36
|
+
[ 404, response_headers(), response_not_found({collection:@collection, key:@key}) ]
|
37
|
+
end
|
38
|
+
|
39
|
+
response = @client.get(@collection, @key)
|
40
|
+
assert_equal 404, response.status
|
41
|
+
assert_equal 'items_not_found', response.body['code']
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_puts_key_value_without_ref
|
45
|
+
body={"foo" => "bar"}
|
46
|
+
@stubs.put("/v0/#{@collection}/#{@key}") do |env|
|
47
|
+
assert_authorization @basic_auth, env
|
48
|
+
assert_header 'Content-Type', 'application/json', env
|
49
|
+
assert_equal body.to_json, env.body
|
50
|
+
[ 201, response_headers, '' ]
|
51
|
+
end
|
52
|
+
|
53
|
+
response = @client.put(@collection, @key, body)
|
54
|
+
assert_equal 201, response.status
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_puts_key_value_with_specific_ref
|
58
|
+
body = {"foo" => "bar"}
|
59
|
+
ref = '123456'
|
60
|
+
|
61
|
+
@stubs.put("/v0/#{@collection}/#{@key}") do |env|
|
62
|
+
assert_authorization @basic_auth, env
|
63
|
+
assert_header 'If-Match', "\"#{ref}\"", env
|
64
|
+
assert_header 'Content-Type', 'application/json', env
|
65
|
+
assert_equal body.to_json, env.body
|
66
|
+
[ 200, response_headers, '' ]
|
67
|
+
end
|
68
|
+
|
69
|
+
response = @client.put(@collection, @key, body, ref)
|
70
|
+
assert_equal 200, response.status
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_puts_key_value_if_unmodified
|
74
|
+
body = {"foo" => "bar"}
|
75
|
+
ref = '123456'
|
76
|
+
|
77
|
+
@stubs.put("/v0/#{@collection}/#{@key}") do |env|
|
78
|
+
assert_authorization @basic_auth, env
|
79
|
+
assert_header 'If-Match', "\"#{ref}\"", env
|
80
|
+
assert_header 'Content-Type', 'application/json', env
|
81
|
+
assert_equal body.to_json, env.body
|
82
|
+
[ 200, response_headers, '' ]
|
83
|
+
end
|
84
|
+
|
85
|
+
response = @client.put_if_unmodified(@collection, @key, body, ref)
|
86
|
+
assert_equal 200, response.status
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_puts_key_value_with_inspecific_ref
|
90
|
+
body = {"foo" => "bar"}
|
91
|
+
|
92
|
+
@stubs.put("/v0/#{@collection}/#{@key}") do |env|
|
93
|
+
assert_authorization @basic_auth, env
|
94
|
+
assert_header 'If-None-Match', '*', env
|
95
|
+
assert_header 'Content-Type', 'application/json', env
|
96
|
+
assert_equal body.to_json, env.body
|
97
|
+
[ 200, response_headers, '' ]
|
98
|
+
end
|
99
|
+
|
100
|
+
response = @client.put(@collection, @key, body, false)
|
101
|
+
assert_equal 200, response.status
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_puts_key_value_if_absent
|
105
|
+
body = {"foo" => "bar"}
|
106
|
+
@stubs.put("/v0/#{@collection}/#{@key}") do |env|
|
107
|
+
assert_authorization @basic_auth, env
|
108
|
+
assert_header 'If-None-Match', '*', env
|
109
|
+
assert_header 'Content-Type', 'application/json', env
|
110
|
+
assert_equal body.to_json, env.body
|
111
|
+
[ 200, response_headers, '' ]
|
112
|
+
end
|
113
|
+
|
114
|
+
response = @client.put_if_absent(@collection, @key, body)
|
115
|
+
assert_equal 200, response.status
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_delete_key_value
|
119
|
+
@stubs.delete("/v0/#{@collection}/#{@key}") do |env|
|
120
|
+
assert_authorization @basic_auth, env
|
121
|
+
[ 204, response_headers, '' ]
|
122
|
+
end
|
123
|
+
response = @client.delete(@collection, @key)
|
124
|
+
assert_equal 204, response.status
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_delete_key_value_with_condition
|
128
|
+
ref="12345"
|
129
|
+
@stubs.delete("/v0/#{@collection}/#{@key}") do |env|
|
130
|
+
assert_authorization @basic_auth, env
|
131
|
+
assert_header 'If-Match', "\"#{ref}\"", env
|
132
|
+
[ 204, response_headers, '' ]
|
133
|
+
end
|
134
|
+
response = @client.delete(@collection, @key, ref)
|
135
|
+
assert_equal 204, response.status
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_delete_key_value_with_quoted_condition
|
139
|
+
ref='"12345"'
|
140
|
+
@stubs.delete("/v0/#{@collection}/#{@key}") do |env|
|
141
|
+
assert_authorization @basic_auth, env
|
142
|
+
assert_header 'If-Match', ref, env
|
143
|
+
[ 204, response_headers, '' ]
|
144
|
+
end
|
145
|
+
response = @client.delete(@collection, @key, ref)
|
146
|
+
assert_equal 204, response.status
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_delete_key_value_with_purge
|
150
|
+
@stubs.delete("/v0/#{@collection}/#{@key}") do |env|
|
151
|
+
assert_authorization @basic_auth, env
|
152
|
+
assert_equal "true", env.params["purge"]
|
153
|
+
[ 204, response_headers, '' ]
|
154
|
+
end
|
155
|
+
response = @client.purge(@collection, @key)
|
156
|
+
assert_equal 204, response.status
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_gets_ref
|
160
|
+
body = {"key" => "value"}
|
161
|
+
ref = '123456'
|
162
|
+
@stubs.get("/v0/#{@collection}/#{@key}/refs/#{ref}") do |env|
|
163
|
+
assert_authorization @basic_auth, env
|
164
|
+
assert_accepts_json env
|
165
|
+
[ 200, response_headers, body.to_json ]
|
166
|
+
end
|
167
|
+
|
168
|
+
response = @client.get(@collection, @key, ref)
|
169
|
+
assert_equal 200, response.status
|
170
|
+
assert_equal body, response.body
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|