reflect 0.1.4 → 0.2.0
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 +23 -3
- data/lib/reflect/client.rb +0 -11
- data/lib/reflect/parameter.rb +13 -0
- data/lib/reflect/version.rb +1 -1
- metadata +3 -5
- data/lib/reflect/field.rb +0 -19
- data/lib/reflect/key_list.rb +0 -21
- data/lib/reflect/keyspace.rb +0 -144
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8195355dc7c3a4cc55fb41608d89c917f613ad7d
|
4
|
+
data.tar.gz: 40ffa0b99ac7b34ae6e74310ceb7441188d76256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cd4a2ae7c8e72e656e307fc95e0a8ed604036c99d7d2685866760adbb26038949a21d160c65c5701f760d82126d0de0bf82349bf3ef0e740bcfd467920645c7
|
7
|
+
data.tar.gz: aedb80cdd4c7f38ab93fa4272b73cddc21cff62e97b4ebcc4d63cf3e67a78275193adf2370a5194140715b2cf6b9332722a738fb8ffb6f2c8403625da67a3eaa
|
data/lib/reflect.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
$:.unshift(File.expand_path("../", __FILE__))
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'openssl'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
require 'reflect/parameter'
|
4
7
|
require 'reflect/request_error'
|
5
|
-
require 'reflect/keyspace'
|
6
|
-
require 'reflect/field'
|
7
8
|
require 'reflect/client'
|
8
9
|
|
9
10
|
module Reflect
|
@@ -28,4 +29,23 @@ module Reflect
|
|
28
29
|
def self.logger
|
29
30
|
@logger ||= Logger.new("/dev/null")
|
30
31
|
end
|
32
|
+
|
33
|
+
def self.generate_token(secret_key, parameters=[])
|
34
|
+
data = parameters.map do |param|
|
35
|
+
is_arr = param.value.is_a? Array
|
36
|
+
|
37
|
+
val = if !is_arr then param.value.to_s else '' end
|
38
|
+
vals = if is_arr then param.value.map(&:to_s).sort else [] end
|
39
|
+
|
40
|
+
JSON.generate([param.field, param.op, val, vals])
|
41
|
+
end
|
42
|
+
|
43
|
+
digest = OpenSSL::Digest.new('sha256')
|
44
|
+
hmac = OpenSSL::HMAC.new(secret_key, digest)
|
45
|
+
.update("V2\n")
|
46
|
+
.update(data.sort.join("\n"))
|
47
|
+
.digest
|
48
|
+
|
49
|
+
"=2=#{Base64.encode64(hmac).strip}"
|
50
|
+
end
|
31
51
|
end
|
data/lib/reflect/client.rb
CHANGED
@@ -13,17 +13,6 @@ module Reflect
|
|
13
13
|
@token = token
|
14
14
|
end
|
15
15
|
|
16
|
-
def keyspace(slug)
|
17
|
-
res = get("/v1/keyspaces/#{slug}")
|
18
|
-
|
19
|
-
if res.response.code == "200"
|
20
|
-
Keyspace.new(self, JSON.parse(res.body))
|
21
|
-
else
|
22
|
-
# TODO: What happens if we failed to look this up or whatever?
|
23
|
-
raise Reflect::RequestError, Reflect._format_error_message(res)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
16
|
def get(path)
|
28
17
|
self.class.get(URI.encode(path), options)
|
29
18
|
end
|
data/lib/reflect/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reflect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Heller
|
@@ -60,9 +60,7 @@ extra_rdoc_files: []
|
|
60
60
|
files:
|
61
61
|
- lib/reflect.rb
|
62
62
|
- lib/reflect/client.rb
|
63
|
-
- lib/reflect/
|
64
|
-
- lib/reflect/key_list.rb
|
65
|
-
- lib/reflect/keyspace.rb
|
63
|
+
- lib/reflect/parameter.rb
|
66
64
|
- lib/reflect/request_error.rb
|
67
65
|
- lib/reflect/version.rb
|
68
66
|
- reflect.gemspec
|
@@ -85,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
83
|
version: '0'
|
86
84
|
requirements: []
|
87
85
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.6.10
|
89
87
|
signing_key:
|
90
88
|
specification_version: 3
|
91
89
|
summary: Reflect.io API Ruby client
|
data/lib/reflect/field.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Reflect
|
2
|
-
class Field
|
3
|
-
attr_accessor :name
|
4
|
-
attr_accessor :column_type
|
5
|
-
attr_accessor :type
|
6
|
-
attr_accessor :description
|
7
|
-
attr_accessor :fields
|
8
|
-
attr_accessor :created_at
|
9
|
-
attr_accessor :updated_at
|
10
|
-
|
11
|
-
def initialize(client, attrs={})
|
12
|
-
@client = client
|
13
|
-
|
14
|
-
attrs.each do |k, v|
|
15
|
-
self.send("#{k}=".to_s, v)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/reflect/key_list.rb
DELETED
@@ -1,21 +0,0 @@
|
|
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
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'time'
|
2
|
-
require 'reflect/field'
|
3
|
-
|
4
|
-
module Reflect
|
5
|
-
class Keyspace
|
6
|
-
attr_reader :client
|
7
|
-
|
8
|
-
attr_accessor :name
|
9
|
-
attr_accessor :slug
|
10
|
-
attr_accessor :statistics_key
|
11
|
-
attr_accessor :description
|
12
|
-
attr_accessor :fields
|
13
|
-
attr_accessor :status
|
14
|
-
attr_accessor :created_at
|
15
|
-
attr_accessor :updated_at
|
16
|
-
|
17
|
-
def initialize(client, attrs={})
|
18
|
-
@client = client
|
19
|
-
|
20
|
-
# If we have fields, we'll need to populate them individually.
|
21
|
-
fields = attrs.delete("fields")
|
22
|
-
|
23
|
-
attrs['updated_at'] = Time.parse(attrs['updated_at']) if attrs['updated_at']
|
24
|
-
attrs['created_at'] = Time.parse(attrs['created_at']) if attrs['created_at']
|
25
|
-
|
26
|
-
attrs.each do |k, v|
|
27
|
-
self.send("#{k}=".to_s, v)
|
28
|
-
end
|
29
|
-
|
30
|
-
if fields
|
31
|
-
self.fields = fields.map { |f| Field.new(f) }
|
32
|
-
end
|
33
|
-
end
|
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
|
-
|
51
|
-
# Appends records to a tablet. If the tablet doesn't exist it will be
|
52
|
-
# created. records can be either a single object or an array of objects. A
|
53
|
-
# single object represents a single row.
|
54
|
-
#
|
55
|
-
# @param String key the key to create
|
56
|
-
# @param Array|Hash records the records to create
|
57
|
-
#
|
58
|
-
def append(key, records)
|
59
|
-
resp = client.put(path(slug, key), records)
|
60
|
-
|
61
|
-
if resp.response.code != "202"
|
62
|
-
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Replaces the existing records in a tablet with a net set of records.
|
67
|
-
# records can be either a single object or an array of objects. A single
|
68
|
-
# object represents a single row.
|
69
|
-
#
|
70
|
-
# @param String key the key to create
|
71
|
-
# @param Array|Hash records the records to create
|
72
|
-
#
|
73
|
-
def replace(key, records)
|
74
|
-
resp = client.post(path(slug, key), records)
|
75
|
-
|
76
|
-
if resp.response.code != "202"
|
77
|
-
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
# Patches the existing records in a tablet with a net set of records. The
|
82
|
-
# criteria parameter indicates which records to match existing records on.
|
83
|
-
# In the Reflect API, if no existing records match the supplied records
|
84
|
-
# then those records are dropped.
|
85
|
-
#
|
86
|
-
# @param String key the key to create
|
87
|
-
# @param Array|Hash records the records to create
|
88
|
-
# @param Array criteria an array of field names within a record to match
|
89
|
-
#
|
90
|
-
def patch(key, records, criteria)
|
91
|
-
resp = client.patch(path(slug, key), records, "X-Criteria" => criteria.join(", "))
|
92
|
-
|
93
|
-
if resp.response.code != "202"
|
94
|
-
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# Patch the existing records in a tablet with a new set of records and
|
99
|
-
# insert any that aren't matched. The criteria parameter indicates which
|
100
|
-
# records to match existing records on.
|
101
|
-
#
|
102
|
-
# @param String key the key to create
|
103
|
-
# @param Array|Hash records the records to create
|
104
|
-
# @param Array criteria an array of field names within a record to match
|
105
|
-
#
|
106
|
-
def upsert(key, records, criteria)
|
107
|
-
headers = {
|
108
|
-
"X-Criteria" => criteria.join(", "),
|
109
|
-
"X-Insert-Missing" => true
|
110
|
-
}
|
111
|
-
|
112
|
-
resp = client.patch(path(slug, key), records, headers)
|
113
|
-
|
114
|
-
if resp.response.code != "202"
|
115
|
-
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
|
120
|
-
# Deletes a key within a keyspace.
|
121
|
-
#
|
122
|
-
# @param String key the key to delete
|
123
|
-
#
|
124
|
-
def delete(key)
|
125
|
-
resp = client.delete(path(slug, key))
|
126
|
-
|
127
|
-
if resp.response.code != "202"
|
128
|
-
raise Reflect::RequestError, Reflect._format_error_message(resp)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
|
134
|
-
def path(slug, key)
|
135
|
-
"/v1/keyspaces/#{slug}/tablets/#{key}"
|
136
|
-
end
|
137
|
-
|
138
|
-
def keys_path(slug, continuation=nil)
|
139
|
-
base = "/v1/keyspaces/#{slug}/keys"
|
140
|
-
base += "?next=#{continuation}" if continuation
|
141
|
-
base
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|