Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: implement federation of collections calls #17

Merged
merged 6 commits into from
Sep 1, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
create the RequestFederation to implement federated_get function
  • Loading branch information
syphax-bouazzouni committed Sep 1, 2024
commit 63d00f0f38372087afa06cbc98b2c5ef0f8f6785
1 change: 1 addition & 0 deletions lib/ontologies_api_client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'oj'
require 'multi_json'
require 'spawnling'
require 'request_store'

require_relative 'ontologies_api_client/config'
require_relative 'ontologies_api_client/http'
45 changes: 45 additions & 0 deletions lib/ontologies_api_client/request_federation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'active_support/core_ext/hash'

module LinkedData
module Client
module RequestFederation

def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
def federated_get(params = {}, &link)
portals = request_portals(params)

connections = Parallel.map(portals, in_threads: portals.size) do |conn|
begin
HTTP.get(link.call(conn.url_prefix.to_s.chomp('/')), params, connection: conn)
rescue StandardError => e
[OpenStruct.new(errors: "Problem retrieving #{link.call(conn.url_prefix.to_s.chomp('/')) || conn.url_prefix}")]
end
end

connections.flatten
end

def request_portals(params = {})
federate = params.delete(:federate) || ::RequestStore.store[:federated_portals]

portals = [LinkedData::Client::HTTP.conn]

if federate.is_a?(Array)
portals += LinkedData::Client::HTTP.federated_conn
.select { |portal_name, _| federate.include?(portal_name) || federate.include?(portal_name.to_s) }
.values
elsif !federate.blank? # all
portals += LinkedData::Client::HTTP.federated_conn.values
end

portals
end
end

end
end
end
4 changes: 3 additions & 1 deletion ontologies_api_client.gemspec
Original file line number Diff line number Diff line change
@@ -12,13 +12,15 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = "2.2.0"

gem.add_dependency('activesupport')
gem.add_dependency('activesupport', '~> 7.0.4')
gem.add_dependency('excon')
gem.add_dependency('faraday')
gem.add_dependency('faraday-excon', '~> 2.0.0')
gem.add_dependency('faraday-multipart')
gem.add_dependency('lz4-ruby')
gem.add_dependency('multi_json')
gem.add_dependency('oj')
gem.add_dependency('parallel')
gem.add_dependency('request_store')
gem.add_dependency('spawnling', '2.1.5')
end