Class: Solis::Store::Sparql::Client
- Inherits:
-
Object
- Object
- Solis::Store::Sparql::Client
- Defined in:
- lib/solis/store/sparql/client.rb,
lib/solis/store/sparql/client/query.rb
Defined Under Namespace
Classes: Query
Instance Method Summary collapse
-
#initialize(endpoint, graph_name) ⇒ Client
constructor
A new instance of Client.
- #query(query) ⇒ Object
- #up? ⇒ Boolean
Constructor Details
#initialize(endpoint, graph_name) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 |
# File 'lib/solis/store/sparql/client.rb', line 10 def initialize(endpoint, graph_name) @endpoint = endpoint @graph_name = graph_name @pool = ConnectionPool.new(size:5, timeout: 60) do SPARQL::Client.new(@endpoint, graph: @graph_name) #SPARQL::Client.new(@endpoint) end end |
Instance Method Details
#query(query) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/solis/store/sparql/client.rb', line 30 def query(query) raise Solis::Error::NotFoundError, "Server or graph(#{@graph_name} not found" unless up? result = nil @pool.with do |c| result = Query.new(c).run(query) end result end |
#up? ⇒ Boolean
20 21 22 23 24 25 26 27 28 |
# File 'lib/solis/store/sparql/client.rb', line 20 def up? result = nil @pool.with do |c| result = c.query("ASK WHERE { ?s ?p ?o }") end result rescue HTTP::Error => e return false end |