arangorb 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/ArangoRB.gemspec +2 -2
  3. data/README.md +418 -123
  4. data/lib/ArangoRB_AQL.rb +90 -103
  5. data/lib/ArangoRB_Col.rb +476 -159
  6. data/lib/ArangoRB_DB.rb +305 -79
  7. data/lib/ArangoRB_Doc.rb +112 -114
  8. data/lib/ArangoRB_Edg.rb +81 -62
  9. data/lib/ArangoRB_Gra.rb +125 -76
  10. data/lib/ArangoRB_Index.rb +144 -0
  11. data/lib/ArangoRB_Ser.rb +439 -18
  12. data/lib/ArangoRB_Task.rb +136 -0
  13. data/lib/ArangoRB_Tra.rb +47 -42
  14. data/lib/ArangoRB_Tran.rb +48 -0
  15. data/lib/ArangoRB_User.rb +152 -0
  16. data/lib/ArangoRB_Ver.rb +74 -57
  17. data/lib/arangorb.rb +4 -0
  18. data/spec/arangoRB_helper.rb +2 -9
  19. data/spec/arangoRestart_helper.rb +14 -0
  20. data/spec/lib/{arangoAQL_helper.rb → 0.1.0/arangoAQL_helper.rb} +2 -21
  21. data/spec/lib/{arangoC_helper.rb → 0.1.0/arangoC_helper.rb} +40 -19
  22. data/spec/lib/{arangoDB_helper.rb → 0.1.0/arangoDB_helper.rb} +13 -13
  23. data/spec/lib/{arangoDoc_helper.rb → 0.1.0/arangoDoc_helper.rb} +10 -23
  24. data/spec/lib/0.1.0/arangoE_helper.rb +50 -0
  25. data/spec/lib/{arangoG_helper.rb → 0.1.0/arangoG_helper.rb} +7 -21
  26. data/spec/lib/0.1.0/arangoS_helper.rb +37 -0
  27. data/spec/lib/0.1.0/arangoT_helper.rb +48 -0
  28. data/spec/lib/{arangoV_helper.rb → 0.1.0/arangoV_helper.rb} +6 -22
  29. data/spec/lib/1.0.0/arangoC_helper.rb +73 -0
  30. data/spec/lib/1.0.0/arangoDB_helper.rb +81 -0
  31. data/spec/lib/1.0.0/arangoI_helper.rb +43 -0
  32. data/spec/lib/1.0.0/arangoS_helper.rb +196 -0
  33. data/spec/lib/1.0.0/arangoTa_helper.rb +49 -0
  34. data/spec/lib/1.0.0/arangoTr_helper.rb +15 -0
  35. data/spec/lib/1.0.0/arangoU_helper.rb +72 -0
  36. data/spec/lib/arangoRB_0.1.0_helper.rb +9 -0
  37. data/spec/lib/arangoRB_1.0.0_helper.rb +6 -0
  38. data/spec/spec_helper.rb +34 -0
  39. metadata +28 -15
  40. data/spec/lib/arangoE_helper.rb +0 -70
  41. data/spec/lib/arangoS_helper.rb +0 -28
  42. data/spec/lib/arangoT_helper.rb +0 -67
data/lib/ArangoRB_Doc.rb CHANGED
@@ -1,19 +1,21 @@
1
1
  # ==== DOCUMENT ====
2
2
 
3
- class ArangoDoc < ArangoS
4
- def initialize(key: nil, collection: @@collection, database: @@database, body: {}, from: nil, to: nil)
3
+ class ArangoDocument < ArangoServer
4
+ def initialize(key: nil, collection: @@collection, database: @@database, body: {}, from: nil, to: nil) # TESTED
5
5
  if collection.is_a?(String)
6
6
  @collection = collection
7
- elsif collection.is_a?(ArangoC)
7
+ elsif collection.is_a?(ArangoCollection)
8
8
  @collection = collection.collection
9
9
  else
10
- raise "collection should be a String or an ArangoC instance, not a #{collection.class}"
10
+ raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
11
11
  end
12
12
 
13
13
  if database.is_a?(String)
14
14
  @database = database
15
+ elsif database.is_a?(ArangoDatabase)
16
+ @database = database.database
15
17
  else
16
- raise "database should be a String, not a #{database.class}"
18
+ raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
17
19
  end
18
20
 
19
21
  if key.is_a?(String) || key.nil?
@@ -34,20 +36,20 @@ class ArangoDoc < ArangoS
34
36
 
35
37
  if from.is_a?(String)
36
38
  @body["_from"] = from
37
- elsif from.is_a?(ArangoDoc)
39
+ elsif from.is_a?(ArangoDocument)
38
40
  @body["_from"] = from.id
39
41
  elsif from.nil?
40
42
  else
41
- raise "from should be a String or an ArangoDoc instance, not a #{from.class}"
43
+ raise "from should be a String or an ArangoDocument instance, not a #{from.class}"
42
44
  end
43
45
 
44
46
  if to.is_a?(String)
45
47
  @body["_to"] = to
46
- elsif to.is_a?(ArangoDoc)
48
+ elsif to.is_a?(ArangoDocument)
47
49
  @body["_to"] = to.id
48
50
  elsif to.nil?
49
51
  else
50
- raise "to should be a String or an ArangoDoc instance, not a #{to.class}"
52
+ raise "to should be a String or an ArangoDocument instance, not a #{to.class}"
51
53
  end
52
54
  end
53
55
 
@@ -55,53 +57,49 @@ class ArangoDoc < ArangoS
55
57
 
56
58
  # === GET ===
57
59
 
58
- def retrieve
59
- result = self.class.get("/_db/#{@database}/_api/document/#{@id}").parsed_response
60
- if @@verbose
61
- @body = result unless result["error"]
62
- result
63
- else
64
- if result["error"]
65
- result["errorMessage"]
66
- else
67
- @body = result
68
- self
69
- end
70
- end
60
+ def retrieve # TESTED
61
+ result = self.class.get("/_db/#{@database}/_api/document/#{@id}", @@request)
62
+ self.return_result result: result
71
63
  end
72
64
 
73
- def retrieve_edges(collection: , direction: nil)
65
+ def retrieve_edges(collection: , direction: nil) # TESTED
74
66
  query = {"vertex" => @id, "direction" => direction }.delete_if{|k,v| v.nil?}
75
- new_Document = { :query => query }
67
+ request = @@request.merge({ :query => query })
76
68
  collection = collection.is_a?(String) ? collection : collection.collection
77
- result = self.class.get("/_db/#{@database}/_api/edges/#{collection}", new_Document).parsed_response
69
+ result = self.class.get("/_db/#{@database}/_api/edges/#{collection}", request)
70
+ return result.headers["x-arango-async-id"] if @@async == "store"
71
+ result = result.parsed_response
78
72
  @@verbose ? result : result["error"] ? result["errorMessage"] : result["edges"].map{|edge|
79
- ArangoDoc.new(key: edge["_key"], collection: collection, database: @database, body: edge)
73
+ ArangoDocument.new(key: edge["_key"], collection: collection, database: @database, body: edge)
80
74
  }
81
75
  end
82
76
 
83
- def in(collection)
77
+ def in(collection) # TESTED
84
78
  self.retrieve_edges collection: collection, direction: "in"
85
79
  end
86
80
 
87
- def out(collection)
81
+ def out(collection) # TESTED
88
82
  self.retrieve_edges collection: collection, direction: "out"
89
83
  end
90
84
 
91
- def any(collection)
85
+ def any(collection) # TESTED
92
86
  self.retrieve_edges collection: collection
93
87
  end
94
88
 
95
- def from
96
- result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_from"]}").parsed_response
89
+ def from # TESTED
90
+ result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_from"]}", @@request)
97
91
  collection = result["_id"].split("/")[0]
98
- @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDoc.new(key: result["_key"], collection: collection, database: @database, body: result)
92
+ return result.headers["x-arango-async-id"] if @@async == "store"
93
+ result = result.parsed_response
94
+ @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: collection, database: @database, body: result)
99
95
  end
100
96
 
101
- def to
102
- result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_to"]}").parsed_response
97
+ def to # TESTED
98
+ result = self.class.get("/_db/#{@database}/_api/document/#{self.body["_to"]}", @@request)
103
99
  collection = result["_id"].split("/")[0]
104
- @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDoc.new(key: result["_key"], collection: collection, database: @database, body: result)
100
+ return result.headers["x-arango-async-id"] if @@async == "store"
101
+ result = result.parsed_response
102
+ @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: collection, database: @database, body: result)
105
103
  end
106
104
 
107
105
  # def header
@@ -111,64 +109,60 @@ class ArangoDoc < ArangoS
111
109
 
112
110
  # === POST ====
113
111
 
114
- def create(body: @body, waitForSync: nil, returnNew: nil, database: @database, collection: @collection)
112
+ def create(body: {}, waitForSync: nil, returnNew: nil) # TESTED
113
+ body = @body.merge(body)
115
114
  query = {"waitForSync" => waitForSync, "returnNew" => returnNew}.delete_if{|k,v| v.nil?}
116
- unless body.is_a? Array
117
- body["_key"] = @key if body["_key"].nil? && !@key.nil?
118
- new_Document = { :body => body.to_json, :query => query }
119
- result = self.class.post("/_db/#{database}/_api/document/#{collection}", new_Document).parsed_response
120
- return_result(result, body)
121
- else
122
- new_Document = { :body => body.to_json, :query => query }
123
- result = self.class.post("/_db/#{database}/_api/document/#{collection}", new_Document).parsed_response
124
- i = -1
125
- return @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDoc.new(key: x["_key"], collection: collection, database: database, body: body[i+=1])}
126
- end
115
+ body["_key"] = @key if body["_key"].nil? && !key.nil?
116
+ request = @@request.merge({ :body => @body.to_json, :query => query })
117
+ result = self.class.post("/_db/#{@database}/_api/document/#{@collection}", request)
118
+ return_result result: result, body: @body
127
119
  end
128
120
  alias create_document create
129
121
  alias create_vertex create
130
122
 
131
- def self.create(body: {}, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection)
123
+ def self.create(body: {}, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection) # TESTED
132
124
  collection = collection.is_a?(String) ? collection : collection.collection
133
125
  database = database.is_a?(String) ? database : database.database
134
126
  query = {"waitForSync" => waitForSync, "returnNew" => returnNew}.delete_if{|k,v| v.nil?}
135
127
  unless body.is_a? Array
136
- body["_key"] = @key if body["_key"].nil? && !@key.nil?
137
- new_Document = { :body => body.to_json, :query => query }
138
- result = post("/_db/#{database}/_api/document/#{collection}", new_Document).parsed_response
139
- self.return_result(result, body)
128
+ request = @@request.merge({ :body => body.to_json, :query => query })
129
+ result = post("/_db/#{database}/_api/document/#{collection}", request)
130
+ return result.headers["x-arango-async-id"] if @@async == "store"
131
+ result = result.parsed_response
132
+ @@verbose ? result : result["error"] ? result["errorMessage"] : ArangoDocument.new(key: result["_key"], collection: result["_id"].split("/")[0], body: body)
140
133
  else
141
- new_Document = { :body => body.to_json, :query => query }
142
- result = post("/_db/#{database}/_api/document/#{collection}", new_Document).parsed_response
134
+ body = body.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDocument) ? x.body : nil}
135
+ request = @@request.merge({ :body => body.to_json, :query => query })
136
+ result = post("/_db/#{database}/_api/document/#{collection}", request)
143
137
  i = -1
144
- return @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDoc.new(key: x["_key"], collection: collection, database: database, body: body[i+=1])}
138
+ return result.headers["x-arango-async-id"] if @@async == "store"
139
+ result = result.parsed_response
140
+ @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: collection, database: database, body: body[i+=1])}
145
141
  end
146
142
  end
147
143
 
148
- def create_edge(body: [{}], from:, to:, waitForSync: nil, returnNew: nil, database: @database, collection: @collection)
144
+ def create_edge(body: {}, from:, to:, waitForSync: nil, returnNew: nil, database: @database, collection: @collection) # TESTED
145
+ body = @body.merge(body)
149
146
  edges = []
150
147
  from = [from] unless from.is_a? Array
151
148
  to = [to] unless to.is_a? Array
152
- body = [body] unless body.is_a? Array
153
- body.each do |b|
154
- from.each do |f|
155
- b["_from"] = f.is_a?(String) ? f : f.id
156
- to.each do |t|
157
- b["_to"] = t.is_a?(String) ? t : t.id
158
- edges << b.clone
159
- end
149
+ from.each do |f|
150
+ body["_from"] = f.is_a?(String) ? f : f.id
151
+ to.each do |t|
152
+ body["_to"] = t.is_a?(String) ? t : t.id
153
+ edges << body.clone
160
154
  end
161
155
  end
162
- edges = edges[0] if edges.length == 1
163
- create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
164
- # ArangoDoc.create_edge(body: body, from: from, to: to, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
156
+ edges = edges[0]
157
+ ArangoDocument.create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
165
158
  end
166
159
 
167
- def self.create_edge(body: {}, from:, to:, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection)
160
+ def self.create_edge(body: {}, from:, to:, waitForSync: nil, returnNew: nil, database: @@database, collection: @@collection) # TESTED
168
161
  edges = []
169
162
  from = [from] unless from.is_a? Array
170
163
  to = [to] unless to.is_a? Array
171
164
  body = [body] unless body.is_a? Array
165
+ body = body.map{|x| x.is_a?(Hash) ? x : x.is_a?(ArangoDocument) ? x.body : nil}
172
166
  body.each do |b|
173
167
  from.each do |f|
174
168
  b["_from"] = f.is_a?(String) ? f : f.id
@@ -178,33 +172,34 @@ class ArangoDoc < ArangoS
178
172
  end
179
173
  end
180
174
  end
181
-
182
175
  edges = edges[0] if edges.length == 1
183
- self.create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
176
+ ArangoDocument.create(body: edges, waitForSync: waitForSync, returnNew: returnNew, database: database, collection: collection)
184
177
  end
185
178
 
186
179
  # === MODIFY ===
187
180
 
188
- def replace(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil)
181
+ def replace(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil) # TESTED
189
182
  query = {
190
183
  "waitForSync" => waitForSync,
191
184
  "returnNew" => returnNew,
192
185
  "returnOld" => returnOld,
193
186
  "ignoreRevs" => ignoreRevs
194
187
  }.delete_if{|k,v| v.nil?}
195
- new_Document = { :body => body.to_json, :query => query }
188
+ request = @@request.merge({ :body => body.to_json, :query => query })
196
189
 
197
190
  unless body.is_a? Array
198
- result = self.class.put("/_db/#{@database}/_api/document/#{@id}", new_Document).parsed_response
199
- return_result(result, body)
191
+ result = self.class.put("/_db/#{@database}/_api/document/#{@id}", request)
192
+ self.return_result result: result, body: body
200
193
  else
201
- result = self.class.put("/_db/#{@database}/_api/document/#{@collection}", new_Document).parsed_response
194
+ result = self.class.put("/_db/#{@database}/_api/document/#{@collection}", request)
202
195
  i = -1
203
- return @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDoc.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
196
+ return result.headers["x-arango-async-id"] if @@async == "store"
197
+ result = result.parsed_response
198
+ @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
204
199
  end
205
200
  end
206
201
 
207
- def update(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil, keepNull: nil, mergeObjects: nil)
202
+ def update(body: {}, waitForSync: nil, ignoreRevs: nil, returnOld: nil, returnNew: nil, keepNull: nil, mergeObjects: nil) # TESTED
208
203
  query = {
209
204
  "waitForSync" => waitForSync,
210
205
  "returnNew" => returnNew,
@@ -213,10 +208,12 @@ class ArangoDoc < ArangoS
213
208
  "keepNull" => keepNull,
214
209
  "mergeObjects" => mergeObjects
215
210
  }.delete_if{|k,v| v.nil?}
216
- new_Document = { :body => body.to_json, :query => query }
211
+ request = @@request.merge({ :body => body.to_json, :query => query })
217
212
 
218
213
  unless body.is_a? Array
219
- result = self.class.patch("/_db/#{@database}/_api/document/#{@id}", new_Document).parsed_response
214
+ result = self.class.patch("/_db/#{@database}/_api/document/#{@id}", request)
215
+ return result.headers["x-arango-async-id"] if @@async == "store"
216
+ result = result.parsed_response
220
217
  if @@verbose
221
218
  unless result["error"]
222
219
  @key = result["_key"]
@@ -235,62 +232,63 @@ class ArangoDoc < ArangoS
235
232
  end
236
233
  end
237
234
  else
238
- result = self.class.patch("/_db/#{@database}/_api/document/#{@collection}", new_Document).parsed_response
235
+ result = self.class.patch("/_db/#{@database}/_api/document/#{@collection}", request)
239
236
  i = -1
240
- return @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDoc.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
237
+ return result.headers["x-arango-async-id"] if @@async == "store"
238
+ result = result.parsed_response
239
+ @@verbose ? result : !result.is_a?(Array) ? result["errorMessage"] : result.map{|x| ArangoDocument.new(key: x["_key"], collection: @collection, database: @database, body: body[i+=1])}
241
240
  end
242
241
  end
243
242
 
244
243
  # === DELETE ===
245
244
 
246
- def destroy(body: nil, waitForSync: nil, ignoreRevs: nil, returnOld: nil)
245
+ def destroy(body: nil, waitForSync: nil, ignoreRevs: nil, returnOld: nil) # TESTED
247
246
  query = {
248
247
  "waitForSync" => waitForSync,
249
248
  "returnOld" => returnOld,
250
249
  "ignoreRevs" => ignoreRevs
251
250
  }.delete_if{|k,v| v.nil?}
252
- new_Document = { :query => query }
251
+ request = @@request.merge({ :body => body.to_json, :query => query })
253
252
 
254
253
  unless body.is_a? Array
255
- result = self.class.delete("/_db/#{@database}/_api/document/#{@id}", new_Document).parsed_response
256
- @@verbose ? result : result["error"] ? result["errorMessage"] : true
254
+ result = self.class.delete("/_db/#{@database}/_api/document/#{@id}", request)
255
+ return_result result: result, caseTrue: true
257
256
  else
258
- new_Document = { :body => body.to_json, :query => query }
259
- result = self.class.delete("/_db/#{@database}/_api/document/#{@collection}", new_Document).parsed_response
260
- return result
257
+ result = self.class.delete("/_db/#{@database}/_api/document/#{@collection}", request)
258
+ return_result result: result, caseTrue: true
261
259
  end
262
260
  end
263
261
 
264
262
  # === UTILITY ===
265
263
 
266
- def return_result(result, body)
267
- if @@verbose
268
- unless result["error"]
269
- @key = result["_key"]
270
- @id = "#{@collection}/#{@key}"
271
- @body = body
272
- end
273
- result
274
- else
275
- if result["error"]
276
- result["errorMessage"]
277
- else
278
- @key = result["_key"]
279
- @id = "#{@collection}/#{@key}"
280
- @body = body
281
- self
282
- end
283
- end
284
- end
285
-
286
- def self.return_result(result, body)
287
- if @@verbose
288
- result
264
+ def return_result(result:, body: {}, caseTrue: false, key: nil)
265
+ if @@async == "store"
266
+ result.headers["x-arango-async-id"]
289
267
  else
290
- if result["error"]
291
- result["errorMessage"]
268
+ result = result.parsed_response
269
+ if @@verbose || !result.is_a?(Hash)
270
+ resultTemp = result
271
+ unless result["errorMessage"]
272
+ result.delete("error")
273
+ result.delete("code")
274
+ @key = result["_key"]
275
+ @collection = result["_id"].split("/")[0]
276
+ @body = result.merge(body)
277
+ end
278
+ resultTemp
292
279
  else
293
- ArangoDoc.new key: result["_key"], collection: result["_id"].split("/")[0], body: body
280
+ if result["error"]
281
+ result["errorMessage"]
282
+ else
283
+ return true if caseTrue
284
+ result.delete("error")
285
+ result.delete("code")
286
+ @key = result["_key"]
287
+ @collection = result["_id"].split("/")[0]
288
+ @id = "#{@collection}/#{@key}"
289
+ @body = result.merge(body)
290
+ key.nil? ? self : result[key]
291
+ end
294
292
  end
295
293
  end
296
294
  end
data/lib/ArangoRB_Edg.rb CHANGED
@@ -1,27 +1,29 @@
1
1
  # === GRAPH EDGE ===
2
2
 
3
- class ArangoE < ArangoDoc
4
- def initialize(key: nil, collection: @@collection, graph: @@graph, database: @@database, body: {}, from: nil, to: nil)
3
+ class ArangoEdge < ArangoDocument
4
+ def initialize(key: nil, collection: @@collection, graph: @@graph, database: @@database, body: {}, from: nil, to: nil) # TESTED
5
5
  if collection.is_a?(String)
6
6
  @collection = collection
7
- elsif collection.is_a?(ArangoC)
7
+ elsif collection.is_a?(ArangoCollection)
8
8
  @collection = collection.collection
9
9
  else
10
- raise "collection should be a String or an ArangoC instance, not a #{collection.class}"
10
+ raise "collection should be a String or an ArangoCollection instance, not a #{collection.class}"
11
11
  end
12
12
 
13
13
  if graph.is_a?(String)
14
14
  @graph = graph
15
- elsif graph.is_a?(ArangoG)
15
+ elsif graph.is_a?(ArangoGraph)
16
16
  @graph = graph.graph
17
17
  else
18
- raise "graph should be a String or an ArangoG instance, not a #{graph.class}"
18
+ raise "graph should be a String or an ArangoGraph instance, not a #{graph.class}"
19
19
  end
20
20
 
21
21
  if database.is_a?(String)
22
22
  @database = database
23
+ elsif database.is_a?(ArangoDatabase)
24
+ @database = database.database
23
25
  else
24
- raise "database should be a String, not a #{database.class}"
26
+ raise "database should be a String or an ArangoDatabase instance, not a #{database.class}"
25
27
  end
26
28
 
27
29
  if key.is_a?(String) || key.nil?
@@ -42,20 +44,20 @@ class ArangoE < ArangoDoc
42
44
 
43
45
  if from.is_a?(String)
44
46
  @body["_from"] = from
45
- elsif from.is_a?(ArangoDoc)
47
+ elsif from.is_a?(ArangoDocument)
46
48
  @body["_from"] = from.id
47
49
  elsif from.nil?
48
50
  else
49
- raise "from should be a String or an ArangoDoc instance, not a #{from.class}"
51
+ raise "from should be a String or an ArangoDocument instance, not a #{from.class}"
50
52
  end
51
53
 
52
54
  if to.is_a?(String)
53
55
  @body["_to"] = to
54
- elsif to.is_a?(ArangoDoc)
56
+ elsif to.is_a?(ArangoDocument)
55
57
  @body["_to"] = to.id
56
58
  elsif to.nil?
57
59
  else
58
- raise "to should be a String or an ArangoDoc instance, not a #{to.class}"
60
+ raise "to should be a String or an ArangoDocument instance, not a #{to.class}"
59
61
  end
60
62
  end
61
63
 
@@ -63,94 +65,111 @@ class ArangoE < ArangoDoc
63
65
 
64
66
  # === GET ===
65
67
 
66
- def retrieve #DONE
67
- result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}").parsed_response
68
- if @@verbose
69
- @body = result["edge"] unless result["error"]
70
- result
68
+ def retrieve # TESTED
69
+ result = self.class.get("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", @@request)
70
+ if @@async == "store"
71
+ result.headers["x-arango-async-id"]
71
72
  else
72
- if result["error"]
73
- result["errorMessage"]
73
+ result = result.parsed_response
74
+ if @@verbose
75
+ @body = result["edge"] unless result["error"]
76
+ result
74
77
  else
75
- @body = result["edge"]
76
- self
78
+ if result["error"]
79
+ result["errorMessage"]
80
+ else
81
+ @body = result["edge"]
82
+ self
83
+ end
77
84
  end
78
85
  end
79
86
  end
80
87
 
81
88
  # === POST ====
82
89
 
83
- def create(body: {}, from: @body["_from"], to: @body["_to"], waitForSync: nil) #DONE
90
+ def create(body: {}, from: @body["_from"], to: @body["_to"], waitForSync: nil) # TESTED
84
91
  query = {"waitForSync" => waitForSync}.delete_if{|k,v| v.nil?}
85
92
  body["_key"] = @key if body["_key"].nil? && !@key.nil?
86
93
  body["_from"] = from.is_a?(String) ? from : from.id
87
94
  body["_to"] = to.is_a?(String) ? to : to.id
88
- new_Document = { :body => body.to_json, :query => query }.delete_if{|k,v| v.nil?}
89
- result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@collection}", new_Document).parsed_response
90
- self.return_result(result, body)
95
+ request = @@request.merge({ :body => body.to_json, :query => query })
96
+ result = self.class.post("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@collection}", request)
97
+ return_result result: result, body: body
91
98
  end
92
99
  alias create_document create
93
100
  alias create_vertex create
94
101
 
95
102
  # === MODIFY ===
96
103
 
97
- def replace(body: {}, waitForSync: nil)
104
+ def replace(body: {}, waitForSync: nil) # TESTED
98
105
  query = { "waitForSync" => waitForSync }.delete_if{|k,v| v.nil?}
99
- new_Document = { :body => body.to_json, :query => query }.delete_if{|k,v| v.nil?}
100
- result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", new_Document).parsed_response
101
- self.return_result(result, body)
106
+ request = @@request.merge({ :body => body.to_json, :query => query })
107
+ result = self.class.put("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", request)
108
+ return_result result: result, body: body
102
109
  end
103
110
 
104
- def update(body: {}, waitForSync: nil, keepNull: nil) #DONE
111
+ def update(body: {}, waitForSync: nil, keepNull: nil) # TESTED
105
112
  query = {"waitForSync" => waitForSync, "keepNull" => keepNull}.delete_if{|k,v| v.nil?}
106
- new_Document = { :body => body.to_json, :query => query }
107
- result = self.class.patch("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", new_Document).parsed_response
108
- if @@verbose
109
- unless result["error"]
110
- @key = result["_key"]
111
- @id = "#{@collection}/#{@key}"
112
- @body = body
113
- end
114
- result
113
+ request = @@request.merge({ :body => body.to_json, :query => query })
114
+ result = self.class.patch("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", request)
115
+ if @@async == "store"
116
+ result.headers["x-arango-async-id"]
115
117
  else
116
- if result["error"]
117
- result["errorMessage"]
118
+ result = result.parsed_response
119
+ if @@verbose
120
+ unless result["error"]
121
+ @key = result["_key"]
122
+ @id = "#{@collection}/#{@key}"
123
+ @body = body
124
+ end
125
+ result
118
126
  else
119
- @key = result["_key"]
120
- @id = "#{@collection}/#{@key}"
121
- @body = @body.merge(body)
122
- self
127
+ if result["error"]
128
+ result["errorMessage"]
129
+ else
130
+ @key = result["edge"]["_key"]
131
+ @id = "#{@collection}/#{@key}"
132
+ @body = @body.merge(body)
133
+ @body = @body.merge(result["edge"])
134
+ self
135
+ end
123
136
  end
124
137
  end
125
138
  end
126
139
 
127
140
  # === DELETE ===
128
141
 
129
- def destroy(body: nil, waitForSync: nil) #OONE
142
+ def destroy(body: nil, waitForSync: nil) # TESTED
130
143
  query = { "waitForSync" => waitForSync }.delete_if{|k,v| v.nil?}
131
- new_Document = { :query => query }
132
- result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}").parsed_response
133
- @@verbose ? result : result["error"] ? result["errorMessage"] : true
144
+ request = @@request.merge({ :query => query })
145
+ result = self.class.delete("/_db/#{@database}/_api/gharial/#{@graph}/edge/#{@id}", request)
146
+ return_result result: result, caseTrue: true
134
147
  end
135
148
 
136
149
  # === UTILITY ===
137
150
 
138
- def return_result(result, body)
139
- if @@verbose
140
- unless result["error"]
141
- @key = result["edge"]["_key"]
142
- @id = "#{@collection}/#{@key}"
143
- @body = body
144
- end
145
- result
151
+ def return_result(result:, body: {}, caseTrue: false)
152
+ if @@async == "store"
153
+ result.headers["x-arango-async-id"]
146
154
  else
147
- if result["error"]
148
- result["errorMessage"]
155
+ result = result.parsed_response
156
+ if @@verbose
157
+ unless result["error"]
158
+ @key = result["edge"]["_key"]
159
+ @id = "#{@collection}/#{@key}"
160
+ @body = body
161
+ end
162
+ result
149
163
  else
150
- @key = result["edge"]["_key"]
151
- @id = "#{@collection}/#{@key}"
152
- @body = body
153
- self
164
+ if result["error"]
165
+ result["errorMessage"]
166
+ else
167
+ return true if caseTrue
168
+ @key = result["edge"]["_key"]
169
+ @id = "#{@collection}/#{@key}"
170
+ @body = body
171
+ self
172
+ end
154
173
  end
155
174
  end
156
175
  end