Module: OSCRuby::QueryModule
Class Method Summary
collapse
attr_hash_exists_and_is_type_of, check_attributes, check_client, check_for_id, check_object_for_id, check_query, extract_attributes
Class Method Details
.check_obj_for_errors(obj_to_check) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/osc_ruby/query_module.rb', line 80
def check_obj_for_errors(obj_to_check)
json_obj = JSON.parse(obj_to_check.body)
if !json_obj.nil? && json_obj['items'][0]['rows'].count == 0
raise ArgumentError, 'There were no objects matching your query; please try again.'
end
end
|
.create(rn_client, resource, json_content) ⇒ Object
32
33
34
35
36
|
# File 'lib/osc_ruby/query_module.rb', line 32
def create(rn_client,resource,json_content)
OSCRuby::Connect.post_or_patch(rn_client,resource,json_content)
end
|
.destroy(rn_client, resource) ⇒ Object
44
45
46
47
48
|
# File 'lib/osc_ruby/query_module.rb', line 44
def destroy(rn_client,resource)
OSCRuby::Connect.delete(rn_client,resource)
end
|
.find(rn_client, resource) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/osc_ruby/query_module.rb', line 15
def find(rn_client,resource)
obj_to_find = OSCRuby::Connect.get(rn_client,resource)
if obj_to_find.code.to_i == 200 || obj_to_find.code.to_i == 201
check_obj_for_errors(obj_to_find)
normalize(obj_to_find)
else
obj_to_find.body
end
end
|
.normalize(input) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/osc_ruby/query_module.rb', line 50
def normalize(input)
if input.code.to_i == 404
input.body
else
json_input = JSON.parse(input.body)
final_hash = []
json_input['items'][0]['rows'].each do |row|
obj_hash = {}
json_input['items'][0]['columnNames'].each_with_index do |column,i|
obj_hash[column] = if !row[i].nil? && row[i].is_i? == true then row[i].to_i else row[i] end
end
final_hash.push(obj_hash)
end
final_hash.to_json
end
end
|
.update(rn_client, resource, json_content) ⇒ Object
38
39
40
41
42
|
# File 'lib/osc_ruby/query_module.rb', line 38
def update(rn_client,resource,json_content)
OSCRuby::Connect.post_or_patch(rn_client,resource,json_content,true)
end
|