Skip to content

Commit 20f587d

Browse files
committed
Finish 2.1.0
2 parents 6852c67 + 29e3b25 commit 20f587d

10 files changed

+78
-40
lines changed

.travis.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ script: "bundle exec rspec spec"
44
env:
55
- CI=true
66
rvm:
7-
- 2.0
8-
- 2.1
9-
- 2.2.4
10-
- 2.3.0
11-
- jruby-9.0.4.0
12-
- rbx-2
7+
- 2.2.5
8+
- 2.3.1
9+
- jruby
10+
- rbx
1311
gemfile:
1412
- Gemfile
1513
- Gemfile-pure
1614
cache: bundler
1715
sudo: false
1816
matrix:
1917
allow_failures:
20-
- rvm: rbx-2
18+
- rvm: rbx
19+
- rvm: jruby

Gemfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ source "https://rubygems.org"
22

33
gemspec
44

5-
gem 'rdf', github: "ruby-rdf/rdf", branch: "develop"
5+
gem 'rdf', github: "ruby-rdf/rdf", branch: "develop"
66
gem 'rdf-aggregate-repo', github: "ruby-rdf/rdf-aggregate-repo", branch: "develop"
7-
gem 'sparql', github: "ruby-rdf/sparql", branch: "develop"
7+
gem 'sparql', github: "ruby-rdf/sparql", branch: "develop"
88
gem "jruby-openssl", platforms: :jruby
99
gem "nokogiri", '~> 1.6'
1010

@@ -14,15 +14,14 @@ group :development, :test do
1414
gem 'rdf-spec', github: "ruby-rdf/rdf-spec", branch: "develop"
1515
gem 'rdf-turtle', github: "ruby-rdf/rdf-turtle", branch: "develop"
1616
gem "rdf-xsd", github: "ruby-rdf/rdf-xsd", branch: "develop"
17-
gem 'sxp', github: "gkellogg/sxp-ruby", branch: "develop"
17+
gem 'sxp', github: "dryruby/sxp.rb", branch: "develop"
1818
gem "redcarpet", platform: :ruby
1919
gem 'simplecov', require: false, platform: :mri
2020
gem 'coveralls', require: false, platform: :mri
2121
end
2222

2323
group :debug do
2424
gem 'shotgun'
25-
gem "wirble"
2625
gem "byebug", platforms: :mri
2726
end
2827

Gemfile-pure

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ source "https://rubygems.org"
22

33
gemspec
44

5-
gem 'rdf', github: "ruby-rdf/rdf", branch: "develop"
5+
gem 'rdf', github: "ruby-rdf/rdf", branch: "develop"
66
gem 'rdf-aggregate-repo', github: "ruby-rdf/rdf-aggregate-repo", branch: "develop"
7-
gem 'sparql', github: "ruby-rdf/sparql", branch: "develop"
7+
gem 'sparql', github: "ruby-rdf/sparql", branch: "develop"
88
gem "jruby-openssl", platforms: :jruby
99
#gem "nokogiri", '~> 1.6'
1010

@@ -14,7 +14,7 @@ group :development, :test do
1414
gem 'rdf-spec', github: "ruby-rdf/rdf-spec", branch: "develop"
1515
gem 'rdf-turtle', github: "ruby-rdf/rdf-turtle", branch: "develop"
1616
gem "rdf-xsd", github: "ruby-rdf/rdf-xsd", branch: "develop"
17-
gem 'sxp', github: "gkellogg/sxp-ruby", branch: "develop"
17+
gem 'sxp', github: "dryruby/sxp.rb", branch: "develop"
1818
gem "redcarpet", platform: :ruby
1919
gem 'simplecov', require: false, platform: :mri
2020
gem 'coveralls', require: false, platform: :mri

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ This is a [Ruby][] implementation of a [SPARQL][] client for [RDF.rb][].
9292

9393
##Dependencies
9494

95-
* [Ruby](http://ruby-lang.org/) (>= 2.0)
95+
* [Ruby](http://ruby-lang.org/) (>= 2.2.2)
9696
* [RDF.rb](http://rubygems.org/gems/rdf) (>= 2.0)
9797
* [Net::HTTP::Persistent](http://rubygems.org/gems/net-http-persistent) (>= 1.4)
98-
* Soft dependency on [SPARQL](http://rubygems.org/gems/sparql) (>= 1.1)
98+
* Soft dependency on [SPARQL](http://rubygems.org/gems/sparql) (>= 2.0)
9999
* Soft dependency on [Nokogiri](http://rubygems.org/gems/nokogiri) (>= 1.6)
100100

101101
##Installation

Rakefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ begin
66
rescue LoadError => e
77
end
88

9-
require 'sparql/client'
10-
119
namespace :gem do
1210
desc "Build the sparql-client-#{File.read('VERSION').chomp}.gem file"
1311
task :build do

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0
1+
2.1.0

dependencyci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
platform:
2+
Rubygems:
3+
rdf-isomorphic:
4+
tests:
5+
unmaintained: skip

lib/sparql/client.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ class ServerError < StandardError; end
3535
RESULT_JSON,
3636
RESULT_XML,
3737
RESULT_BOOL,
38-
"#{RESULT_TSV};p=0.8",
39-
"#{RESULT_CSV};p=0.2",
40-
'*/*;p=0.1'
38+
"#{RESULT_TSV};q=0.8",
39+
"#{RESULT_CSV};q=0.2",
40+
'*/*;q=0.1'
4141
].join(', ').freeze
4242
GRAPH_ALL = (
4343
RDF::Format.content_types.keys +
44-
['*/*;p=0.1']
44+
['*/*;q=0.1']
4545
).join(', ').freeze
4646

4747
ACCEPT_JSON = {'Accept' => RESULT_JSON}.freeze
@@ -291,6 +291,7 @@ def nodes
291291
# @see http://www.w3.org/TR/sparql11-protocol/#query-operation
292292
def query(query, options = {})
293293
@op = :query
294+
@alt_endpoint = options[:endpoint]
294295
case @url
295296
when RDF::Queryable
296297
require 'sparql' unless defined?(::SPARQL::Grammar)
@@ -317,13 +318,13 @@ def query(query, options = {})
317318
# @see http://www.w3.org/TR/sparql11-protocol/#update-operation
318319
def update(query, options = {})
319320
@op = :update
320-
@alt_endpoint = options[:endpoint] unless options[:endpoint].nil?
321+
@alt_endpoint = options[:endpoint]
321322
case @url
322323
when RDF::Queryable
323324
require 'sparql' unless defined?(::SPARQL::Grammar)
324325
SPARQL.execute(query, @url, options.merge(update: true))
325326
else
326-
parse_response(response(query, options), options)
327+
response(query, options)
327328
end
328329
self
329330
end
@@ -360,6 +361,8 @@ def response(query, options = {})
360361
# @return [Object]
361362
def parse_response(response, options = {})
362363
case options[:content_type] || response.content_type
364+
when NilClass
365+
response.body
363366
when RESULT_BOOL # Sesame-specific
364367
response.body == 'true'
365368
when RESULT_JSON
@@ -536,9 +539,11 @@ def self.parse_xml_value(value, nodes = {})
536539
# @param [Hash{Symbol => Object}] options
537540
# @return [RDF::Enumerable]
538541
def parse_rdf_serialization(response, options = {})
539-
options = {:content_type => response.content_type} if options.empty?
542+
options = {:content_type => response.content_type} unless options[:content_type]
540543
if reader = RDF::Reader.for(options)
541544
reader.new(response.body)
545+
else
546+
raise RDF::ReaderError, "no suitable rdf reader was found."
542547
end
543548
end
544549

@@ -678,8 +683,12 @@ def request(query, headers = {}, &block)
678683

679684
request.basic_auth(url.user, url.password) if url.user && !url.user.empty?
680685

686+
pre_http_hook(request) if respond_to?(:pre_http_hook)
687+
681688
response = @http.request(::URI.parse(url.to_s), request)
682689

690+
post_http_hook(response) if respond_to?(:post_http_hook)
691+
683692
10.times do
684693
if response.kind_of? Net::HTTPRedirection
685694
response = @http.request(::URI.parse(response['location']), request)

sparql-client.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
2828
gem.test_files = %w()
2929
gem.has_rdoc = false
3030

31-
gem.required_ruby_version = '>= 2.0'
31+
gem.required_ruby_version = '>= 2.2.2'
3232
gem.requirements = []
3333
gem.add_runtime_dependency 'rdf', '~> 2.0'
3434
gem.add_runtime_dependency 'net-http-persistent', '~> 2.9'

spec/client_spec.rb

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
require File.join(File.dirname(__FILE__), 'spec_helper')
33
require 'webmock/rspec'
44
require 'json'
5+
require 'rdf/turtle'
56

67
describe SPARQL::Client do
78
let(:query) {'DESCRIBE ?kb WHERE { ?kb <http://data.linkedmdb.org/resource/movie/actor_name> "Kevin Bacon" . }'}
89
let(:construct_query) {'CONSTRUCT {?kb <http://data.linkedmdb.org/resource/movie/actor_name> "Kevin Bacon" . } WHERE { ?kb <http://data.linkedmdb.org/resource/movie/actor_name> "Kevin Bacon" . }'}
910
let(:select_query) {'SELECT ?kb WHERE { ?kb <http://data.linkedmdb.org/resource/movie/actor_name> "Kevin Bacon" . }'}
1011
let(:describe_query) {'DESCRIBE ?kb WHERE { ?kb <http://data.linkedmdb.org/resource/movie/actor_name> "Kevin Bacon" . }'}
1112
let(:ask_query) {'ASK WHERE { ?kb <http://data.linkedmdb.org/resource/movie/actor_name> "Kevin Bacon" . }'}
13+
let(:update_query) {'DELETE {?s ?p ?o} WHERE {}'}
1214

1315
describe "#initialize" do
1416
it "calls block" do
@@ -24,7 +26,7 @@
2426

2527
def response(header)
2628
response = Net::HTTPSuccess.new '1.1', 200, 'body'
27-
response.content_type = header
29+
response.content_type = header if header
2830
allow(response).to receive(:body).and_return('body')
2931
response
3032
end
@@ -55,7 +57,7 @@ def response(header)
5557

5658
it "should handle successful response with plain header" do
5759
expect(subject).to receive(:request).and_yield response('text/plain')
58-
expect(RDF::Reader).to receive(:for).with(:content_type => 'text/plain')
60+
expect(RDF::Reader).to receive(:for).with(:content_type => 'text/plain').and_call_original
5961
subject.query(query)
6062
end
6163

@@ -94,15 +96,14 @@ def response(header)
9496
subject.query(query, :content_type => SPARQL::Client::RESULT_JSON)
9597
end
9698

97-
it "should handle successful response with overridden JSON header" do
98-
expect(subject).to receive(:request).and_yield response(SPARQL::Client::RESULT_JSON)
99-
expect(subject.class).to receive(:parse_xml_bindings)
100-
subject.query(query, :content_type => SPARQL::Client::RESULT_XML)
99+
it "should handle successful response with no content type" do
100+
expect(subject).to receive(:request).and_yield response(nil)
101+
expect { subject.query(query) }.not_to raise_error
101102
end
102103

103104
it "should handle successful response with overridden plain header" do
104105
expect(subject).to receive(:request).and_yield response('text/plain')
105-
expect(RDF::Reader).to receive(:for).with(:content_type => 'text/turtle')
106+
expect(RDF::Reader).to receive(:for).with(:content_type => 'text/turtle').and_call_original
106107
subject.query(query, :content_type => 'text/turtle')
107108
end
108109

@@ -122,7 +123,7 @@ def response(header)
122123

123124
it "should enable overriding the http method" do
124125
stub_request(:get, "http://data.linkedmdb.org/sparql?query=DESCRIBE%20?kb%20WHERE%20%7B%20?kb%20%3Chttp://data.linkedmdb.org/resource/movie/actor_name%3E%20%22Kevin%20Bacon%22%20.%20%7D").
125-
to_return(:status => 200, :body => "", :headers => {})
126+
to_return(:status => 200, :body => "", :headers => { 'Content-Type' => 'application/n-triples'})
126127
allow(subject).to receive(:request_method).with(query).and_return(:get)
127128
expect(subject).to receive(:make_get_request).and_call_original
128129
subject.query(query)
@@ -152,7 +153,7 @@ def response(header)
152153

153154
it 'follows redirects' do
154155
WebMock.stub_request(:any, 'http://sparql.linkedmdb.org/sparql').
155-
to_return(:body => '{}', :status => 200)
156+
to_return(:body => '{}', :status => 200, :headers => { :content_type => SPARQL::Client::RESULT_JSON})
156157
subject.query(ask_query)
157158
expect(WebMock).to have_requested(:post, "http://sparql.linkedmdb.org/sparql").
158159
with(:body => 'query=ASK+WHERE+%7B+%3Fkb+%3Chttp%3A%2F%2Fdata.linkedmdb.org%2Fresource%2Fmovie%2Factor_name%3E+%22Kevin+Bacon%22+.+%7D')
@@ -171,31 +172,58 @@ def response(header)
171172
to_return(:body => '{}', :status => 200, :headers => { 'Content-Type' => 'application/sparql-results+json'})
172173
subject.query(ask_query)
173174
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/sparql").
174-
with(:headers => {'Accept'=>'application/sparql-results+json, application/sparql-results+xml, text/boolean, text/tab-separated-values;p=0.8, text/csv;p=0.2, */*;p=0.1'})
175+
with(:headers => {'Accept'=>'application/sparql-results+json, application/sparql-results+xml, text/boolean, text/tab-separated-values;q=0.8, text/csv;q=0.2, */*;q=0.1'})
175176
end
176177

177178
it "should use application/n-triples for CONSTRUCT" do
178179
WebMock.stub_request(:any, 'http://data.linkedmdb.org/sparql').
179180
to_return(:body => '', :status => 200, :headers => { 'Content-Type' => 'application/n-triples'})
180181
subject.query(construct_query)
181182
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/sparql").
182-
with(:headers => {'Accept'=>'application/n-triples, text/plain, */*;p=0.1'})
183+
with(:headers => {'Accept'=>'application/n-triples, text/plain, */*;q=0.1'})
183184
end
184185

185186
it "should use application/n-triples for DESCRIBE" do
186187
WebMock.stub_request(:any, 'http://data.linkedmdb.org/sparql').
187188
to_return(:body => '', :status => 200, :headers => { 'Content-Type' => 'application/n-triples'})
188189
subject.query(describe_query)
189190
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/sparql").
190-
with(:headers => {'Accept'=>'application/n-triples, text/plain, */*;p=0.1'})
191+
with(:headers => {'Accept'=>'application/n-triples, text/plain, */*;q=0.1'})
191192
end
192193

193194
it "should use application/sparql-results+json for SELECT" do
194195
WebMock.stub_request(:any, 'http://data.linkedmdb.org/sparql').
195196
to_return(:body => '{}', :status => 200, :headers => { 'Content-Type' => 'application/sparql-results+json'})
196197
subject.query(select_query)
197198
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/sparql").
198-
with(:headers => {'Accept'=>'application/sparql-results+json, application/sparql-results+xml, text/boolean, text/tab-separated-values;p=0.8, text/csv;p=0.2, */*;p=0.1'})
199+
with(:headers => {'Accept'=>'application/sparql-results+json, application/sparql-results+xml, text/boolean, text/tab-separated-values;q=0.8, text/csv;q=0.2, */*;q=0.1'})
200+
end
201+
end
202+
203+
context "Alternative Endpoint" do
204+
it "should use the default endpoint if no alternative endpoint is provided" do
205+
WebMock.stub_request(:any, 'http://data.linkedmdb.org/sparql').
206+
to_return(:body => '', :status => 200)
207+
subject.update(update_query)
208+
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/sparql")
209+
end
210+
211+
it "should use the alternative endpoint if provided" do
212+
WebMock.stub_request(:any, 'http://data.linkedmdb.org/alternative').
213+
to_return(:body => '', :status => 200)
214+
subject.update(update_query, { endpoint: "http://data.linkedmdb.org/alternative" })
215+
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/alternative")
216+
end
217+
218+
it "should not use the alternative endpoint for a select query" do
219+
WebMock.stub_request(:any, 'http://data.linkedmdb.org/sparql').
220+
to_return(:body => '', :status => 200)
221+
WebMock.stub_request(:any, 'http://data.linkedmdb.org/alternative').
222+
to_return(:body => '', :status => 200)
223+
subject.update(update_query, { endpoint: "http://data.linkedmdb.org/alternative" })
224+
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/alternative")
225+
subject.query(select_query)
226+
expect(WebMock).to have_requested(:post, "http://data.linkedmdb.org/sparql")
199227
end
200228
end
201229

0 commit comments

Comments
 (0)