From e6d6587943ac316527c13fc367a3da7567b2d65b Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Tue, 6 Sep 2022 01:48:50 +0200 Subject: [PATCH 1/5] return the response for path, batch and delete methods --- lib/ontologies_api_client/http.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ontologies_api_client/http.rb b/lib/ontologies_api_client/http.rb index ef57f9d..102d536 100644 --- a/lib/ontologies_api_client/http.rb +++ b/lib/ontologies_api_client/http.rb @@ -99,7 +99,7 @@ def self.get_batch(paths, params = {}) else responses = threaded_request(paths, params) end - return responses + responses end def self.post(path, obj, options = {}) @@ -133,12 +133,14 @@ def self.patch(path, obj) custom_req(obj, file, file_attribute, req) end raise Exception, response.body if response.status >= 500 + response end def self.delete(id) puts "Deleting #{id}" if $DEBUG response = conn.delete id raise Exception, response.body if response.status >= 500 + response end def self.object_from_json(json) From d468ce092edabd89a9ec93fb229748e02f9cfa39 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Tue, 6 Sep 2022 01:50:09 +0200 Subject: [PATCH 2/5] replace Exception with StandardError --- lib/ontologies_api_client/http.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ontologies_api_client/http.rb b/lib/ontologies_api_client/http.rb index 102d536..c4999ea 100644 --- a/lib/ontologies_api_client/http.rb +++ b/lib/ontologies_api_client/http.rb @@ -83,7 +83,7 @@ def self.get(path, params = {}, options = {}) else obj = recursive_struct(load_json(response.body)) end - rescue Exception => e + rescue StandardError => e puts "Problem getting #{path}" if $DEBUG raise e end @@ -108,7 +108,8 @@ def self.post(path, obj, options = {}) req.url path custom_req(obj, file, file_attribute, req) end - raise Exception, response.body if response.status >= 500 + raise StandardError, response.body if response.status >= 500 + if options[:raw] || false # return the unparsed body of the request return response.body else @@ -122,7 +123,8 @@ def self.put(path, obj) req.url path custom_req(obj, file, file_attribute, req) end - raise Exception, response.body if response.status >= 500 + raise StandardError, response.body if response.status >= 500 + recursive_struct(load_json(response.body)) end @@ -132,14 +134,16 @@ def self.patch(path, obj) req.url path custom_req(obj, file, file_attribute, req) end - raise Exception, response.body if response.status >= 500 + raise StandardError, response.body if response.status >= 500 + response end def self.delete(id) puts "Deleting #{id}" if $DEBUG response = conn.delete id - raise Exception, response.body if response.status >= 500 + raise StandardError, response.body if response.status >= 500 + response end From 94463b643547f85dc66cf737cb0b03f4e3ea6738 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Tue, 6 Sep 2022 01:50:37 +0200 Subject: [PATCH 3/5] remove useless return keyword --- lib/ontologies_api_client/http.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ontologies_api_client/http.rb b/lib/ontologies_api_client/http.rb index c4999ea..0378bde 100644 --- a/lib/ontologies_api_client/http.rb +++ b/lib/ontologies_api_client/http.rb @@ -111,9 +111,9 @@ def self.post(path, obj, options = {}) raise StandardError, response.body if response.status >= 500 if options[:raw] || false # return the unparsed body of the request - return response.body + response.body else - return recursive_struct(load_json(response.body)) + recursive_struct(load_json(response.body)) end end From d98fb9467af30ce3fb2c42ddccd9f4383e16b68a Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Tue, 6 Sep 2022 01:53:04 +0200 Subject: [PATCH 4/5] RuboCop auto lint --- lib/ontologies_api_client/http.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/ontologies_api_client/http.rb b/lib/ontologies_api_client/http.rb index 0378bde..8b736eb 100644 --- a/lib/ontologies_api_client/http.rb +++ b/lib/ontologies_api_client/http.rb @@ -19,6 +19,7 @@ def members def length @table.keys.length end + alias :size :length def to_a @@ -37,7 +38,9 @@ def values_at(*selectors) module LinkedData module Client module HTTP - class Link < String; attr_accessor :media_type; end + class Link < String + attr_accessor :media_type; + end def self.conn unless LinkedData::Client.connection_configured? @@ -53,7 +56,7 @@ def self.conn def self.get(path, params = {}, options = {}) headers = options[:headers] || {} raw = options[:raw] || false # return the unparsed body of the request - params = params.delete_if {|k,v| v == nil || v.to_s.empty?} + params = params.delete_if { |k, v| v == nil || v.to_s.empty? } params[:ncbo_cache_buster] = Time.now.to_f if raw # raw requests don't get cached to ensure body is available invalidate_cache = params.delete(:invalidate_cache) || false @@ -94,7 +97,7 @@ def self.get_batch(paths, params = {}) responses = [] if conn.in_parallel? conn.in_parallel do - paths.each {|p| responses << conn.get(p, params) } + paths.each { |p| responses << conn.get(p, params) } end else responses = threaded_request(paths, params) @@ -176,9 +179,11 @@ def self.custom_req(obj, file, file_attribute, req) def self.params_file_handler(params) return if params.nil? + file, return_attribute = nil, nil params.dup.each do |attribute, value| next unless value.is_a?(File) || value.is_a?(Tempfile) || value.is_a?(ActionDispatch::Http::UploadedFile) + filename = value.original_filename file = Faraday::UploadIO.new(value.path, "text/plain", filename) return_attribute = attribute @@ -209,7 +214,7 @@ def self.recursive_struct(json_obj) context = json_obj.delete("@context") # strip context # Create a struct with the left-over attributes to store data - attributes = json_obj.keys.map {|k| k.to_sym} + attributes = json_obj.keys.map { |k| k.to_sym } attributes_always_present = value_cls.attrs_always_present || [] rescue [] attributes = (attributes + attributes_always_present).uniq @@ -239,7 +244,7 @@ def self.recursive_struct(json_obj) end else # Get the struct class - recursive_obj_hash = {links: nil, context: nil} + recursive_obj_hash = { links: nil, context: nil } json_obj.each do |key, value| recursive_obj_hash[key] = recursive_struct(value) end @@ -266,6 +271,7 @@ def self.prep_links(obj) context = links.delete("@context") return if context.nil? + links.keys.each do |link_type| link = Link.new(links[link_type]) link.media_type = context[link_type] @@ -276,6 +282,7 @@ def self.prep_links(obj) def self.load_json(json) return if json.nil? || json.empty? + begin MultiJson.load(json) rescue Exception => e From a7d447fa539f3500401a15454d0eff3579409742 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Tue, 6 Sep 2022 02:11:55 +0200 Subject: [PATCH 5/5] add bundle linux platform --- Gemfile.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile.lock b/Gemfile.lock index e5d51e8..38ba97b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,6 +59,7 @@ PLATFORMS ruby x86_64-darwin-16 x86_64-darwin-17 + x86_64-linux DEPENDENCIES ontologies_api_client!