Skip to content

Commit e6772d2

Browse files
committed
allow api_get of raw query
1 parent 19a33a4 commit e6772d2

5 files changed

Lines changed: 25 additions & 25 deletions

File tree

lib/rdf/virtuoso/query.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,6 @@ def delete(*patterns)
228228
self
229229
end
230230

231-
# def delete(*variables)
232-
# @values = variables.map { |var|
233-
# [var, var.is_a?(RDF::URI) ? var : RDF::Query::Variable.new(var)]
234-
# }
235-
# self
236-
# end
237-
238231
def create(uri)
239232
options[:graph] = uri
240233
self
@@ -271,8 +264,6 @@ def from(uri)
271264
def from_named(uri)
272265
(options[:from_named] ||= []) << uri
273266
self
274-
#options[:from_named] = uri
275-
#self
276267
end
277268

278269
# @param RDF::URI uri
@@ -350,7 +341,6 @@ def reduced(state = true)
350341

351342
AGG_METHODS.each do |m|
352343
define_method m do |*variables|
353-
#options[m.to_sym] = variables
354344
options[m.to_sym] ||= []
355345
options[m.to_sym] += variables
356346
self
@@ -507,7 +497,6 @@ def to_s
507497
aggregates = [:count, :min, :max, :avg, :sum, :sample, :group_concat, :group_digest]
508498
if (options.keys & aggregates).any?
509499
(options.keys & aggregates).each do |agg|
510-
#p options[agg]
511500
case agg
512501
when :sample
513502
# multiple samples splits to individual sample expressions

lib/rdf/virtuoso/repository.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module RDF
77
module Virtuoso
8-
class Repository
8+
class Repository < ::RDF::Repository
99
include APISmith::Client
1010

1111
RESULT_JSON = 'application/sparql-results+json'.freeze
@@ -20,7 +20,6 @@ class MalformedQuery < ClientError; end
2020
class NotAuthorized < ClientError; end
2121
class ServerError < StandardError; end
2222

23-
# TODO: Look at issues with HTTParty Connection reset
2423
#persistent
2524
maintain_method_across_redirects true
2625

@@ -41,8 +40,8 @@ def initialize(uri, opts={})
4140
self.class.base_uri @base_uri
4241
end
4342

44-
READ_METHODS = %w(select ask construct describe)
45-
WRITE_METHODS = %w(query insert insert_data update delete delete_data create drop clear)
43+
READ_METHODS = %w(query select ask construct describe)
44+
WRITE_METHODS = %w(insert insert_data update delete delete_data create drop clear)
4645

4746
READ_METHODS.each do |m|
4847
define_method m do |*args|
@@ -74,7 +73,6 @@ def headers
7473
end
7574

7675
def base_query_options
77-
#{ :format => 'json' }
7876
{ :format => RESULT_JSON }
7977
end
8078

@@ -107,6 +105,7 @@ def api_get(query, options = {})
107105
else
108106
self.class.endpoint @sparql_endpoint
109107
Timeout::timeout(@timeout) {
108+
puts self.inspect
110109
get '/', :extra_query => { :query => query }.merge(options),
111110
:transform => RDF::Virtuoso::Parser::JSON
112111
}

rdf-virtuoso.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Gem::Specification.new do |s|
1010
s.email = ['benjamin.rokseth@kul.oslo.kommune.no']
1111
s.homepage = 'https://github.com/digibib/rdf-virtuoso'
1212
s.summary = %q{An RDF.rb extension library for interacting with a Virtuoso rdf store}
13-
s.description = %q{An RDF.rb extension library for interacting with a Virtuoso rdf store}
13+
s.description = %q{An RDF.rb extension library for interacting with a Virtuoso rdf store.\nSupports SPARQL 1.1 UPDATE extensions and some Virtuoso specific commands.}
14+
s.licenses = ['GPL-3']
1415

1516
s.rubyforge_project = 'rdf-virtuoso'
1617

spec/repository_spec.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
$:.unshift "."
2-
require 'spec_helper'
2+
require File.join(File.dirname(__FILE__), 'spec_helper')
33
require 'rdf/spec/repository'
4+
45
#require_relative '../lib/rdf/virtuoso/repository'
6+
57
describe RDF::Virtuoso::Repository do
68

79
before(:each) do
810
@uri = "http://localhost:8890/sparql"
911
@update_uri = "http://localhost:8890/sparql-auth"
12+
@repository = RDF::Virtuoso::Repository.new(@uri)
1013
end
11-
12-
it "should mixin RDF::Repository" do
13-
@repository = RDF::Virtuoso::Repository.new(@uri)
14-
#it_should_behave_like RDF_Repository # not working!
15-
end
16-
14+
15+
#include RDF_Repository # not implemented
16+
1717
it "should support connecting to a Virtuoso SPARQL endpoint" do
1818
repo = RDF::Virtuoso::Repository.new(@uri)
1919
repo.instance_variable_get("@sparul_endpoint").should == "/sparql"
@@ -38,4 +38,11 @@
3838
repo = RDF::Virtuoso::Repository.new(@uri, :timeout => 10)
3939
repo.instance_variable_get("@timeout").should == 10
4040
end
41+
42+
it "should support custom query" do
43+
q = "CONSTRUCT {?s a rdf:resource} WHERE {?s a ?type} LIMIT 1"
44+
repo = RDF::Virtuoso::Repository.new(@uri, :update_uri => @update_uri, :username => 'dba', :password => 'virtuoso99admin', :auth_method => 'digest')
45+
result = repo.query(q)
46+
result.first[:p].should == RDF.type
47+
end
4148
end

spec/spec_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22
require 'rspec'
33
require 'rdf'
44
require 'rdf/spec'
5+
require 'rdf/spec/matchers'
56
require 'rdf/virtuoso'
6-
require 'rdf/spec/repository'
7+
8+
RSpec.configure do |config|
9+
config.include(RDF::Spec::Matchers)
10+
end

0 commit comments

Comments
 (0)