Module: OSCRuby::QueryModule
- Included in:
- ServiceProduct
- Defined in:
- lib/osc_ruby/query_module.rb
Class Method Summary collapse
- .check_obj_for_errors(obj_to_check) ⇒ Object
- .create(rn_client, resource, json_content) ⇒ Object
- .find(rn_client, resource) ⇒ Object
- .normalize(input) ⇒ Object
Class Method Details
.check_obj_for_errors(obj_to_check) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/osc_ruby/query_module.rb', line 58 def self.check_obj_for_errors(obj_to_check) _json = JSON.parse(obj_to_check.body) if _json['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
20 21 22 23 24 25 26 |
# File 'lib/osc_ruby/query_module.rb', line 20 def self.create(rn_client,resource,json_content) obj_to_find = OSCRuby::Connect.post_or_patch(rn_client,resource,json_content) obj_to_find.body end |
.find(rn_client, resource) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/osc_ruby/query_module.rb', line 10 def self.find(rn_client,resource) obj_to_find = OSCRuby::Connect.get(rn_client,resource) check_obj_for_errors(obj_to_find) obj_info = normalize(obj_to_find) end |
.normalize(input) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/osc_ruby/query_module.rb', line 28 def self.normalize(input) if input.code.to_i == 404 input.body else _json = JSON.parse(input.body) final_hash = [] _json['items'][0]['rows'].each do |row| obj_hash = {} _json['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 |