ldp 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/bin/ldp +127 -0
- data/ldp.gemspec +2 -0
- data/lib/ldp/client/methods.rb +89 -12
- data/lib/ldp/client.rb +18 -21
- data/lib/ldp/container/basic.rb +23 -0
- data/lib/ldp/container/direct.rb +16 -0
- data/lib/ldp/container/indirect.rb +11 -0
- data/lib/ldp/container.rb +23 -9
- data/lib/ldp/orm.rb +49 -20
- data/lib/ldp/resource/binary_source.rb +23 -0
- data/lib/ldp/resource/rdf_source.rb +77 -0
- data/lib/ldp/resource.rb +39 -70
- data/lib/ldp/response/paging.rb +57 -0
- data/lib/ldp/response.rb +59 -95
- data/lib/ldp/uri.rb +37 -5
- data/lib/ldp/version.rb +1 -1
- data/lib/ldp.rb +11 -1
- data/spec/lib/ldp/client_spec.rb +71 -30
- data/spec/lib/ldp/orm/orm_spec.rb +19 -9
- data/spec/lib/ldp/resource/rdf_source_spec.rb +52 -0
- data/spec/lib/ldp/resource_spec.rb +30 -0
- data/spec/lib/ldp/response_spec.rb +2 -8
- data/spec/spec_helper.rb +2 -1
- metadata +41 -3
@@ -4,19 +4,19 @@ describe Ldp::Orm do
|
|
4
4
|
subject { Ldp::Orm.new test_resource }
|
5
5
|
|
6
6
|
let(:simple_graph) do
|
7
|
-
|
8
|
-
graph.dump(:ttl)
|
7
|
+
RDF::Graph.new << [RDF::URI.new(""), RDF::DC.title, "Hello, world!"]
|
9
8
|
end
|
10
9
|
|
11
10
|
let(:conn_stubs) do
|
12
|
-
|
13
|
-
stub.get('/a_resource') {[ 200, {"Link" => "http://www.w3.org/ns/ldp#Resource;rel=\"type\""}, simple_graph ]}
|
11
|
+
Faraday::Adapter::Test::Stubs.new do |stub|
|
12
|
+
stub.get('/a_resource') {[ 200, {"Link" => "http://www.w3.org/ns/ldp#Resource;rel=\"type\""}, simple_graph.dump(:ttl) ]}
|
13
|
+
stub.head('/a_resource') { [200] }
|
14
14
|
stub.put("/a_resource") { [204]}
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
let(:mock_conn) do
|
19
|
-
|
19
|
+
Faraday.new do |builder|
|
20
20
|
builder.adapter :test, conn_stubs do |stub|
|
21
21
|
end
|
22
22
|
end
|
@@ -27,7 +27,7 @@ describe Ldp::Orm do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
let :test_resource do
|
30
|
-
Ldp::Resource.new mock_client, "http://example.com/a_resource"
|
30
|
+
Ldp::Resource::RdfSource.new mock_client, "http://example.com/a_resource"
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#delete" do
|
@@ -38,7 +38,17 @@ describe Ldp::Orm do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "#create" do
|
41
|
-
|
41
|
+
let(:conn_stubs) do
|
42
|
+
Faraday::Adapter::Test::Stubs.new do |stub|
|
43
|
+
stub.post("/") { [201]}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
let :test_resource do
|
47
|
+
Ldp::Resource::RdfSource.new mock_client, nil, simple_graph
|
48
|
+
end
|
49
|
+
it "should return a new orm" do
|
50
|
+
expect(subject.create).to be_kind_of Ldp::Orm
|
51
|
+
end
|
42
52
|
end
|
43
53
|
|
44
54
|
describe "#save" do
|
@@ -54,7 +64,7 @@ describe Ldp::Orm do
|
|
54
64
|
|
55
65
|
it "should return false if the response was not successful" do
|
56
66
|
conn_stubs.instance_variable_get(:@stack)[:put] = [] # erases the stubs for :put
|
57
|
-
conn_stubs.put('/a_resource') {[412]}
|
67
|
+
conn_stubs.put('/a_resource') {[412, nil, 'There was an error']}
|
58
68
|
expect(subject.save).to be_false
|
59
69
|
end
|
60
70
|
end
|
@@ -68,7 +78,7 @@ describe Ldp::Orm do
|
|
68
78
|
it "should raise an exception if the ETag didn't match" do
|
69
79
|
conn_stubs.instance_variable_get(:@stack)[:put] = [] # erases the stubs for :put
|
70
80
|
conn_stubs.put('/a_resource') {[412, {}, "Bad If-Match header value: 'ae43aa934dc4f4e15ea1b4dd1ca7a56791972836'"]}
|
71
|
-
expect { subject.save! }.to raise_exception(Ldp::SaveException)
|
81
|
+
expect { subject.save! }.to raise_exception(Ldp::SaveException, "STATUS: 412 Bad If-Match header value: 'ae43aa934dc4f4e15ea1b4dd1ca7a56791972836'...")
|
72
82
|
end
|
73
83
|
end
|
74
84
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ldp::Resource::RdfSource do
|
4
|
+
let(:simple_graph) do
|
5
|
+
RDF::Graph.new << [RDF::URI.new(), RDF::DC.title, "Hello, world!"]
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:conn_stubs) do
|
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
|
+
stub.post("/") { [201]}
|
12
|
+
stub.post("/abs_url_object") { [201]}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:mock_conn) do
|
17
|
+
Faraday.new url: "http://my.ldp.server/" do |builder|
|
18
|
+
builder.adapter :test, conn_stubs do |stub|
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let :mock_client do
|
24
|
+
Ldp::Client.new mock_conn
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
describe "#create" do
|
29
|
+
subject { Ldp::Resource::RdfSource.new mock_client, nil }
|
30
|
+
|
31
|
+
it "should return a new resource" do
|
32
|
+
created_resource = subject.create
|
33
|
+
expect(created_resource).to be_kind_of Ldp::Resource::RdfSource
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow absolute URLs to the LDP server" do
|
37
|
+
obj = Ldp::Resource::RdfSource.new mock_client, "http://my.ldp.server/abs_url_object"
|
38
|
+
obj.stub(new?: true)
|
39
|
+
created_resource = obj.create
|
40
|
+
expect(created_resource).to be_kind_of Ldp::Resource::RdfSource
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#initialize" do
|
45
|
+
context "with bad attributes" do
|
46
|
+
it "should raise an error" do
|
47
|
+
expect{ Ldp::Resource::RdfSource.new mock_client, nil, "derp" }.to raise_error(ArgumentError,
|
48
|
+
"Third argument to Ldp::Resource::RdfSource.new should be a RDF::Graph or a Ldp::Response. You provided String")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -5,7 +5,10 @@ describe Ldp::Resource do
|
|
5
5
|
|
6
6
|
let(:conn_stubs) do
|
7
7
|
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
8
|
+
stub.head('/not_found_resource') { [404] }
|
8
9
|
stub.get('/not_found_resource') { [404] }
|
10
|
+
stub.head('/a_new_resource') { [404] }
|
11
|
+
stub.head('/a_resource') { [200] }
|
9
12
|
stub.get('/a_resource') { [200] }
|
10
13
|
end
|
11
14
|
end
|
@@ -37,4 +40,31 @@ describe Ldp::Resource do
|
|
37
40
|
end
|
38
41
|
end
|
39
42
|
end
|
43
|
+
|
44
|
+
describe "#new?" do
|
45
|
+
context "with an object not in the repository" do
|
46
|
+
let(:path) { '/not_found_resource' }
|
47
|
+
it "should be true" do
|
48
|
+
expect(subject).to be_new
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with an object in the repository" do
|
53
|
+
let(:path) { '/a_resource' }
|
54
|
+
it "should be false" do
|
55
|
+
expect(subject).to_not be_new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#create" do
|
61
|
+
context "with initial content" do
|
62
|
+
let(:path) { '/a_new_resource' }
|
63
|
+
it "should post an RDF graph" do
|
64
|
+
mock_client.should_receive(:post).with(path, "xyz").and_return(double(headers: {}))
|
65
|
+
subject.content = "xyz"
|
66
|
+
subject.save
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
40
70
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Ldp::Response do
|
4
4
|
LDP_RESOURCE_HEADERS = { "Link" => Ldp.resource.to_s + ";rel=\"type\""}
|
5
5
|
|
6
|
-
let(:mock_response) { double() }
|
6
|
+
let(:mock_response) { double(headers: {}, env: { url: "info:a" }) }
|
7
7
|
let(:mock_client) { double(Ldp::Client) }
|
8
8
|
|
9
9
|
subject do
|
@@ -14,7 +14,6 @@ describe Ldp::Response do
|
|
14
14
|
it "should mixin Ldp::Response into the raw response" do
|
15
15
|
Ldp::Response.wrap(mock_client, mock_response)
|
16
16
|
expect(mock_response).to be_a_kind_of(Ldp::Response)
|
17
|
-
expect(mock_response.ldp_client).to eq(mock_client)
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
@@ -32,7 +31,7 @@ describe Ldp::Response do
|
|
32
31
|
|
33
32
|
expect(h['some-rel']).to include("xyz")
|
34
33
|
expect(h['some-multi-rel']).to include("abc", "123")
|
35
|
-
expect(h['doesnt-exist']).to
|
34
|
+
expect(h['doesnt-exist']).to be_nil
|
36
35
|
end
|
37
36
|
|
38
37
|
it "should return an empty hash if no link headers are availabe" do
|
@@ -58,7 +57,6 @@ describe Ldp::Response do
|
|
58
57
|
describe "#graph" do
|
59
58
|
it "should parse the response body for an RDF graph" do
|
60
59
|
mock_response.stub :body => "<> <info:b> <info:c> .", :headers => LDP_RESOURCE_HEADERS
|
61
|
-
subject.stub :page_subject => RDF::URI.new('info:a')
|
62
60
|
graph = subject.graph
|
63
61
|
|
64
62
|
expect(graph).to have_subject(RDF::URI.new("info:a"))
|
@@ -86,8 +84,6 @@ describe Ldp::Response do
|
|
86
84
|
it "should see if the response has an ldp:Page statement" do
|
87
85
|
graph = RDF::Graph.new
|
88
86
|
|
89
|
-
subject.stub :page_subject => RDF::URI.new('info:a')
|
90
|
-
|
91
87
|
graph << [RDF::URI.new('info:a'), RDF.type, Ldp.page]
|
92
88
|
|
93
89
|
mock_response.stub :body => graph.dump(:ttl), :headers => LDP_RESOURCE_HEADERS
|
@@ -106,8 +102,6 @@ describe Ldp::Response do
|
|
106
102
|
it "should get the ldp:Page data from the query" do
|
107
103
|
graph = RDF::Graph.new
|
108
104
|
|
109
|
-
subject.stub :page_subject => RDF::URI.new('info:a')
|
110
|
-
|
111
105
|
graph << [RDF::URI.new('info:a'), RDF.type, Ldp.page]
|
112
106
|
graph << [RDF::URI.new('info:b'), RDF.type, Ldp.page]
|
113
107
|
|
data/spec/spec_helper.rb
CHANGED
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.4
|
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-04-
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: http_logger
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: slop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: bundler
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -83,7 +111,8 @@ dependencies:
|
|
83
111
|
description: Linked Data Platform client library
|
84
112
|
email:
|
85
113
|
- chris@cbeer.info
|
86
|
-
executables:
|
114
|
+
executables:
|
115
|
+
- ldp
|
87
116
|
extensions: []
|
88
117
|
extra_rdoc_files: []
|
89
118
|
files:
|
@@ -93,19 +122,27 @@ files:
|
|
93
122
|
- LICENSE.txt
|
94
123
|
- README.md
|
95
124
|
- Rakefile
|
125
|
+
- bin/ldp
|
96
126
|
- ldp.gemspec
|
97
127
|
- lib/ldp.rb
|
98
128
|
- lib/ldp/client.rb
|
99
129
|
- lib/ldp/client/methods.rb
|
100
130
|
- lib/ldp/container.rb
|
131
|
+
- lib/ldp/container/basic.rb
|
132
|
+
- lib/ldp/container/direct.rb
|
133
|
+
- lib/ldp/container/indirect.rb
|
101
134
|
- lib/ldp/orm.rb
|
102
135
|
- lib/ldp/resource.rb
|
136
|
+
- lib/ldp/resource/binary_source.rb
|
137
|
+
- lib/ldp/resource/rdf_source.rb
|
103
138
|
- lib/ldp/response.rb
|
139
|
+
- lib/ldp/response/paging.rb
|
104
140
|
- lib/ldp/uri.rb
|
105
141
|
- lib/ldp/version.rb
|
106
142
|
- spec/lib/integration/integration_spec.rb
|
107
143
|
- spec/lib/ldp/client_spec.rb
|
108
144
|
- spec/lib/ldp/orm/orm_spec.rb
|
145
|
+
- spec/lib/ldp/resource/rdf_source_spec.rb
|
109
146
|
- spec/lib/ldp/resource_spec.rb
|
110
147
|
- spec/lib/ldp/response_spec.rb
|
111
148
|
- spec/spec_helper.rb
|
@@ -137,6 +174,7 @@ test_files:
|
|
137
174
|
- spec/lib/integration/integration_spec.rb
|
138
175
|
- spec/lib/ldp/client_spec.rb
|
139
176
|
- spec/lib/ldp/orm/orm_spec.rb
|
177
|
+
- spec/lib/ldp/resource/rdf_source_spec.rb
|
140
178
|
- spec/lib/ldp/resource_spec.rb
|
141
179
|
- spec/lib/ldp/response_spec.rb
|
142
180
|
- spec/spec_helper.rb
|