class Marmotta::Connection
Attributes
context[R]
uri[R]
Public Class Methods
new(uri:, context: "default")
click to toggle source
# File lib/marmotta/connection.rb, line 4 def initialize(uri:, context: "default") @uri = uri @context = context end
Public Instance Methods
delete(resource_uri)
click to toggle source
Deletes a subject from the context. @param [String, to_s] resource_uri URI of resource to delete. @return [True, False] Result of deleting. @todo Should this only delete triples from the given context?
# File lib/marmotta/connection.rb, line 38 def delete(resource_uri) connection.delete("resource") do |request| request.query[:uri] = resource_uri.to_s request.query.delete(:graph) end end
delete_all()
click to toggle source
# File lib/marmotta/connection.rb, line 9 def delete_all connection.delete("context/#{context}") do |c| c.query.delete(:graph) end end
get(resource_uri)
click to toggle source
Returns an RDFSource represented by the resource URI. @param [String, to_s] resource_uri URI to request @return [RDF::Graph] The resulting graph
# File lib/marmotta/connection.rb, line 18 def get(resource_uri) result = connection.get("resource") do |request| request.query[:uri] = resource_uri.to_s request.query.delete(:graph) end MaybeGraphResult.new(result).value end
ldpath(path)
click to toggle source
Returns an LDPath connection for a given path. @param [String, to_s] path LDPath query to run @return [LdPathConnection] Connection
which will run that path query.
# File lib/marmotta/connection.rb, line 48 def ldpath(path) LdPathConnection.new(connection, path) end
post(graph)
click to toggle source
Posts a graph to Marmotta
in the appropriate context. @param [RDF::Enumerable] graph The graph to post. @return [True, False] Result of posting.
# File lib/marmotta/connection.rb, line 29 def post(graph) sparql_update_client.insert_data(graph, :graph => context_uri.to_s) true end
Private Instance Methods
connection()
click to toggle source
# File lib/marmotta/connection.rb, line 54 def connection @connection ||= ::Hurley::Client.new(uri).tap do |c| c.header[:accept] = mime_type c.header[:content_type] = mime_type c.query[:graph] = context_uri.to_s end end
context_uri()
click to toggle source
@todo Support arbitrary non-Marmotta contexts.
# File lib/marmotta/connection.rb, line 71 def context_uri ::RDF::URI("#{uri}/context/#{context}") end
mime_type()
click to toggle source
# File lib/marmotta/connection.rb, line 66 def mime_type "application/ld+json" end
sparql_update_client()
click to toggle source
# File lib/marmotta/connection.rb, line 62 def sparql_update_client @sparql_update_client ||= SPARQL::Client.new("#{uri}/sparql/update") end