forked from ontoportal/ontologies_api
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into stage
- Loading branch information
Showing
17 changed files
with
542 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ name: Docker branch Images build | |
on: | ||
push: | ||
branches: | ||
- master | ||
- development | ||
- stage | ||
- test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require_relative '../test/test_case' | ||
|
||
use Rack::ContentNegotiation | ||
|
||
class DereferenceResourceController < ApplicationController | ||
namespace "/ontologies" do | ||
get "/:acronym/resolve/:uri" do | ||
acronym = params[:acronym] | ||
uri = params[:uri] | ||
|
||
if acronym.blank? || uri.blank? | ||
error 500, "Usage: ontologies/:acronym/resolve/:uri?output_format= OR POST: acronym, uri, output_format parameters" | ||
end | ||
|
||
output_format = env["format"].presence || params[:output_format].presence || 'application/n-triples' | ||
|
||
process_request(acronym, uri, output_format) | ||
end | ||
|
||
private | ||
|
||
def process_request(acronym_param, uri_param, output_format) | ||
acronym = acronym_param | ||
uri = URI.decode_www_form_component(uri_param) | ||
|
||
error 500, "INVALID URI" unless valid_url?(uri) | ||
sub = LinkedData::Models::Ontology.find(acronym).first&.latest_submission | ||
|
||
error 500, "Ontology not found" unless sub | ||
|
||
r = Resource.new(sub.id, uri) | ||
case output_format | ||
when 'application/ld+json', 'application/json' | ||
r.to_json | ||
when 'application/rdf+xml', 'application/xml' | ||
r.to_xml | ||
when 'text/turtle' | ||
r.to_turtle | ||
when 'application/n-triples' | ||
r.to_ntriples | ||
else | ||
error 500, "Invalid output format, valid format are: application/json, application/ld+json, application/xml, application/rdf+xml, text/turtle and application/n-triples" | ||
end | ||
|
||
|
||
end | ||
|
||
def valid_url?(url) | ||
uri = URI.parse(url) | ||
uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) | ||
rescue URI::InvalidURIError | ||
false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.