Skip to content

Commit

Permalink
Merge pull request #6 from ncbo/master
Browse files Browse the repository at this point in the history
Sync: merge releases 2.2.3 and onward from ncbo
  • Loading branch information
jvendetti authored Oct 10, 2024
2 parents b0e055f + 9b5059c commit 78d6513
Show file tree
Hide file tree
Showing 19 changed files with 290 additions and 137 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ruby-version: ['2.7', '3.0']
ruby-version: ['3.0', '3.1']
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
Expand All @@ -34,4 +34,4 @@ jobs:
- name: Run tests
env:
UT_APIKEY: ${{ secrets.UT_APIKEY }}
run: bundle exec rake test
run: bundle exec rake test TESTOPTS="-v"
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

gem 'pry'
gem 'rake'
gem 'rubocop', '~> 1.43'
gem 'pry'
gem 'test-unit'
93 changes: 52 additions & 41 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PATH
remote: .
specs:
ontologies_api_client (2.2.2)
activesupport (= 6.1.7.3)
ontologies_api_client (2.4.0)
activesupport (= 7.0.8)
addressable (~> 2.8)
excon
faraday
Expand All @@ -11,74 +11,83 @@ PATH
lz4-ruby
multi_json
oj
spawnling (= 2.1.5)

GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.7.3)
activesupport (7.0.8)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.4)
public_suffix (>= 2.0.2, < 6.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
bigdecimal (3.1.8)
coderay (1.1.3)
concurrent-ruby (1.2.2)
excon (0.100.0)
faraday (2.7.6)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
concurrent-ruby (1.3.3)
excon (0.111.0)
faraday (2.10.0)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-excon (2.1.0)
excon (>= 0.27.4)
faraday (~> 2.0)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (3.0.2)
i18n (1.14.1)
faraday-net_http (3.1.0)
net-http
i18n (1.14.5)
concurrent-ruby (~> 1.0)
json (2.6.3)
json (2.7.2)
language_server-protocol (3.17.0.3)
logger (1.6.0)
lz4-ruby (0.3.3)
method_source (1.0.0)
minitest (5.18.1)
method_source (1.1.0)
minitest (5.25.1)
minitest-hooks (1.5.1)
minitest (> 5.3)
multi_json (1.15.0)
multipart-post (2.3.0)
oj (3.15.0)
parallel (1.22.1)
parser (3.2.0.0)
multipart-post (2.4.1)
net-http (0.4.1)
uri
oj (3.16.4)
bigdecimal (>= 3.0)
parallel (1.25.1)
parser (3.3.4.0)
ast (~> 2.4.1)
power_assert (2.0.3)
racc
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.1)
public_suffix (6.0.0)
racc (1.8.0)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.6.2)
rexml (3.2.5)
rubocop (1.44.1)
rake (13.2.1)
regexp_parser (2.9.2)
rexml (3.3.2)
strscan
rubocop (1.65.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.24.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.24.1)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
spawnling (2.1.5)
test-unit (3.5.7)
power_assert
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
strscan (3.1.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.4.2)
zeitwerk (2.6.8)
unicode-display_width (2.5.0)
uri (0.13.0)

PLATFORMS
ruby
Expand All @@ -87,11 +96,13 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
faraday-follow_redirects (~> 0.3)
minitest (~> 5.25)
minitest-hooks (~> 1.5)
ontologies_api_client!
pry
rake
rubocop (~> 1.43)
test-unit

BUNDLED WITH
2.3.22
2.4.18
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# ontologies_api_client

Models and serializers for ontologies and related artifacts backed by a [4store](https://github.com/4store/4store)
RDF database. This library can be used for interacting with a 4store instance that stores
[BioPortal](https://bioportal.bioontology.org/) ontology data. Models in the library are based on
[Graph Oriented Objects for Ruby (Goo)](https://github.com/ncbo/goo). Serializers support RDF serialization as
Rack Middleware and automatic generation of hypermedia links.
Models and serializers for ontologies and related artifacts backed by an
[AllegroGraph](https://allegrograph.com/products/allegrograph/) or a [4store](https://github.com/4store/4store)
database. This library can be used for interacting with an AllegroGraph or a 4store instance that
stores [BioPortal](https://bioportal.bioontology.org/) ontology data. Models in the library are based on
[Graph Oriented Objects for Ruby (Goo)](https://github.com/ncbo/goo). Serializers support RDF serialization as Rack Middleware and automatic
generation of hypermedia links.

## Install

Expand Down Expand Up @@ -152,7 +153,7 @@ For questions please email [[email protected]]([email protected].)

## License

Copyright (c) 2021, The Board of Trustees of Leland Stanford Junior University All rights reserved.
Copyright (c) 2024, The Board of Trustees of Leland Stanford Junior University All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
14 changes: 9 additions & 5 deletions config/config.test.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# frozen_string_literal: true

# config.rb is required for testing
# unit test makes calls to bioportal api so it needs a valid API key which can
# be set via ENV variable UT_APIKEY
abort('UT_APIKEY env variable is not set. Canceling tests') unless ENV.include?('UT_APIKEY')
abort('UT_APIKEY env variable is set to an empty value. Canceling tests') unless ENV['UT_APIKEY'].size > 5

LinkedData::Client.config do |config|
config.rest_url = 'https://data.bioontology.org'
config.apikey = ENV['UT_APIKEY']
# config.apikey = 'xxxxx-xxxxx-xxxxxxxxxx'
config.links_attr = 'links'
config.cache = false
config.rest_url = 'https://data.bioontology.org'
config.apikey = ENV['UT_APIKEY']
# config.apikey = 'xxxxx-xxxxx-xxxxxxxxxx'
config.links_attr = 'links'
config.purl_host = 'purl.bioontology.org'
config.purl_prefix = 'https://purl.bioontology.org/ontology'
config.cache = false
end
2 changes: 1 addition & 1 deletion lib/ontologies_api_client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'oj'
require 'multi_json'
require 'spawnling'

require_relative 'ontologies_api_client/config'
require_relative 'ontologies_api_client/http'
Expand All @@ -9,6 +8,7 @@
require_relative 'ontologies_api_client/collection'
require_relative 'ontologies_api_client/read_write'
require_relative 'ontologies_api_client/analytics'
require_relative 'ontologies_api_client/version'

# Models
curr_dir = File.expand_path("../ontologies_api_client", __FILE__)
Expand Down
17 changes: 14 additions & 3 deletions lib/ontologies_api_client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ class Base
attr_accessor :context, :links

class << self
attr_accessor :media_type, :act_as_media_type, :include_attrs, :include_attrs_full, :attrs_always_present
attr_accessor :act_as_media_type, :include_attrs, :include_attrs_full, :attrs_always_present
def media_types
Array(@media_type)
end

def media_type
media_types.first
end

end

##
Expand All @@ -31,8 +39,11 @@ def self.map_classes
map = {}
classes = LinkedData::Client::Models.constants.map {|c| LinkedData::Client::Models.const_get(c)}
classes.each do |media_type_cls|
next if map[media_type_cls] || !media_type_cls.respond_to?(:media_type) || !media_type_cls.ancestors.include?(LinkedData::Client::Base)
map[media_type_cls.media_type] = media_type_cls
next if map[media_type_cls] || !media_type_cls.respond_to?(:media_types) || !media_type_cls.ancestors.include?(LinkedData::Client::Base)
media_type_cls.media_types.each do |type|
next if map[type]
map[type] = media_type_cls
end
media_type_cls.act_as_media_type.each {|mt| map[mt] = media_type_cls} if media_type_cls.act_as_media_type
end
return map
Expand Down
12 changes: 6 additions & 6 deletions lib/ontologies_api_client/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def method_missing(meth, *args, &block)
##
# Get all top-level links for the API
def top_level_links
HTTP.get(LinkedData::Client.settings.rest_url)
@top_level_links ||= HTTP.get(LinkedData::Client.settings.rest_url)
end

##
Expand Down Expand Up @@ -73,18 +73,18 @@ def where(params = {}, &block)
end
end

##
# Find a resource by id
#
# @deprecated Use {#get} instead
def find(id, params = {})
found = where do |obj|
obj.id.eql?(id)
end
found.first
get(id, params)
end

##
# Get a resource by id (this will retrieve it from the REST service)
def get(id, params = {})
path = collection_path
id = "#{path}/#{id}" unless id.include?(path)
HTTP.get(id, params)
end

Expand Down
29 changes: 17 additions & 12 deletions lib/ontologies_api_client/config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'ostruct'
require 'faraday'
require 'faraday/excon'
Expand All @@ -16,27 +18,30 @@ module Client

def config(&block)
return if @settings_run

@settings_run = true

yield @settings if block_given?

# Set defaults
@settings.rest_url ||= "http://stagedata.bioontology.org"
@settings.apikey ||= "4ea81d74-8960-4525-810b-fa1baab576ff"
@settings.links_attr ||= "links"
@settings.rest_url ||= 'http://stagedata.bioontology.org'
@settings.apikey ||= '4ea81d74-8960-4525-810b-fa1baab576ff'
@settings.links_attr ||= 'links'
@settings.cache ||= false
@settings.enable_long_request_log ||= false
@settings.purl_prefix ||= "http://purl.example.org"
@settings.purl_prefix ||= 'http://purl.example.org'
@settings.purl_host ||= 'purl.example.org'

# Remove trailing slash
@settings.rest_url = @settings.rest_url.chomp("/")
@settings.purl_prefix = @settings.purl_prefix.chomp("/")
@settings.rest_url = @settings.rest_url.chomp('/')
@settings.purl_prefix = @settings.purl_prefix.chomp('/')

@settings_run = true
end

def config_connection(options = {})
return if @settings_run_connection

store = options[:cache_store]
@settings.conn = Faraday.new(@settings.rest_url) do |faraday|
if @settings.enable_long_request_log
Expand All @@ -57,20 +62,20 @@ def config_connection(options = {})
begin
require_relative 'middleware/faraday-object-cache'
faraday.use :object_cache, store: store
puts "=> faraday caching enabled"
puts '=> faraday caching enabled'
puts "=> faraday cache store: #{store.class}"
rescue LoadError
puts "=> WARNING: faraday http cache gem is not available, caching disabled"
puts '=> WARNING: faraday http cache gem is not available, caching disabled'
end
end

faraday.request :multipart
faraday.request :url_encoded
faraday.adapter :excon
faraday.headers = {
"Accept" => "application/json",
"Authorization" => "apikey token=#{@settings.apikey}",
"User-Agent" => "NCBO API Ruby Client v0.1.0"
'Accept' => 'application/json',
'Authorization' => "apikey token=#{@settings.apikey}",
'User-Agent' => "NCBO API Ruby Client v#{LinkedData::Client::VERSION}"
}
end
@settings_run_connection = true
Expand All @@ -80,4 +85,4 @@ def connection_configured?
@settings_run_connection
end
end
end
end
Loading

0 comments on commit 78d6513

Please sign in to comment.