reflect-rb 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reflect.rb +9 -0
- data/lib/reflect/client.rb +13 -3
- data/lib/reflect/key_list.rb +21 -0
- data/lib/reflect/keyspace.rb +43 -4
- data/lib/reflect/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25db9005bbdc970fe479c2e5d91910b9b398c9d7
|
4
|
+
data.tar.gz: ec858bb37b3230d6495b1e703582ad9a6712faa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7f69a4e1587ae3e5915c9f14690ef681fa7da21e9524220abb585eaf273151d69fc77f50c4b59837c8243ee9dc1aed61481f2d64337758ec4f6dd80e8ea89b9
|
7
|
+
data.tar.gz: 155323b8632e22e7bceabf6e57acd5aaed522b22bd5c878d3c581d424ac4bece7bedb0c26c9918fa717075b067e48855634f93e2f847da18f7df2ca2f5c8664e
|
data/lib/reflect.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
$:.unshift(File.expand_path("../", __FILE__))
|
2
2
|
|
3
|
+
require 'reflect/key_list'
|
3
4
|
require 'reflect/request_error'
|
4
5
|
require 'reflect/keyspace'
|
5
6
|
require 'reflect/field'
|
@@ -19,4 +20,12 @@ module Reflect
|
|
19
20
|
""
|
20
21
|
end
|
21
22
|
end
|
23
|
+
|
24
|
+
def self.logger=(logger)
|
25
|
+
@logger = logger
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.logger
|
29
|
+
@logger ||= Logger.new("/dev/null")
|
30
|
+
end
|
22
31
|
end
|
data/lib/reflect/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'uri'
|
1
2
|
require 'json'
|
2
3
|
require 'httparty'
|
3
4
|
require 'reflect/version'
|
@@ -24,15 +25,20 @@ module Reflect
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def get(path)
|
27
|
-
self.class.get(path, options)
|
28
|
+
self.class.get(URI.encode(path), options)
|
28
29
|
end
|
29
30
|
|
30
31
|
def post(path, content)
|
31
|
-
self.class.post(path, options(body: dump(content)))
|
32
|
+
self.class.post(URI.encode(path), options(body: dump(content)))
|
32
33
|
end
|
33
34
|
|
34
35
|
def put(path, content)
|
35
|
-
self.class.put(path, options(body: dump(content)))
|
36
|
+
self.class.put(URI.encode(path), options(body: dump(content)))
|
37
|
+
end
|
38
|
+
|
39
|
+
def delete(path)
|
40
|
+
logger.debug { "[reflect] Sending DELETE #{URI.encode(path)}" }
|
41
|
+
self.class.delete(URI.encode(path), options)
|
36
42
|
end
|
37
43
|
|
38
44
|
def patch(path, content, headers={})
|
@@ -58,5 +64,9 @@ module Reflect
|
|
58
64
|
def dump(obj)
|
59
65
|
JSON.dump(obj)
|
60
66
|
end
|
67
|
+
|
68
|
+
def logger
|
69
|
+
Reflect.logger
|
70
|
+
end
|
61
71
|
end
|
62
72
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Reflect
|
2
|
+
class KeyList
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
attr_reader :keys
|
6
|
+
attr_reader :next
|
7
|
+
|
8
|
+
def initialize(keys, continuation)
|
9
|
+
@keys = keys || []
|
10
|
+
@next = continuation
|
11
|
+
end
|
12
|
+
|
13
|
+
def each(&blk)
|
14
|
+
keys.each(&blk)
|
15
|
+
end
|
16
|
+
|
17
|
+
def empty?
|
18
|
+
keys.count < 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/reflect/keyspace.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'cgi'
|
2
1
|
require 'time'
|
3
2
|
require 'reflect/field'
|
4
3
|
|
@@ -33,6 +32,22 @@ module Reflect
|
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
35
|
+
def keys(continuation=nil)
|
36
|
+
resp = client.get(keys_path(slug, continuation))
|
37
|
+
|
38
|
+
if resp.response.code != "200"
|
39
|
+
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
40
|
+
end
|
41
|
+
|
42
|
+
json = JSON.parse(resp.body)
|
43
|
+
|
44
|
+
if json["keys"].nil? || json["keys"].empty?
|
45
|
+
nil
|
46
|
+
else
|
47
|
+
KeyList.new(json["keys"], json["next"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
36
51
|
# Appends records to a tablet. If the tablet doesn't exist it will be
|
37
52
|
# created. records can be either a single object or an array of objects. A
|
38
53
|
# single object represents a single row.
|
@@ -41,7 +56,7 @@ module Reflect
|
|
41
56
|
# @param Array|Hash records the records to create
|
42
57
|
#
|
43
58
|
def append(key, records)
|
44
|
-
resp = client.put(
|
59
|
+
resp = client.put(path(slug, key), records)
|
45
60
|
|
46
61
|
if resp.response.code != "202"
|
47
62
|
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
@@ -56,7 +71,7 @@ module Reflect
|
|
56
71
|
# @param Array|Hash records the records to create
|
57
72
|
#
|
58
73
|
def replace(key, records)
|
59
|
-
resp = client.post(
|
74
|
+
resp = client.post(path(slug, key), records)
|
60
75
|
|
61
76
|
if resp.response.code != "202"
|
62
77
|
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
@@ -73,11 +88,35 @@ module Reflect
|
|
73
88
|
# @param Array criteria an array of field names within a record to match
|
74
89
|
#
|
75
90
|
def patch(key, records, criteria)
|
76
|
-
resp = client.patch(
|
91
|
+
resp = client.patch(path(slug, key), records, "X-Criteria" => criteria.join(", "))
|
77
92
|
|
78
93
|
if resp.response.code != "202"
|
79
94
|
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
80
95
|
end
|
81
96
|
end
|
97
|
+
|
98
|
+
# Deletes a key within a keyspace.
|
99
|
+
#
|
100
|
+
# @param String key the key to delete
|
101
|
+
#
|
102
|
+
def delete(key)
|
103
|
+
resp = client.delete(path(slug, key))
|
104
|
+
|
105
|
+
if resp.response.code != "202"
|
106
|
+
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def path(slug, key)
|
113
|
+
"/v1/keyspaces/#{slug}/tablets/#{key}"
|
114
|
+
end
|
115
|
+
|
116
|
+
def keys_path(slug, continuation=nil)
|
117
|
+
base = "/v1/keyspaces/#{slug}/keys"
|
118
|
+
base += "?next=#{continuation}" if continuation
|
119
|
+
base
|
120
|
+
end
|
82
121
|
end
|
83
122
|
end
|
data/lib/reflect/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reflect-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Heller
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/reflect.rb
|
62
62
|
- lib/reflect/client.rb
|
63
63
|
- lib/reflect/field.rb
|
64
|
+
- lib/reflect/key_list.rb
|
64
65
|
- lib/reflect/keyspace.rb
|
65
66
|
- lib/reflect/request_error.rb
|
66
67
|
- lib/reflect/version.rb
|