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, options = {}) ⇒ Client
constructor
A new instance of Client.
- #query(query, options = {}) ⇒ Object
- #up? ⇒ Boolean
Constructor Details
#initialize(endpoint, options = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/solis/store/sparql/client.rb', line 10 def initialize(endpoint, = {}) @endpoint = endpoint @graph_name = [:graph_name] || '' @read_timeout = [:read_timeout] || 120 @logger = [:logger] || Solis::LOGGER @pool = ConnectionPool.new(size:5, timeout: 160) do Solis::LOGGER.level = Logger::DEBUG if ConfigFile[:debug] if @graph_name client = SPARQL::Client.new(@endpoint, graph: @graph_name, read_timeout: @read_timeout, logger: @logger) else client = SPARQL::Client.new(@endpoint, read_timeout: @read_timeout, logger: @logger) end client end end |
Instance Method Details
#query(query, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/solis/store/sparql/client.rb', line 39 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
29 30 31 32 33 34 35 36 37 |
# File 'lib/solis/store/sparql/client.rb', line 29 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 |