class Artemis::Adapters::MultiDomainAdapter
Attributes
adapter[R]
Public Class Methods
new(_uri, service_name: , timeout: , pool_size: , adapter_options: {})
click to toggle source
# File lib/artemis/adapters/multi_domain_adapter.rb, line 10 def initialize(_uri, service_name: , timeout: , pool_size: , adapter_options: {}) @connection_by_url = {} @service_name = service_name.to_s @timeout = timeout @pool_size = pool_size @adapter = adapter_options[:adapter] || :net_http @mutex_for_connection = Mutex.new end
Public Instance Methods
connection()
click to toggle source
# File lib/artemis/adapters/multi_domain_adapter.rb, line 31 def connection raise NotImplementedError, "Calling the #connection method without a URI is not supported. Please use the " \ "#connection_for_url(uri) instead." end
connection_for_url(url)
click to toggle source
# File lib/artemis/adapters/multi_domain_adapter.rb, line 36 def connection_for_url(url) @connection_by_url[url.to_s] || @mutex_for_connection.synchronize do @connection_by_url[url.to_s] ||= ::Artemis::Adapters.lookup(adapter).new(url, service_name: service_name, timeout: timeout, pool_size: pool_size) end end
execute(document:, operation_name: nil, variables: {}, context: {})
click to toggle source
Makes an HTTP request for GraphQL query.
# File lib/artemis/adapters/multi_domain_adapter.rb, line 20 def execute(document:, operation_name: nil, variables: {}, context: {}) url = context[:url] if url.nil? raise ArgumentError, 'The MultiDomain adapter requires a url on every request. Please specify a url with a context: ' \ 'Client.with_context(url: "https://awesomeshop.domain.conm")' end connection_for_url(url).execute(document: document, operation_name: operation_name, variables: variables, context: context) end