arangorb3 0.0.10

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.
data/lib/Traversal.rb ADDED
@@ -0,0 +1,224 @@
1
+ # === TRAVERSAL ===
2
+
3
+ module Arango
4
+ class Traversal
5
+ include Arango::Helper_Error
6
+ include Arango::Helper_Return
7
+ include Arango::Database_Return
8
+
9
+ def initialize(body: {}, edgeCollection: nil,
10
+ sort: nil, direction: nil, minDepth: nil,
11
+ vertex:, visitor: nil, itemOrder: nil, strategy: nil,
12
+ filter: nil, init: nil, maxIterations: nil, maxDepth: nil,
13
+ uniqueness: nil, order: nil, expander: nil)
14
+ satisfy_category?(direction, ["outbound", "inbound", "any", nil])
15
+ satisfy_category?(itemOrder, ["forward", "backward", nil])
16
+ satisfy_category?(strategy, ["depthfirst", "breadthfirst", nil])
17
+ satisfy_category?(order, ["preorder", "postorder", "preorder-expander", nil])
18
+ body[:sort] ||= sort
19
+ body[:direction] ||= direction
20
+ body[:maxDepth] ||= maxDepth
21
+ body[:minDepth] ||= minDepth
22
+ body[:startVertex] ||= vertex
23
+ body[:visitor] ||= visitor
24
+ body[:itemOrder] ||= itemOrder
25
+ body[:strategy] ||= strategy
26
+ body[:filter] ||= filter
27
+ body[:init] ||= init
28
+ body[:maxiterations] ||= maxIterations
29
+ body[:uniqueness] ||= uniqueness
30
+ body[:order] ||= order
31
+ body[:expander] ||= expander
32
+ body[:edgeCollection] ||= edgeCollection
33
+ assign_body(body)
34
+ @vertices = nil
35
+ @paths = nil
36
+ end
37
+
38
+ # === DEFINE ===
39
+
40
+ attr_accessor :sort, :maxDepth, :minDepth, :visitor, :filter, :init, :maxiterations, :uniqueness, :expander
41
+ attr_reader :vertices, :paths, :direction, :itemOrder,
42
+ :strategy, :order, :database, :server, :vertex, :edgeCollection, :graph, :body, :collection
43
+ alias startVertex vertex
44
+
45
+ def body=(body)
46
+ @body = body
47
+ @sort = body[:sort] || @sort
48
+ @direction = body[:direction] || @direction
49
+ @maxDepth = body[:maxDepth] || @maxDepth
50
+ @minDepth = body[:minDepth] || @minDepth
51
+ return_vertex(body[:startVertex] || @vertex)
52
+ @visitor = body[:visitor] || @visitor
53
+ @itemOrder = body[:itemOrder] || @itemOrder
54
+ @strategy = body[:strategy] || @strategy
55
+ @filter = body[:filter] || @filter
56
+ @init = body[:init] || @init
57
+ @maxIterations = body[:maxiterations] || @maxIterations
58
+ @uniqueness = body[:uniqueness] || @uniqueness
59
+ @order = body[:order] || @order
60
+ @expander = body[:expander] || @expander
61
+ return_edgeCollection(body[:edgeCollection] || @edgeCollection)
62
+ end
63
+ alias assign_body body=
64
+
65
+ def direction=(direction)
66
+ satisfy_category?(direction, ["outbound", "inbound", "any", nil])
67
+ @direction = direction
68
+ end
69
+
70
+ def itemOrder=(itemOrder)
71
+ satisfy_category?(itemOrder, ["forward", "backward", nil])
72
+ @itemOrder = itemOrder
73
+ end
74
+
75
+ def strategy=(strategy)
76
+ satisfy_category?(strategy, ["depthfirst", "breadthfirst", nil])
77
+ @strategy = strategy
78
+ end
79
+
80
+ def order=(order)
81
+ satisfy_category?(order, ["preorder", "postorder", "preorder-expander", nil])
82
+ @order = order
83
+ end
84
+
85
+ def startVertex=(vertex)
86
+ case vertex
87
+ when Arango::Edge
88
+ when Arango::Document, Arango::Vertex
89
+ @vertex = vertex
90
+ @collection = @vertex.collection
91
+ @database = @collection.database
92
+ @graph = @collection.graph
93
+ @server = @database.server
94
+ return
95
+ when String
96
+ if @database.nil?
97
+ raise Arango::Error.new err: :database_undefined_for_traversal
98
+ elsif vertex.include? "/"
99
+ val = vertex.split("/")
100
+ @collection = Arango::Collection.new(database: @database, name: val[0])
101
+ @vertex = Arango::Document.new(collection: @collection, name: val[1])
102
+ return
103
+ end
104
+ end
105
+ raise Arango::Error.new err: :wrong_start_vertex_type
106
+ end
107
+ alias vertex= startVertex=
108
+ alias return_vertex startVertex=
109
+
110
+ def edgeCollection=(collection)
111
+ return nil if collection.nil?
112
+ satisfy_class?(collection, [Arango::Collection, String])
113
+ case collection
114
+ when Arango::Collection
115
+ if collection.type != :edge
116
+ raise Arango::Error.new err: :edge_collection_should_be_of_type_edge
117
+ end
118
+ @edgeCollection = collection
119
+ when String
120
+ collection_instance = Arango::Collection.new(name: edgedef[:collection],
121
+ database: @database, type: :edge, graph: @graph)
122
+ @edgeCollection = collection_instance
123
+ end
124
+ end
125
+ alias return_edgeCollection edgeCollection=
126
+
127
+ alias vertex= startVertex=
128
+ alias vertex startVertex
129
+ alias max maxDepth
130
+ alias max= maxDepth=
131
+ alias min minDepth
132
+ alias min= minDepth=
133
+
134
+ def in
135
+ @direction = "inbound"
136
+ end
137
+
138
+ def out
139
+ @direction = "outbound"
140
+ end
141
+
142
+ def any
143
+ @direction = "any"
144
+ end
145
+
146
+ # === TO HASH ===
147
+
148
+ def to_h
149
+ {
150
+ "sort": @sort,
151
+ "direction": @direction,
152
+ "maxDepth": @maxDepth,
153
+ "minDepth": @minDepth,
154
+ "visitor": @visitor,
155
+ "itemOrder": @itemOrder,
156
+ "strategy": @strategy,
157
+ "filter": @filter,
158
+ "init": @init,
159
+ "maxiterations": @maxiterations,
160
+ "uniqueness": @uniqueness,
161
+ "order": @order,
162
+ "expander": @expander,
163
+ "vertices": @vertices&.map{|x| x.id},
164
+ "paths": @paths&.map do |x|
165
+ {
166
+ "edges": x[:edges]&.map{|e| e.id},
167
+ "vertices": x[:vertices]&.map{|v| v.id}
168
+ }
169
+ end,
170
+ "idCache": @idCache,
171
+ "startVertex": @vertex&.id,
172
+ "graph": @graph&.name,
173
+ "edgeCollection": @edgeCollection&.name,
174
+ "database": @database.name
175
+ }.delete_if{|k,v| v.nil?}
176
+ end
177
+
178
+ # === EXECUTE ===
179
+
180
+ def execute
181
+ body = {
182
+ "sort": @sort,
183
+ "direction": @direction,
184
+ "maxDepth": @maxDepth,
185
+ "minDepth": @minDepth,
186
+ "startVertex": @vertex&.id,
187
+ "visitor": @visitor,
188
+ "itemOrder": @itemOrder,
189
+ "strategy": @strategy,
190
+ "filter": @filter,
191
+ "init": @init,
192
+ "maxiterations": @maxiterations,
193
+ "uniqueness": @uniqueness,
194
+ "order": @order,
195
+ "graphName": @graph&.name,
196
+ "expander": @expander,
197
+ "edgeCollection": @edgeCollection&.name
198
+ }
199
+ result = @database.request("POST", "_api/traversal", body: body)
200
+ return result if @server.async != false
201
+ @vertices = result[:result][:visited][:vertices].map do |x|
202
+ collection = Arango::Collection.new(name: x[:_id].split("/")[0],
203
+ database: @database)
204
+ Arango::Document.new(name: x[:_key], collection: collection, body: x)
205
+ end
206
+ @paths = result[:result][:visited][:paths].map do |x|
207
+ {
208
+ "edges": x[:edges].map do |e|
209
+ collection_edge = Arango::Collection.new(name: e[:_id].split("/")[0],
210
+ database: @database, type: :edge)
211
+ Arango::Document.new(name: e[:_key], collection: collection_edge,
212
+ body: e, from: e[:_from], to: e[:_to])
213
+ end,
214
+ "vertices": x[:vertices].map do |v|
215
+ collection_vertex = Arango::Collection.new(name: v[:_id].split("/")[0],
216
+ database: @database)
217
+ Arango::Document.new(name: v[:_key], collection: collection_vertex, body: v)
218
+ end
219
+ }
220
+ end
221
+ return return_directly?(result) ? result : self
222
+ end
223
+ end
224
+ end
data/lib/User.rb ADDED
@@ -0,0 +1,197 @@
1
+ # === USER ===
2
+
3
+ module Arango
4
+ class User
5
+ include Arango::Helper_Error
6
+ include Arango::Helper_Return
7
+ include Arango::Server_Return
8
+
9
+ def self.new(*args)
10
+ hash = args[0]
11
+ super unless hash.is_a?(Hash)
12
+ database = hash[:database]
13
+ if database.is_a?(Arango::Database) && database.server.active_cache
14
+ cache_name = hash[:name]
15
+ cached = database.server.cache.cache.dig(:user, cache_name)
16
+ if cached.nil?
17
+ hash[:cache_name] = cache_name
18
+ return super
19
+ else
20
+ body = {}
21
+ [:password, :extra, :active].each{|k| body[k] ||= hash[k]}
22
+ cached.assign_attributes(body)
23
+ return cached
24
+ end
25
+ end
26
+ super
27
+ end
28
+
29
+ def initialize(server:, password: "", name:, extra: {}, active: nil, cache_name: nil)
30
+ assign_server(server)
31
+ unless cache_name.nil?
32
+ @cache_name = cache_name
33
+ @server.cache.save(:user, cache_name, self)
34
+ end
35
+ @password = password
36
+ @name = name
37
+ @extra = extra
38
+ @active = active
39
+ end
40
+
41
+ # === DEFINE ===
42
+
43
+ attr_accessor :name, :extra, :active
44
+ attr_reader :server, :body, :cache_name
45
+ attr_writer :password
46
+ alias user name
47
+ alias user= name=
48
+
49
+ def body=(result)
50
+ @body = result
51
+ @password = result[:password] || @password
52
+ @name = result[:user] || @name
53
+ @extra = result[:extra] || @extra
54
+ @active = result[:active].nil? ? @active : result[:active]
55
+ if @server.active_cache && @cache_name.nil?
56
+ @cache_name = @name
57
+ @server.cache.save(:user, @cache_name, self)
58
+ end
59
+ end
60
+ alias assign_attributes body=
61
+
62
+ # === TO HASH ===
63
+
64
+ def to_h
65
+ {
66
+ "user": @name,
67
+ "extra": @extra,
68
+ "active": @active,
69
+ "cache_name": @cache_name,
70
+ "server": @server.base_uri
71
+ }.delete_if{|k,v| v.nil?}
72
+ end
73
+
74
+ def [](database)
75
+ if self.databases[database.to_sym] == "rw"
76
+ Arango::Database.new name: database, server: @server
77
+ else
78
+ "This User does not have access to Database #{database}."
79
+ end
80
+ end
81
+ alias database []
82
+
83
+ # == USER ACTION ==
84
+
85
+ def create(password: @password, active: @active, extra: @extra)
86
+ body = {
87
+ "user": @name,
88
+ "passwd": password,
89
+ "extra": extra,
90
+ "active": active
91
+ }
92
+ result = @server.request("POST", "_api/user", body: body)
93
+ return_element(result)
94
+ end
95
+
96
+ def retrieve
97
+ result = @server.request("GET", "_api/user/#{@name}", body: body)
98
+ return_element(result)
99
+ end
100
+
101
+ def replace(password: @password, active: @active, extra: @extra)
102
+ body = {
103
+ "passwd": password,
104
+ "active": active,
105
+ "extra": extra
106
+ }
107
+ result = @server.request("PUT", "_api/user/#{@name}", body: body)
108
+ @password = password
109
+ return_element(result)
110
+ end
111
+
112
+ def update(password: @password, active: @active, extra: @extra)
113
+ body = {
114
+ "passwd": password,
115
+ "active": active,
116
+ "extra": extra
117
+ }
118
+ result = @server.request("PATCH", "_api/user/#{@name}", body: body)
119
+ @password = password
120
+ return_element(result)
121
+ end
122
+
123
+ def destroy
124
+ result = @server.request("DELETE", "_api/user/#{@name}")
125
+ return return_directly?(result) ? result : true
126
+ end
127
+
128
+ # == ACCESS ==
129
+
130
+ def addDatabaseAccess(grant:, database:)
131
+ satisfy_category?(grant, ["rw", "ro", "none"])
132
+ satisfy_class?(database, [Arango::Database, String])
133
+ database = database.name if database.is_a?(Arango::Database)
134
+ body = {"grant": grant}
135
+ result = @server.request("PUT", "_api/user/#{@name}/database/#{database}",
136
+ body: body)
137
+ return return_directly?(result) ? result : result[database.to_sym]
138
+ end
139
+
140
+ def grant(database:)
141
+ addDatabaseAccess(grant: "rw", database: database)
142
+ end
143
+
144
+ def addCollectionAccess(grant:, database:, collection:)
145
+ satisfy_category?(grant, ["rw", "ro", "none"])
146
+ satisfy_class?(database, [Arango::Database, String])
147
+ satisfy_class?(collection, [Arango::Collection, String])
148
+ database = database.name if database.is_a?(Arango::Database)
149
+ collection = collection.name if collection.is_a?(Arango::Collection)
150
+ body = {"grant": grant}
151
+ result = @server.request("PUT", "_api/user/#{@name}/database/#{database}/#{collection}",
152
+ body: body)
153
+ return return_directly?(result) ? result : result[:"#{database}/#{collection}"]
154
+ end
155
+
156
+ def revokeDatabaseAccess(database:)
157
+ satisfy_class?(database, [Arango::Database, String])
158
+ database = database.name if database.is_a?(Arango::Database)
159
+ result = @server.request("DELETE", "_api/user/#{@name}/database/#{database}")
160
+ return return_directly?(result) ? result : true
161
+ end
162
+ alias revoke revokeDatabaseAccess
163
+
164
+ def revokeCollectionAccess(database:, collection:)
165
+ satisfy_class?(database, [Arango::Database, String])
166
+ satisfy_class?(collection, [Arango::Collection, String])
167
+ database = database.name if database.is_a?(Arango::Database)
168
+ collection = collection.name if collection.is_a?(Arango::Collection)
169
+ result = @server.request("DELETE", "_api/user/#{@name}/database/#{database}/#{collection}")
170
+ return return_directly?(result) ? result : true
171
+ end
172
+
173
+ def listAccess(full: nil)
174
+ query = {"full": full}
175
+ result = @server.request("GET", "_api/user/#{@name}/database", query: query)
176
+ return return_directly?(result) ? result : result[:result]
177
+ end
178
+ alias databases listAccess
179
+
180
+ def databaseAccess(database:)
181
+ satisfy_class?(database, [Arango::Database, String])
182
+ database = database.name if database.is_a?(Arango::Database)
183
+ result = @server.request("GET", "_api/user/#{@name}/database/#{database}")
184
+ return return_directly?(result) ? result : result[:result]
185
+ end
186
+
187
+ def collectionAccess(database:, collection:)
188
+ satisfy_class?(database, [Arango::Database, String])
189
+ satisfy_class?(collection, [Arango::Collection, String])
190
+ database = database.name if database.is_a?(Arango::Database)
191
+ collection = collection.name if collection.is_a?(Arango::Collection)
192
+ result = @server.request("GET", "_api/user/#{@name}/database/#{database}/#{collection}",
193
+ body: body)
194
+ return return_directly?(result) ? result : result[:result]
195
+ end
196
+ end
197
+ end
data/lib/Vertex.rb ADDED
@@ -0,0 +1,127 @@
1
+ # === GRAPH VERTEX ===
2
+
3
+ module Arango
4
+ class Vertex < Arango::Document
5
+ def initialize(name: nil, collection:, body: {}, rev: nil, cache_name: nil)
6
+ assign_collection(collection)
7
+ unless cache_name.nil?
8
+ @cache_name = cache_name
9
+ @server.cache.save(:document, cache_name, self)
10
+ end
11
+ body[:_key] ||= name
12
+ body[:_rev] ||= rev
13
+ body[:_id] ||= "#{@collection.name}/#{name}" unless name.nil?
14
+ assign_attributes(body)
15
+ end
16
+
17
+ # === DEFINE ===
18
+
19
+ attr_reader :collection, :database, :server, :graph
20
+
21
+ def collection=(collection)
22
+ satisfy_class?(collection, [Arango::Collection])
23
+ if collection.graph.nil?
24
+ raise Arango::Error.new err: :collection_does_not_have_a_graph, data:
25
+ {"name_collection": collection.name, "graph": nil}
26
+ end
27
+ @collection = collection
28
+ @graph = @collection.graph
29
+ @database = @collection.database
30
+ @server = @database.server
31
+ end
32
+ alias assign_collection collection=
33
+
34
+ # == GET ==
35
+
36
+ def retrieve(if_match: false)
37
+ headers = {}
38
+ headers[:"If-Match"] = @body[:_rev] if if_match
39
+ result = @graph.request("GET", "vertex/#{@collection.name}/#{@body[:_key]}",
40
+ headers: headers, key: :vertex)
41
+ return_element(result)
42
+ end
43
+
44
+ # == POST ==
45
+
46
+ def create(body: {}, waitForSync: nil)
47
+ body = @body.merge(body)
48
+ query = {"waitForSync": waitForSync}
49
+ result = @graph.request("POST", "vertex/#{@collection.name}", body: body,
50
+ query: query, key: :vertex)
51
+ return result if @server.async != false
52
+ body2 = result.clone
53
+ body = body.merge(body2)
54
+ assign_attributes(body)
55
+ return return_directly?(result) ? result : self
56
+ end
57
+
58
+ # == PUT ==
59
+
60
+ def replace(body: {}, waitForSync: nil, keepNull: nil, if_match: false)
61
+ query = {
62
+ "waitForSync": waitForSync,
63
+ "keepNull": keepNull
64
+ }
65
+ headers = {}
66
+ headers[:"If-Match"] = @body[:_rev] if if_match
67
+ result = @graph.request("PUT", "vertex/#{@collection.name}/#{@body[:_key]}",
68
+ body: body, query: query, headers: headers, key: :vertex)
69
+ return result if @server.async != false
70
+ body2 = result.clone
71
+ body = body.merge(body2)
72
+ assign_attributes(body)
73
+ return return_directly?(result) ? result : self
74
+ end
75
+
76
+ def update(body: {}, waitForSync: nil, if_match: false, keepNull: nil)
77
+ query = {"waitForSync": waitForSync, "keepNull": keepNull}
78
+ headers = {}
79
+ headers[:"If-Match"] = @body[:_rev] if if_match
80
+ result = @graph.request("PATCH", "vertex/#{@collection.name}/#{@body[:_key]}", body: body,
81
+ query: query, headers: headers, key: :vertex)
82
+ return result if @server.async != false
83
+ body2 = result.clone
84
+ body = body.merge(body2)
85
+ body = @body.merge(body)
86
+ assign_attributes(body)
87
+ return return_directly?(result) ? result : self
88
+ end
89
+
90
+ # === DELETE ===
91
+
92
+ def destroy(waitForSync: nil, if_match: false)
93
+ query = {"waitForSync": waitForSync}
94
+ headers = {}
95
+ headers[:"If-Match"] = @body[:_rev] if if_match
96
+ result = @graph.request("DELETE", "vertex/#{@collection.name}/#{@body[:_key]}",
97
+ query: query, headers: headers)
98
+ return_delete(result)
99
+ end
100
+
101
+ # === TRAVERSAL ===
102
+
103
+ def traversal(body: {}, sort: nil, direction: nil, minDepth: nil,
104
+ visitor: nil, itemOrder: nil, strategy: nil,
105
+ filter: nil, init: nil, maxIterations: nil, maxDepth: nil,
106
+ uniqueness: nil, order: nil, expander: nil,
107
+ edgeCollection: nil)
108
+ Arango::Traversal.new(body: body,
109
+ sort: sort, direction: direction, minDepth: minDepth,
110
+ vertex: self, visitor: visitor,itemOrder: itemOrder,
111
+ strategy: strategy, filter: filter, init: init,
112
+ maxIterations: maxIterations, maxDepth: maxDepth,
113
+ uniqueness: uniqueness, order: order,
114
+ expander: expander, edgeCollection: edgeCollection)
115
+ end
116
+
117
+ # === WRONG ===
118
+
119
+ def from=(arg)
120
+ raise Arango::Error.new err: you_cannot_assign_from_or_to_to_a_vertex
121
+ end
122
+ alias to= from=
123
+ alias to from=
124
+ alias toR from=
125
+ alias fromR from=
126
+ end
127
+ end
data/lib/View.rb ADDED
@@ -0,0 +1,151 @@
1
+ # ==== DOCUMENT ====
2
+
3
+ module Arango
4
+ class View
5
+ include Arango::Helper_Error
6
+ include Arango::Helper_Return
7
+ include Arango::Database_Return
8
+
9
+ def self.new(*args)
10
+ hash = args[0]
11
+ super unless hash.is_a?(Hash)
12
+ database = hash[:database]
13
+ if database.is_a?(Arango::Database) && database.server.active_cache && !hash[:id].nil?
14
+ cache_name = "#{database.name}/#{hash[:id]}"
15
+ cached = database.server.cache.cache.dig(:view, cache_name)
16
+ if cached.nil?
17
+ hash[:cache_name] = cache_name
18
+ return super
19
+ else
20
+ body = {}
21
+ [:type, :name].each{|k| body[k] ||= hash[k]}
22
+ cached.assign_attributes(body)
23
+ return cached
24
+ end
25
+ end
26
+ super
27
+ end
28
+
29
+ def initialize(database:, type: "arangosearch", name:, id: nil, cache_name: nil)
30
+ assign_database(database)
31
+ unless cache_name.nil?
32
+ @cache_name = cache_name
33
+ @server.cache.save(:view, cache_name, self)
34
+ end
35
+ satisfy_category?(type, ["arangosearch"])
36
+ @type = type
37
+ @name = name
38
+ @links = {}
39
+ @id = id
40
+ end
41
+
42
+ # === DEFINE ===
43
+
44
+ attr_reader :type, :links, :database, :cache_name
45
+ attr_accessor :id, :name
46
+
47
+ def type=(type)
48
+ satisfy_category?(type, ["arangosearch"])
49
+ @type = type
50
+ end
51
+ alias assign_type type=
52
+
53
+ def addLink(collection:, analyzers: nil, fields: {}, includeAllFields: nil, trackListPositions: nil, storeValues: nil)
54
+ satisfy_class?(collection, [Arango::Collection, String])
55
+ collection_name = collection.is_a?(String) ? collection : collection.name
56
+ satisfy_category?(storeValues, ["none", "id", nil])
57
+ @links[collection_name] = {
58
+ analyzers: analyzers,
59
+ fields: fields,
60
+ includeAllFields: includeAllFields,
61
+ trackListPositions: trackListPositions,
62
+ storeValues: storeValues
63
+ }
64
+ @links[collection_name].delete_if{|k,v| v.nil?}
65
+ end
66
+
67
+ def to_h
68
+ {
69
+ "name": @name,
70
+ "id": @id,
71
+ "type": @type,
72
+ "links": @links,
73
+ "cache_name": @cache_name,
74
+ "database": @database.name
75
+ }.delete_if{|k,v| v.nil?}
76
+ end
77
+
78
+ def body=(result)
79
+ @body = result
80
+ @id = result[:id] || @id
81
+ @type = assign_type(result[:type] || @type)
82
+ @links = result[:links] || @links
83
+ @name = result[:name] || name
84
+ if @server.active_cache && @cache_name.nil?
85
+ @cache_name = "#{@database.name}/#{@id}"
86
+ @server.cache.save(:task, @cache_name, self)
87
+ end
88
+ end
89
+ alias assign_attributes body=
90
+
91
+ # === COMMANDS ===
92
+
93
+ def retrieve
94
+ result = @database.request("GET", "_api/view/#{@name}")
95
+ return result.headers[:"x-arango-async-id"] if @server.async == :store
96
+ return_element(result)
97
+ end
98
+
99
+ def manage_properties(method, url, consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil)
100
+ body = {
101
+ properties: {
102
+ links: @links.empty? ? nil : @links,
103
+ consolidationIntervalMsec: consolidationIntervalMsec,
104
+ consolidationPolicy: {
105
+ threshold: threshold,
106
+ segmentThreshold: segmentThreshold
107
+ },
108
+ cleanupIntervalStep: cleanupIntervalStep
109
+ }
110
+ }
111
+ if method == "POST"
112
+ body[:type] = @type
113
+ body[:name] = @name
114
+ end
115
+ body[:properties][:consolidationPolicy].delete_if{|k,v| v.nil?}
116
+ body[:properties].delete(:consolidationPolicy) if body[:properties][:consolidationPolicy].empty?
117
+ body[:properties].delete_if{|k,v| v.nil?}
118
+ body.delete(:properties) if body[:properties].empty?
119
+ body.delete_if{|k,v| v.nil?}
120
+ result = @database.request(method, url, body: body)
121
+ return_element(result)
122
+ end
123
+ private :manage_properties
124
+
125
+ def create(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil)
126
+ manage_properties("POST", "_api/view", consolidationIntervalMsec: consolidationIntervalMsec, threshold: threshold, segmentThreshold: segmentThreshold, cleanupIntervalStep: cleanupIntervalStep)
127
+ end
128
+
129
+ def replaceProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil)
130
+ manage_properties("PUT", "_api/view/#{@name}/properties", consolidationIntervalMsec: consolidationIntervalMsec, threshold: threshold, segmentThreshold: segmentThreshold, cleanupIntervalStep: cleanupIntervalStep)
131
+ end
132
+
133
+ def updateProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil)
134
+ manage_properties("PATCH", "_api/view/#{@name}/properties", consolidationIntervalMsec: consolidationIntervalMsec, threshold: threshold, segmentThreshold: segmentThreshold, cleanupIntervalStep: cleanupIntervalStep)
135
+ end
136
+
137
+ def rename name:
138
+ body = {name: name}
139
+ result = @database.request("PUT", "_api/view/#{@name}/rename", body: body)
140
+ return_element(result)
141
+ end
142
+
143
+ def properties
144
+ @database.request("GET", "_api/view/#{@name}/properties")
145
+ end
146
+
147
+ def destroy
148
+ @database.request("DELETE", "_api/view/#{@name}", key: :result)
149
+ end
150
+ end
151
+ end