Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Reduce indirection by passing a url rather than a symbol #671

Merged
merged 1 commit into from
Jan 8, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 6 additions & 20 deletions lib/dor/rest_resource_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,20 @@ module Dor
class RestResourceFactory
include Singleton

# @param type [Symbol] the type of connection to create (e.g. :fedora)
# @param url [String] the url to connect to
# @return [RestClient::Resource]
def self.create(type)
instance.create(type)
def self.create(url)
instance.create(url)
end

# @param type [Symbol] the type of connection to create (e.g. :fedora)
# @param url [String] the url to connect to
# @return [RestClient::Resource]
def create(type)
RestClient::Resource.new(url_for(type), connection_options)
def create(url)
RestClient::Resource.new(url, connection_options)
end

private

# @param type [Symbol] the type of connection to create (e.g. :fedora)
# @return [String] the url to connect to.
def url_for(type)
connection_configuration(type).url
end

# @param type [Symbol] the type of connection to create (e.g. :fedora)
# @return [#url] the configuration for the connection
def connection_configuration(type)
Dor::Config.fetch(type)
rescue KeyError
raise "ERROR: Unable to find a configuration for #{type}"
end

# @return [Hash] options for creating a RestClient::Resource
def connection_options
{}
Expand Down
2 changes: 1 addition & 1 deletion lib/dor/static_config/fedora_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def configure(&block)
end

def client
CertificateAuthenticatedRestResourceFactory.create(:fedora)
CertificateAuthenticatedRestResourceFactory.create(url)
end

def url(new_value = nil)
Expand Down