reflect-rb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reflect/client.rb +7 -1
- data/lib/reflect/keyspace.rb +33 -4
- data/lib/reflect/request_error.rb +4 -0
- data/lib/reflect/version.rb +1 -1
- data/lib/reflect.rb +16 -0
- 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: dcd5a5f70d9f6bff722d83ed08b30ec2bc6c30fa
|
4
|
+
data.tar.gz: a21b5a7dc2686632b2a06414afea2a083cf1728e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 903096125f908b0544601df70ab51743b176307eefbdc5f7a40aa6fa2e0c0cb47b82eb7a3e17cdc5818cce0334e393b9ce69a30d8721bb15663df9f24b4e2c9c
|
7
|
+
data.tar.gz: 463f5d46fb6a9957bcbabbe26f1db668901c8d7e2202fa57acf3b856566d6ce382b7468c47e8e02dfb853f55a02aa1b2268c2ab4472a97eff70b3c6fb81499b1
|
data/lib/reflect/client.rb
CHANGED
@@ -19,7 +19,7 @@ module Reflect
|
|
19
19
|
Keyspace.new(self, JSON.parse(res.body))
|
20
20
|
else
|
21
21
|
# TODO: What happens if we failed to look this up or whatever?
|
22
|
-
|
22
|
+
raise Reflect::RequestError, Reflect._format_error_message(res)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -35,6 +35,12 @@ module Reflect
|
|
35
35
|
self.class.put(path, options(body: dump(content)))
|
36
36
|
end
|
37
37
|
|
38
|
+
def patch(path, content, headers={})
|
39
|
+
opts = options(body: dump(content))
|
40
|
+
opts[:headers].merge!(headers) unless headers.empty?
|
41
|
+
self.class.patch(path, opts)
|
42
|
+
end
|
43
|
+
|
38
44
|
private
|
39
45
|
|
40
46
|
def options(opts={})
|
data/lib/reflect/keyspace.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'cgi'
|
1
2
|
require 'time'
|
2
3
|
require 'reflect/field'
|
3
4
|
|
@@ -33,22 +34,50 @@ module Reflect
|
|
33
34
|
end
|
34
35
|
|
35
36
|
# Appends records to a tablet. If the tablet doesn't exist it will be
|
36
|
-
# created.
|
37
|
+
# created. records can be either a single object or an array of objects. A
|
38
|
+
# single object represents a single row.
|
37
39
|
#
|
38
40
|
# @param String key the key to create
|
39
41
|
# @param Array|Hash records the records to create
|
40
42
|
#
|
41
43
|
def append(key, records)
|
42
|
-
client.put("/v1/keyspaces/"+self.slug+"/tablets/"+key, records)
|
44
|
+
resp = client.put("/v1/keyspaces/"+self.slug+"/tablets/"+CGI.escape(key), records)
|
45
|
+
|
46
|
+
if resp.response.code != "202"
|
47
|
+
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
48
|
+
end
|
43
49
|
end
|
44
50
|
|
45
51
|
# Replaces the existing records in a tablet with a net set of records.
|
46
|
-
#
|
52
|
+
# records can be either a single object or an array of objects. A single
|
53
|
+
# object represents a single row.
|
54
|
+
#
|
47
55
|
# @param String key the key to create
|
48
56
|
# @param Array|Hash records the records to create
|
49
57
|
#
|
50
58
|
def replace(key, records)
|
51
|
-
client.post("/v1/keyspaces/"+self.slug+"/tablets/"+key, records)
|
59
|
+
resp = client.post("/v1/keyspaces/"+self.slug+"/tablets/"+CGI.escape(key), records)
|
60
|
+
|
61
|
+
if resp.response.code != "202"
|
62
|
+
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Patches the existing records in a tablet with a net set of records. The
|
67
|
+
# criteria parameter indicates which records to match existing records on.
|
68
|
+
# In the Reflect API, if no existing records match the supplied records
|
69
|
+
# then those records are dropped.
|
70
|
+
#
|
71
|
+
# @param String key the key to create
|
72
|
+
# @param Array|Hash records the records to create
|
73
|
+
# @param Array criteria an array of field names within a record to match
|
74
|
+
#
|
75
|
+
def patch(key, records, criteria)
|
76
|
+
resp = client.patch("/v1/keyspaces/"+self.slug+"/tablets/"+CGI.escape(key), records, "X-Criteria" => criteria.join(", "))
|
77
|
+
|
78
|
+
if resp.response.code != "202"
|
79
|
+
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
80
|
+
end
|
52
81
|
end
|
53
82
|
end
|
54
83
|
end
|
data/lib/reflect/version.rb
CHANGED
data/lib/reflect.rb
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
$:.unshift(File.expand_path("../", __FILE__))
|
2
2
|
|
3
|
+
require 'reflect/request_error'
|
3
4
|
require 'reflect/keyspace'
|
4
5
|
require 'reflect/field'
|
5
6
|
require 'reflect/client'
|
6
7
|
|
8
|
+
module Reflect
|
9
|
+
def self._format_error_message(resp)
|
10
|
+
"An error occured with the request. Status: #{resp.response.code} Error: #{_extract_error_message(resp)}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def self._extract_error_message(resp)
|
14
|
+
begin
|
15
|
+
json = JSON.parse(resp.body)
|
16
|
+
json["error"]
|
17
|
+
rescue JSON::ParserError
|
18
|
+
# TODO: Report this?
|
19
|
+
""
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Heller
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/reflect/client.rb
|
63
63
|
- lib/reflect/field.rb
|
64
64
|
- lib/reflect/keyspace.rb
|
65
|
+
- lib/reflect/request_error.rb
|
65
66
|
- lib/reflect/version.rb
|
66
67
|
- reflect.gemspec
|
67
68
|
homepage: http://github.com/reflect/reflect-rb
|