iq_triplestorage 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/iq_triplestorage.rb +3 -3
- data/lib/iq_triplestorage/sesame_adaptor.rb +9 -2
- data/test/sesame_test.rb +13 -7
- metadata +2 -8
data/lib/iq_triplestorage.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module IqTriplestorage
|
2
|
-
VERSION = "0.2.
|
2
|
+
VERSION = "0.2.2"
|
3
3
|
|
4
4
|
class BaseAdaptor
|
5
5
|
attr_reader :host
|
@@ -10,13 +10,13 @@ module IqTriplestorage
|
|
10
10
|
@password = options[:password]
|
11
11
|
end
|
12
12
|
|
13
|
-
def http_request(method, path, body, headers={})
|
13
|
+
def http_request(method, path, body=nil, headers={})
|
14
14
|
uri = URI.join("#{@host}/", path)
|
15
15
|
|
16
16
|
req = Net::HTTP.const_get(method.to_s.downcase.capitalize).new(uri.to_s)
|
17
17
|
req.basic_auth(@username, @password) if (@username && @password)
|
18
18
|
headers.each { |key, value| req[key] = value }
|
19
|
-
req.body = body
|
19
|
+
req.body = body if body
|
20
20
|
|
21
21
|
return Net::HTTP.new(uri.host, uri.port).request(req)
|
22
22
|
end
|
@@ -16,11 +16,18 @@ class IqTriplestorage::SesameAdaptor < IqTriplestorage::BaseAdaptor
|
|
16
16
|
path = "/repositories/#{CGI.escape(@repo)}/statements"
|
17
17
|
path = URI.join("#{@host}/", path[1..-1]).path
|
18
18
|
|
19
|
+
del_params = triples_by_graph.keys.
|
20
|
+
map { |graph| val = CGI.escape("<#{graph}>"); "context=#{val}" }.
|
21
|
+
join("&")
|
22
|
+
res = http_request("DELETE", "#{path}?#{del_params}")
|
23
|
+
return false unless res.code == "204"
|
24
|
+
|
19
25
|
data = triples_by_graph.map do |graph_uri, ntriples|
|
20
26
|
"<#{graph_uri}> {\n#{ntriples}\n}\n"
|
21
27
|
end.join("\n\n")
|
22
|
-
|
23
|
-
|
28
|
+
res = http_request("POST", path, data,
|
29
|
+
{ "Content-Type" => "application/x-trig" })
|
30
|
+
return res.code == "204"
|
24
31
|
end
|
25
32
|
|
26
33
|
end
|
data/test/sesame_test.rb
CHANGED
@@ -9,9 +9,7 @@ class SesameTest < WebTestCase
|
|
9
9
|
def setup
|
10
10
|
super
|
11
11
|
WebMock.stub_request(:any, /.*example.org.*/).with(&@request_handler).
|
12
|
-
to_return
|
13
|
-
{ :status => req.uri.to_s.end_with?("/rdf_sink") ? 200 : 201 }
|
14
|
-
end
|
12
|
+
to_return { |req| { :status => 204 } }
|
15
13
|
|
16
14
|
@host = "http://example.org/sesame"
|
17
15
|
@repo = "test"
|
@@ -28,11 +26,19 @@ class SesameTest < WebTestCase
|
|
28
26
|
"http://example.com/bar" => "<ggg> <hhh> <iii> .\n<jjj> <kkk> <lll> ."
|
29
27
|
}
|
30
28
|
|
29
|
+
@observers << lambda do |req|
|
30
|
+
assert_equal :delete, req.method
|
31
|
+
assert_equal "/sesame/repositories/#{CGI.escape(@repo)}/statements",
|
32
|
+
req.uri.path
|
33
|
+
# XXX: currently cannot test query parameters due to WebMock issues:
|
34
|
+
# https://github.com/bblimke/webmock/issues/226
|
35
|
+
# https://github.com/bblimke/webmock/issues/227
|
36
|
+
#assert_equal "context=...", req.uri.query
|
37
|
+
end
|
31
38
|
@observers << lambda do |req|
|
32
39
|
assert_equal :post, req.method
|
33
|
-
|
34
|
-
|
35
|
-
start_with?("/sesame/repositories/#{CGI.escape(@repo)}/statements")
|
40
|
+
assert_equal "/sesame/repositories/#{CGI.escape(@repo)}/statements",
|
41
|
+
req.uri.path
|
36
42
|
assert_equal "application/x-trig", req.headers["Content-Type"]
|
37
43
|
data.each do |graph_uri, ntriples|
|
38
44
|
assert req.body.include?(<<-EOS)
|
@@ -42,7 +48,7 @@ class SesameTest < WebTestCase
|
|
42
48
|
EOS
|
43
49
|
end
|
44
50
|
end
|
45
|
-
|
51
|
+
assert_equal true, @adaptor.batch_update(data)
|
46
52
|
end
|
47
53
|
|
48
54
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iq_triplestorage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -42,18 +42,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
42
|
- - ! '>='
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
|
-
segments:
|
46
|
-
- 0
|
47
|
-
hash: -3716524453347900390
|
48
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
46
|
none: false
|
50
47
|
requirements:
|
51
48
|
- - ! '>='
|
52
49
|
- !ruby/object:Gem::Version
|
53
50
|
version: '0'
|
54
|
-
segments:
|
55
|
-
- 0
|
56
|
-
hash: -3716524453347900390
|
57
51
|
requirements: []
|
58
52
|
rubyforge_project: iq_triplestorage
|
59
53
|
rubygems_version: 1.8.23
|