ldp 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/lib/ldp/client/methods.rb +11 -11
- data/lib/ldp/orm.rb +3 -3
- data/lib/ldp/resource.rb +6 -6
- data/lib/ldp/resource/rdf_source.rb +39 -17
- data/lib/ldp/version.rb +1 -1
- data/spec/lib/ldp/resource/rdf_source_spec.rb +24 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f66622678bcc98c5f6466a33d8ff1d6203fe2e4f
|
4
|
+
data.tar.gz: 35bc0630a59c9c881e5b6f7c4d5c07138dda3619
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a2d387ff7e6ccbd5c873e169c57ed49225ab6fd6b51ef783b1bd84cfac08a133ed518fb31defd5764e3be667483dde5c022a849d44394d9c08a5dde413cb27b
|
7
|
+
data.tar.gz: f7195ee962860939ed50c60007226d697c84e2544f897c43b926f8f971ac7406f7ab9c1facb7de01ecc11be62454f541a551cc8f2000c246d4ec28eb698841c6
|
data/lib/ldp/client/methods.rb
CHANGED
@@ -3,19 +3,19 @@ require 'faraday'
|
|
3
3
|
##
|
4
4
|
# HTTP client methods for making requests to an LDP resource and getting a response back.
|
5
5
|
module Ldp::Client::Methods
|
6
|
-
|
6
|
+
|
7
7
|
attr_reader :http
|
8
8
|
def initialize_http_client *http_client
|
9
9
|
if http_client.length == 1 and http_client.first.is_a? Faraday::Connection
|
10
10
|
@http = http_client.first
|
11
|
-
else
|
12
|
-
@http = Faraday.new *http_client
|
11
|
+
else
|
12
|
+
@http = Faraday.new *http_client
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def head url
|
17
17
|
logger.debug "LDP: HEAD [#{url}]"
|
18
|
-
resp = http.head do |req|
|
18
|
+
resp = http.head do |req|
|
19
19
|
req.url munge_to_relative_url(url)
|
20
20
|
|
21
21
|
yield req if block_given?
|
@@ -27,7 +27,7 @@ module Ldp::Client::Methods
|
|
27
27
|
# Get a LDP Resource by URI
|
28
28
|
def get url, options = {}
|
29
29
|
logger.debug "LDP: GET [#{url}]"
|
30
|
-
resp = http.get do |req|
|
30
|
+
resp = http.get do |req|
|
31
31
|
req.url munge_to_relative_url(url)
|
32
32
|
|
33
33
|
if options[:minimal]
|
@@ -35,7 +35,7 @@ module Ldp::Client::Methods
|
|
35
35
|
else
|
36
36
|
includes = Array(options[:include]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" }
|
37
37
|
omits = Array(options[:omit]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" }
|
38
|
-
req.headers["Prefer"] = ["return=representation",
|
38
|
+
req.headers["Prefer"] = ["return=representation",
|
39
39
|
("include=\"#{includes.join(" ")}\"" unless includes.empty?),
|
40
40
|
("omit=\"#{omits.join(" ")}\"" unless omits.empty?)
|
41
41
|
].compact.join("; ")
|
@@ -49,7 +49,7 @@ module Ldp::Client::Methods
|
|
49
49
|
else
|
50
50
|
resp
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
check_for_errors(resp)
|
54
54
|
end
|
55
55
|
|
@@ -100,7 +100,7 @@ module Ldp::Client::Methods
|
|
100
100
|
check_for_errors(resp)
|
101
101
|
end
|
102
102
|
private
|
103
|
-
|
103
|
+
|
104
104
|
def check_for_errors resp
|
105
105
|
resp.tap do |resp|
|
106
106
|
unless resp.success?
|
@@ -119,14 +119,14 @@ module Ldp::Client::Methods
|
|
119
119
|
def default_headers
|
120
120
|
{"Content-Type"=>"text/turtle"}
|
121
121
|
end
|
122
|
-
|
122
|
+
|
123
123
|
def default_patch_headers
|
124
124
|
{"Content-Type"=>"application/sparql-update"}
|
125
125
|
end
|
126
126
|
##
|
127
127
|
# Some valid query paths can be mistaken for absolute URIs
|
128
128
|
# with an alternative scheme. If the scheme isn't HTTP(S), assume
|
129
|
-
# they meant a relative URI instead.
|
129
|
+
# they meant a relative URI instead.
|
130
130
|
def munge_to_relative_url url
|
131
131
|
purl = URI.parse(url)
|
132
132
|
if purl.absolute? and !((purl.scheme rescue nil) =~ /^http/)
|
data/lib/ldp/orm.rb
CHANGED
data/lib/ldp/resource.rb
CHANGED
@@ -44,7 +44,7 @@ module Ldp
|
|
44
44
|
def get
|
45
45
|
@get ||= client.get(subject)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def head
|
49
49
|
@head ||= @get || client.head(subject)
|
50
50
|
end
|
@@ -56,11 +56,11 @@ module Ldp
|
|
56
56
|
req.headers['If-Match'] = get.etag if retrieved_content?
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def save
|
61
61
|
new? ? create : update
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
##
|
65
65
|
# Create a new resource at the URI
|
66
66
|
# @return [RdfSource] the new representation
|
@@ -68,7 +68,7 @@ module Ldp
|
|
68
68
|
raise "Can't call create on an existing resource" unless new?
|
69
69
|
verb = subject.nil? ? :post : :put
|
70
70
|
resp = client.send(verb, (subject || @base_path), content) do |req|
|
71
|
-
|
71
|
+
|
72
72
|
yield req if block_given?
|
73
73
|
end
|
74
74
|
|
@@ -76,7 +76,7 @@ module Ldp
|
|
76
76
|
@subject_uri = nil
|
77
77
|
reload
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
##
|
81
81
|
# Update the stored graph
|
82
82
|
def update new_content = nil
|
@@ -91,7 +91,7 @@ module Ldp
|
|
91
91
|
def current? response = nil
|
92
92
|
response ||= @get
|
93
93
|
return true if new? and subject.nil?
|
94
|
-
|
94
|
+
|
95
95
|
new_response = client.head(subject)
|
96
96
|
|
97
97
|
response.headers['ETag'] &&
|
@@ -14,39 +14,61 @@ module Ldp
|
|
14
14
|
raise ArgumentError, "Third argument to #{self.class}.new should be a RDF::Graph or a Ldp::Response. You provided #{graph_or_response.class}"
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
def create
|
19
19
|
super do |req|
|
20
20
|
req.headers = { "Content-Type" => "text/turtle" }
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def content
|
25
25
|
graph.dump(:ttl) if graph
|
26
26
|
end
|
27
27
|
|
28
28
|
def graph
|
29
|
-
@graph ||=
|
30
|
-
|
31
|
-
original_graph = get.graph
|
29
|
+
@graph ||= new? ? build_empty_graph : build_graph(get.graph)
|
30
|
+
end
|
32
31
|
|
33
|
-
|
32
|
+
def build_empty_graph
|
33
|
+
graph_class.new
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
##
|
37
|
+
# graph_class may be overridden so that a subclass of RDF::Graph
|
38
|
+
# is returned (e.g. an ActiveTriples resource)
|
39
|
+
# @returns [Class] a class that is an descendant of RDF::Graph
|
40
|
+
def graph_class
|
41
|
+
RDF::Graph
|
42
|
+
end
|
38
43
|
|
39
|
-
original_graph.each_statement do |s|
|
40
|
-
unless inlinedResources.include? s.subject
|
41
|
-
new_graph << s
|
42
|
-
end
|
43
|
-
end
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
##
|
49
|
+
# @param [RDF::Graph] original_graph The graph returned by the LDP server
|
50
|
+
# @return [RDF::Graph] A graph striped of any inlined resources present in the original
|
51
|
+
def build_graph(original_graph)
|
52
|
+
inlined_resources = get.graph.query(predicate: Ldp.contains).map { |x| x.object }
|
53
|
+
|
54
|
+
# we want to scope this graph to just statements about this model, not contained relations
|
55
|
+
if inlined_resources.empty?
|
47
56
|
original_graph
|
57
|
+
else
|
58
|
+
graph_without_inlined_resources(original_graph, inlined_resources)
|
48
59
|
end
|
49
60
|
end
|
50
|
-
|
61
|
+
|
62
|
+
def graph_without_inlined_resources(original_graph, inlined_resources)
|
63
|
+
new_graph = build_empty_graph
|
64
|
+
|
65
|
+
original_graph.each_statement do |s|
|
66
|
+
unless inlined_resources.include? s.subject
|
67
|
+
new_graph << s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
new_graph
|
72
|
+
end
|
51
73
|
end
|
52
74
|
end
|
data/lib/ldp/version.rb
CHANGED
@@ -7,7 +7,6 @@ describe Ldp::Resource::RdfSource do
|
|
7
7
|
|
8
8
|
let(:conn_stubs) do
|
9
9
|
Faraday::Adapter::Test::Stubs.new do |stub|
|
10
|
-
# stub.get('/a_resource') {[ 200, {"Link" => "<http://www.w3.org/ns/ldp#Resource>;rel=\"type\""}, simple_graph ]}
|
11
10
|
stub.post("/") { [201]}
|
12
11
|
stub.put("/abs_url_object") { [201]}
|
13
12
|
end
|
@@ -32,7 +31,7 @@ describe Ldp::Resource::RdfSource do
|
|
32
31
|
created_resource = subject.create
|
33
32
|
expect(created_resource).to be_kind_of Ldp::Resource::RdfSource
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
it "should allow absolute URLs to the LDP server" do
|
37
36
|
obj = Ldp::Resource::RdfSource.new mock_client, "http://my.ldp.server/abs_url_object"
|
38
37
|
allow(obj).to receive(:new?).and_return(true)
|
@@ -49,4 +48,27 @@ describe Ldp::Resource::RdfSource do
|
|
49
48
|
end
|
50
49
|
end
|
51
50
|
end
|
51
|
+
|
52
|
+
context "When graph_class is overridden" do
|
53
|
+
before do
|
54
|
+
class SpecialGraph < RDF::Graph; end
|
55
|
+
|
56
|
+
class SpecialResource < Ldp::Resource::RdfSource
|
57
|
+
def graph_class
|
58
|
+
SpecialGraph
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
after do
|
64
|
+
Object.send(:remove_const, :SpecialGraph)
|
65
|
+
Object.send(:remove_const, :SpecialResource)
|
66
|
+
end
|
67
|
+
|
68
|
+
subject { SpecialResource.new mock_client, nil }
|
69
|
+
|
70
|
+
it "should use the specified class" do
|
71
|
+
expect(subject.graph).to be_a SpecialGraph
|
72
|
+
end
|
73
|
+
end
|
52
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ldp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
168
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
169
|
+
rubygems_version: 2.2.2
|
170
170
|
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: Linked Data Platform client library
|