class RoadForest::RemoteHost
This is a client’s main entry point in RoadForest
- we instantiate a RemoteHost
to represent the server in the local program and interact with it. The design goal is that, having created a RemoteHost
object, you should be able to forget that it isn’t, in fact, part of your program. So, the details of TCP (or indeed HTTP
, or whatever the network is doing) become incidental to the abstraction.
One consequence being that you should be able to use a mock host for testing.
Attributes
grant_list_pattern[RW]
http_client[W]
url[R]
Public Class Methods
new(well_known_url)
click to toggle source
# File lib/roadforest/remote-host.rb, line 25 def initialize(well_known_url) self.url = well_known_url end
Public Instance Methods
add_credentials(username, password)
click to toggle source
# File lib/roadforest/remote-host.rb, line 78 def add_credentials(username, password) prepared_credential_source.add(url, username, password) end
anneal(focus) { |focus| ... }
click to toggle source
# File lib/roadforest/remote-host.rb, line 95 def anneal(focus) graph = focus.access_manager.source_graph annealer = SourceRigor::CredenceAnnealer.new(graph) annealer.resolve do focus.reset yield focus end end
build_graph_store()
click to toggle source
# File lib/roadforest/remote-host.rb, line 36 def build_graph_store SourceRigor::GraphStore.new end
forbidden?(method, focus)
click to toggle source
# File lib/roadforest/remote-host.rb, line 205 def forbidden?(method, focus) decider = AuthorizationDecider.new(self, focus) decider.forbidden?(method) end
getting(&block)
click to toggle source
# File lib/roadforest/remote-host.rb, line 241 def getting(&block) transaction(SourceRigor::RetrieveManager, Graph::GraphFocus, &block) end
graph_trace=(target)
click to toggle source
# File lib/roadforest/remote-host.rb, line 49 def graph_trace=(target) graph_transfer.trace = target end
graph_transfer()
click to toggle source
# File lib/roadforest/remote-host.rb, line 57 def graph_transfer @graph_transfer ||= HTTP::GraphTransfer.new(user_agent) end
http_client()
click to toggle source
# File lib/roadforest/remote-host.rb, line 40 def http_client @http_client ||= HTTP::ExconAdapter.new(url) end
http_trace=(target)
click to toggle source
# File lib/roadforest/remote-host.rb, line 44 def http_trace=(target) user_agent.trace = target end
Also aliased as: trace=
posting(&block)
click to toggle source
# File lib/roadforest/remote-host.rb, line 233 def posting(&block) poster = transaction(SourceRigor::PostManager, Graph::PostFocus, &block) poster.graphs.each_pair do |url, graph| graph_transfer.post(url, graph) end end
prepared_credential_source()
click to toggle source
# File lib/roadforest/remote-host.rb, line 71 def prepared_credential_source @prepared_credential_source ||= HTTP::PreparedCredentialSource.new.tap do |prepd| user_agent.keychain.add_source(prepd) end end
put_file(destination, type, io)
click to toggle source
# File lib/roadforest/remote-host.rb, line 245 def put_file(destination, type, io) if destination.respond_to?(:to_context) destination = destination.to_context elsif destination.respond_to?(:to_s) destination = destination.to_s end user_agent.make_request("PUT", destination, {"Content-Type" => type}, io) end
putting(&block)
click to toggle source
# File lib/roadforest/remote-host.rb, line 223 def putting(&block) update = transaction(SourceRigor::UpdateManager, Graph::GraphFocus, &block) access = update.access_manager access.each_target do |context, graph| graph_transfer.put(context, graph) end end
render_graph(graph)
click to toggle source
# File lib/roadforest/remote-host.rb, line 91 def render_graph(graph) Resource::ContentType::JSONLD.from_graph(graph) end
source_rigor()
click to toggle source
# File lib/roadforest/remote-host.rb, line 82 def source_rigor @source_rigor ||= begin rigor = SourceRigor.http rigor.graph_transfer = graph_transfer rigor end end
transaction(manager_class, focus_class, &block)
click to toggle source
# File lib/roadforest/remote-host.rb, line 211 def transaction(manager_class, focus_class, &block) graph = build_graph_store access = manager_class.new access.rigor = source_rigor access.source_graph = graph focus = focus_class.new(access, url) anneal(focus, &block) return focus end
url=(string)
click to toggle source
# File lib/roadforest/remote-host.rb, line 32 def url=(string) @url = normalize_resource(string) end
use_ca_cert(cert)
click to toggle source
# File lib/roadforest/remote-host.rb, line 61 def use_ca_cert(cert) http_client.connection_defaults.merge!(:ssl_ca_file => cert) http_client.reset_connections end
use_client_tls(key, cert)
click to toggle source
# File lib/roadforest/remote-host.rb, line 66 def use_client_tls(key, cert) http_client.connection_defaults.merge!(:client_key => key, :client_cert => cert) http_client.reset_connections end
user_agent()
click to toggle source
# File lib/roadforest/remote-host.rb, line 53 def user_agent @user_agent ||= HTTP::UserAgent.new(http_client) end