orchestrate 0.6.1 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e012cb7bc45936de2be4211e167acee8a8908b8
4
- data.tar.gz: aa2439edb8a6594826e8e1e892d86e4d3dd9df34
3
+ metadata.gz: 155ad76859df4168e1f6c4bccb31aa3653c8d818
4
+ data.tar.gz: ff250dcd5c8fee7d94517aee3cc4ca3779111b08
5
5
  SHA512:
6
- metadata.gz: 4b1088cdddc122bbfaef376f5e577155cecae4d2cfa5e658a1a7ddf593ea0253cf29929054da79dfa63ab2bfb3a1f410759043863a884fc7aeb2784ff808ff15
7
- data.tar.gz: e4c960bd4754ae8bcb1dc08b79e903016c84b3f7583845f520c6b9cb458fc2b7c37336e2c52d85eda04d1aaa8c652b20c4aa7594c63c1f3abe9ae9d94a6b3f2a
6
+ metadata.gz: 29dc0b21580643d4dc2f064a0db2794be8d2d91abadb1ebc7f81c40359801aafe7fd6991de2c0739bd4b7a19449038c747940b4a3f1e419b7c2104c4ce386fb3
7
+ data.tar.gz: 6bdadb28536cefb2b8969e4e98f7ea2c8da1f13b1344395fb7407508c51ee863d70bc2cecf3129897942ab5fdf51be0324f3a743e9f3ebfe65770ae2e928705b
data/README.md CHANGED
@@ -104,6 +104,12 @@ end
104
104
 
105
105
  ## Release Notes
106
106
 
107
+ - June 24, 2014: release 0.6.2
108
+ - Fix #48 to remove trailing -gzip from Etag header for ref value.
109
+ - Custom #to_s and #inspect methods for Client, Response classes.
110
+ - Implement `If-Match` header for Client#purge
111
+ - Implement Client#post for auto-generated keys endpoint
112
+
107
113
  - June 17, 2014: release 0.6.1
108
114
  - Fix #43 for If-None-Match on Client#put
109
115
  - Fix #46 for Client#ping
@@ -40,6 +40,12 @@ module Orchestrate::API
40
40
  @request_time = Time.parse(headers['Date'])
41
41
  end
42
42
 
43
+ # @!visibility private
44
+ def to_s
45
+ "#<#{self.class.name} status=#{status} request_id=#{request_id}>"
46
+ end
47
+ alias :inspect :to_s
48
+
43
49
  end
44
50
 
45
51
  # A generic response for a single entity (K/V, Ref, Event)
@@ -55,8 +61,9 @@ module Orchestrate::API
55
61
  def initialize(faraday_response, client)
56
62
  super(faraday_response, client)
57
63
  @location = headers['Content-Location'] || headers['Location']
58
- @ref = headers.fetch('Etag','').gsub('"','')
64
+ @ref = headers.fetch('Etag','').gsub('"','').sub(/-gzip$/,'')
59
65
  end
66
+
60
67
  end
61
68
 
62
69
  # A generic response for a collection of entities (K/V, Refs, Events, Search)
@@ -35,6 +35,12 @@ module Orchestrate
35
35
  end
36
36
  end
37
37
 
38
+ # @!visibility private
39
+ def to_s
40
+ "#<Orchestrate::Client api_key=#{api_key[0..7]}... >"
41
+ end
42
+ alias :inspect :to_s
43
+
38
44
  # Tests authentication with Orchestrate.
39
45
  # @return Orchestrate::API::Response
40
46
  # @raise Orchestrate::API::Unauthorized if the client could not authenticate.
@@ -105,6 +111,15 @@ module Orchestrate
105
111
  send_request :get, [collection, key, :refs], { query: options, response: API::CollectionResponse }
106
112
  end
107
113
 
114
+ # [Creates a value at an auto-generated
115
+ # key](https://orchestrate.io/docs/api/?shell#key/value/post-\(create-&-generate-key\)).
116
+ # @param collection [#to_s] The name of the collection.
117
+ # @param body [#to_json] The value to store.
118
+ # @return Orchestrate::API::ItemResponse
119
+ def post(collection, body)
120
+ send_request :post, [collection], { body: body, response: API::ItemResponse }
121
+ end
122
+
108
123
  # [Updates the value associated with
109
124
  # a key](http://orchestrate.io/docs/api/#key/value/put-\(create/update\)).
110
125
  # If the key does not currently have a value, will create the value.
@@ -159,10 +174,12 @@ module Orchestrate
159
174
  # key](http://orchestrate.io/docs/api/#key/value/delete11).
160
175
  # @param collection [#to_s] The name of the collection.
161
176
  # @param key [#to_s] The name of the key.
177
+ # @param ref [#to_s] If specified, purges the ref only if the current value's ref matches.
162
178
  # @return Orchestrate::API::Response
163
- # @todo take an optional ref for If-Match
164
- def purge(collection, key)
165
- send_request :delete, [collection, key], { query: { purge: true } }
179
+ def purge(collection, key, ref=nil)
180
+ headers = {}
181
+ headers['If-Match'] = API::Helpers.format_ref(ref) if ref
182
+ send_request :delete, [collection, key], { query: { purge: true }, headers: headers }
166
183
  end
167
184
 
168
185
  # [List the KeyValue items in a collection](http://orchestrate.io/docs/api/#key/value/list).
@@ -1,3 +1,3 @@
1
1
  module Orchestrate
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
@@ -16,7 +16,7 @@ class KeyValueTest < MiniTest::Unit::TestCase
16
16
  assert_accepts_json env
17
17
  headers = {
18
18
  'Content-Location' => ref_url,
19
- 'ETag' => "\"#{ref}\"",
19
+ 'ETag' => "\"#{ref}-gzip\"",
20
20
  }.merge(chunked_encoding_header)
21
21
  [ 200, response_headers(headers), body.to_json]
22
22
  end
@@ -25,7 +25,7 @@ class KeyValueTest < MiniTest::Unit::TestCase
25
25
  assert_equal 200, response.status
26
26
  assert_equal body, response.body
27
27
 
28
- assert_equal "\"#{ref}\"", response.headers['Etag']
28
+ assert_equal "\"#{ref}-gzip\"", response.headers['Etag']
29
29
  assert_equal ref_url, response.headers['Content-Location']
30
30
 
31
31
  assert_equal ref_url, response.location
@@ -46,6 +46,23 @@ class KeyValueTest < MiniTest::Unit::TestCase
46
46
  end
47
47
  end
48
48
 
49
+ def test_posts_key_value
50
+ body = {"foo" => "bar"}
51
+ ref = "12345"
52
+ key = "567890ac"
53
+ @stubs.post("/v0/#{@collection}") do |env|
54
+ assert_authorization @basic_auth, env
55
+ assert_header 'Content-Type', 'application/json', env
56
+ assert_equal body.to_json, env.body
57
+ headers = { "Location" => "/v0/#{@collection}/#{key}/refs/#{ref}", "Etag" => "\"#{ref}\"" }
58
+ [ 201, response_headers(headers), '' ]
59
+ end
60
+ response = @client.post(@collection, body)
61
+ assert_equal 201, response.status
62
+ assert_equal ref, response.ref
63
+ assert_equal "/v0/#{@collection}/#{key}/refs/#{ref}", response.location
64
+ end
65
+
49
66
  def test_puts_key_value_without_ref
50
67
  body={"foo" => "bar"}
51
68
  ref = "12345"
@@ -169,6 +186,18 @@ class KeyValueTest < MiniTest::Unit::TestCase
169
186
  assert_equal response.headers['X-Orchestrate-Req-Id'], response.request_id
170
187
  end
171
188
 
189
+ def test_delete_key_value_with_purge_and_condition
190
+ ref = "12345"
191
+ @stubs.delete("/v0/#{@collection}/#{@key}") do |env|
192
+ assert_authorization @basic_auth, env
193
+ assert_equal "true", env.params["purge"]
194
+ assert_header 'If-Match', "\"#{ref}\"", env
195
+ [ 204, response_headers, '' ]
196
+ end
197
+ response = @client.purge(@collection, @key, ref)
198
+ assert_equal 204, response.status
199
+ end
200
+
172
201
  def test_gets_ref
173
202
  body = {"key" => "value"}
174
203
  ref = '123456'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orchestrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Lyon
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-06-17 00:00:00.000000000 Z
13
+ date: 2014-06-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday