Class: RoadForest::RemoteHost
Overview
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.
Defined Under Namespace
Classes: AuthorizationDecider
Constant Summary
Graph::Normalization::Vocabs
Instance Attribute Summary collapse
Instance Method Summary
collapse
#expand_curie, #expand_curie_pair, #interned_uri, #literal, #normalize_context, #normalize_property, #normalize_resource, #normalize_statement, #normalize_term, #normalize_tuple, #normalize_uri, #relevant_prefixes_for_graph, #root_url, #uri, #vocabularies_in_graph
Constructor Details
#initialize(well_known_url) ⇒ RemoteHost
Returns a new instance of RemoteHost.
25
26
27
|
# File 'lib/roadforest/remote-host.rb', line 25
def initialize(well_known_url)
self.url = well_known_url
end
|
Instance Attribute Details
#grant_list_pattern ⇒ Object
Returns the value of attribute grant_list_pattern.
29
30
31
|
# File 'lib/roadforest/remote-host.rb', line 29
def grant_list_pattern
@grant_list_pattern
end
|
#http_client ⇒ Object
40
41
42
|
# File 'lib/roadforest/remote-host.rb', line 40
def http_client
@http_client ||= HTTP::ExconAdapter.new(url)
end
|
#url ⇒ Object
Returns the value of attribute url.
28
29
30
|
# File 'lib/roadforest/remote-host.rb', line 28
def url
@url
end
|
Instance Method Details
#add_credentials(username, password) ⇒ Object
78
79
80
|
# File 'lib/roadforest/remote-host.rb', line 78
def add_credentials(username, password)
prepared_credential_source.add(url, username, password)
end
|
#anneal(focus) ⇒ Object
95
96
97
98
99
100
101
102
|
# 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 ⇒ Object
#forbidden?(method, focus) ⇒ Boolean
205
206
207
208
209
|
# File 'lib/roadforest/remote-host.rb', line 205
def forbidden?(method, focus)
decider = AuthorizationDecider.new(self, focus)
decider.forbidden?(method)
end
|
#getting(&block) ⇒ Object
#graph_trace=(target) ⇒ Object
49
50
51
|
# File 'lib/roadforest/remote-host.rb', line 49
def graph_trace=(target)
graph_transfer.trace = target
end
|
#graph_transfer ⇒ Object
57
58
59
|
# File 'lib/roadforest/remote-host.rb', line 57
def graph_transfer
@graph_transfer ||= HTTP::GraphTransfer.new(user_agent)
end
|
#http_trace=(target) ⇒ Object
Also known as:
trace=
44
45
46
|
# File 'lib/roadforest/remote-host.rb', line 44
def http_trace=(target)
user_agent.trace = target
end
|
#posting(&block) ⇒ Object
233
234
235
236
237
238
239
|
# 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 ⇒ Object
71
72
73
74
75
76
|
# 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) ⇒ Object
245
246
247
248
249
250
251
252
|
# 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) ⇒ Object
223
224
225
226
227
228
229
230
231
|
# 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) ⇒ Object
91
92
93
|
# File 'lib/roadforest/remote-host.rb', line 91
def render_graph(graph)
Resource::ContentType::JSONLD.from_graph(graph)
end
|
#source_rigor ⇒ Object
82
83
84
85
86
87
88
89
|
# 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) ⇒ Object
211
212
213
214
215
216
217
218
219
220
221
|
# 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
|
#use_ca_cert(cert) ⇒ Object
61
62
63
64
|
# 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) ⇒ Object
66
67
68
69
|
# 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 ⇒ Object
53
54
55
|
# File 'lib/roadforest/remote-host.rb', line 53
def user_agent
@user_agent ||= HTTP::UserAgent.new(http_client)
end
|