Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 41 additions & 39 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,85 +29,87 @@ GEM
tzinfo (~> 2.0, >= 2.0.5)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.9)
ast (2.4.3)
base64 (0.3.0)
benchmark (0.5.0)
bigdecimal (3.3.1)
coderay (1.1.3)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
drb (2.2.1)
excon (1.2.3)
faraday (2.12.2)
connection_pool (2.5.4)
drb (2.2.3)
excon (1.3.1)
logger
faraday (2.14.0)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-excon (2.3.0)
faraday-excon (2.4.0)
excon (>= 1.0.0)
faraday (>= 2.11.0, < 3)
faraday-follow_redirects (0.3.0)
faraday-follow_redirects (0.4.0)
faraday (>= 1, < 3)
faraday-multipart (1.1.0)
faraday-multipart (1.1.1)
multipart-post (~> 2.0)
faraday-net_http (3.4.0)
faraday-net_http (3.4.1)
net-http (>= 0.5.0)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
json (2.9.1)
language_server-protocol (3.17.0.4)
logger (1.6.5)
json (2.15.2)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
lz4-ruby (0.3.3)
method_source (1.1.0)
minitest (5.25.4)
minitest (5.26.0)
minitest-hooks (1.5.2)
minitest (> 5.3)
multi_json (1.15.0)
multi_json (1.17.0)
multipart-post (2.4.1)
net-http (0.6.0)
net-http (0.7.0)
uri
oj (3.16.9)
oj (3.16.12)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
ostruct (0.6.1)
parallel (1.26.3)
parser (3.3.7.1)
ostruct (0.6.3)
parallel (1.27.0)
parser (3.3.10.0)
ast (~> 2.4.1)
racc
prism (1.6.0)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (6.0.1)
public_suffix (6.0.2)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.10.0)
rubocop (1.71.2)
rake (13.3.1)
regexp_parser (2.11.3)
rubocop (1.81.7)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-ast (>= 1.47.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.38.0)
parser (>= 3.3.1.0)
rubocop-ast (1.47.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
ruby-progressbar (1.13.0)
securerandom (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
uri (1.0.3)
unicode-display_width (3.2.0)
unicode-emoji (~> 4.1)
unicode-emoji (4.1.0)
uri (1.1.1)

PLATFORMS
arm64-darwin-24
arm64-darwin-23
ruby
x86_64-darwin-16
x86_64-darwin-17
x86_64-linux

DEPENDENCIES
faraday-follow_redirects (~> 0.3)
Expand All @@ -119,4 +121,4 @@ DEPENDENCIES
rubocop (~> 1.43)

BUNDLED WITH
2.5.11
2.6.9
48 changes: 40 additions & 8 deletions lib/ontologies_api_client/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,50 @@ def self.patch(path, obj)
response
end

def self.delete(id)
puts "Deleting #{id}" if $DEBUG_API_CLIENT
response = conn.delete id
raise StandardError, response.body if response.status >= 500

response
end

def self.object_from_json(json)
recursive_struct(load_json(json))
end

def self.delete(path, params = {}, options = {})
headers = options[:headers] || {}
raw = options[:raw] || false # return response.body (string)
parse = options[:parse] || false # return parsed object (similar to 'get')

params = (params || {}).dup
params = params.delete_if { |k, v| v.nil? || v.to_s.empty? }

begin
puts "Deleting #{path} with #{params}" if $DEBUG_API_CLIENT
response = conn.delete do |req|
req.url path
req.params = params.dup
req.options[:timeout] = options[:timeout] || 60
req.headers.merge!(headers)
end
rescue StandardError => e
query = Faraday::Utils.build_query(params)
pretty = path.dup
pretty += '?' unless query.empty? || pretty.include?('?')
raise e, "Problem deleting:\n#{pretty}#{query}\n\nError: #{e.message}\n#{e.backtrace.join("\n\t")}"
end

raise StandardError, response.body if response.status >= 500

if raw
response.body
elsif parse
if response.respond_to?(:parsed_body) && response.parsed_body
obj = response.parsed_body
obj = obj.dup if obj.frozen?
else
obj = recursive_struct(load_json(response.body))
end
obj
else
response # backward compatibility preserved
end
end

private

def self.custom_req(obj, file, file_attribute, req)
Expand Down
7 changes: 5 additions & 2 deletions test/models/test_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ def test_purl_obo

res = fetch_response(cls.purl)
assert_equal 302, res.status
assert_equal 'https://bioportal.bioontology.org/ontologies/DOID/classes?conceptid=http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FDOID_4',
res.headers['location']

expected_location = 'https://bioportal.bioontology.org/ontologies/DOID/classes?conceptid=http%3A%2F%2Fpurl.obolibrary.org%2Fobo%2FDOID_4'
actual_location = res.headers['location']
normalize = ->(url) { url&.sub(%r{/(\?)}, '\1') }
assert_equal normalize.call(expected_location), normalize.call(actual_location)
end

private
Expand Down
3 changes: 2 additions & 1 deletion test/test_case.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'pry'
require 'minitest/autorun'
require 'minitest/hooks/test'
require_relative '../lib/ontologies_api_client'
Expand Down