Class: FourStore::Store
- Inherits:
-
Object
- Object
- FourStore::Store
- Defined in:
- lib/four_store/store.rb
Instance Method Summary collapse
- #add(graph, turtle) ⇒ Object
- #delete(graph) ⇒ Object
-
#initialize(endpoint, options = nil) ⇒ Store
constructor
A new instance of Store.
- #load(uri) ⇒ Object
- #select(query) ⇒ Object
- #set(graph, turtle) ⇒ Object
Constructor Details
#initialize(endpoint, options = nil) ⇒ Store
Returns a new instance of Store.
10 11 12 13 14 15 16 17 |
# File 'lib/four_store/store.rb', line 10 def initialize(endpoint, = nil) raise "4Store SPARQL end-point URI must end by '/sparql/'" if endpoint.split("/sparql/").size != 1 @endpoint = URI.parse(endpoint) @proxy = URI.parse(ENV['HTTP_PROXY']) if ENV['HTTP_PROXY'] @certificate = ["certificate"] if @key = ["key"] if @softlimit = ["soft-limit"] if end |
Instance Method Details
#add(graph, turtle) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/four_store/store.rb', line 37 def add(graph, turtle) http.start do |h| request = Net::HTTP::Post.new((@endpoint.path.split("/sparql/")[0] or "") + "/data/") request.set_form_data({ 'graph' => graph, 'data' => Namespace::to_turtle + turtle, 'mime-type' => 'application/x-turtle' }) response = h.request(request) end end |
#delete(graph) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/four_store/store.rb', line 49 def delete(graph) http.start do |h| request = Net::HTTP::Delete.new(@endpoint.path + graph) response = h.request(request) end end |
#load(uri) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/four_store/store.rb', line 56 def load(uri) # WARNING - relies on the -U flag being set when running 4s-httpd http.start do |h| request = Net::HTTP::Post.new((@endpoint.path.split("/sparql/")[0] or "") + "/update/") request.set_form_data({ 'update' => "LOAD <#{uri}>" }) response = h.request(request) end end |
#select(query) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/four_store/store.rb', line 19 def select(query) http.start do |h| request = Net::HTTP::Post.new(@endpoint.path) request.set_form_data({ 'query' => Namespace::to_sparql + query, 'soft-limit' => @softlimit }) response = h.request(request) parse_sparql_xml_results(response.body) end end |
#set(graph, turtle) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/four_store/store.rb', line 28 def set(graph, turtle) http.start do |h| request = Net::HTTP::Put.new(@endpoint.path + graph) request.body = Namespace::to_turtle + turtle request.content_type = 'application/x-turtle' response = h.request(request) end end |