ldp 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aed769ef892aa0d5ba1e4c05b3800348191d64c9
4
- data.tar.gz: e46dfc3a68c8028b857f9158c191d2bf953a630e
3
+ metadata.gz: 4d377a827832fb58b1a8a62f81bd434dd75c30a4
4
+ data.tar.gz: 707fd5fcd162dadb2eef16f0b726427f9de51811
5
5
  SHA512:
6
- metadata.gz: 21151cf14c58ab5901e02f487a04592909080b2edba9ad23c447ccf266e1d0a7085a6dd973dbdff932207c4d9f29af08796ab11d183ab0125623edbb3a284056
7
- data.tar.gz: b4dd704c77df50f18d3420eff5ec4ce35671fc793ecef6e001abba69dc5cb7f8c11408c09a2fd801c48d2c1527f506a57d21bb1e38c697cdf3c17f90aa9d002a
6
+ metadata.gz: 2c7eba449185e70f93692dea2a991efecbb3900a69e2384b5692a761d74eab62fd5233753bc850298b2645c1788efa4519011769fe6f66d3d97fd80b3f4a49f9
7
+ data.tar.gz: ed5c4424c1aca7a8b745b0571812258b4b5f552b2b009007c1fa7dade50127ee5707d8d534fbc79cefcc862401ee469219deade75be19fc21b699b6db298fa41
@@ -5,8 +5,6 @@ env:
5
5
  global:
6
6
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
7
7
  rvm:
8
- - 1.9.3
9
- - 2.0
10
8
  - 2.1
11
9
  - 2.2
12
- - jruby-19mode
10
+ - jruby
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ldp.rb
2
2
 
3
- [![Build Status](https://travis-ci.org/cbeer/ldp.png?branch=master)](https://travis-ci.org/cbeer/ldp)
3
+ [![Build Status](https://travis-ci.org/projecthydra/ldp.png?branch=master)](https://travis-ci.org/projecthydra/ldp)
4
4
 
5
5
  Linked Data Platform client library for Ruby
6
6
 
@@ -39,8 +39,8 @@ orm.save
39
39
 
40
40
  ### Fedora Commons notes
41
41
  Due to some discrepancies with alpha version of Fedora Commons, you may need to do some things differently:
42
- * [Can't load resources from Fedora 4](https://github.com/cbeer/ldp/issues/1)
43
- * [orm.save with an rdf:type doesn't work with Fedora 4.0.0-alpha-3](https://github.com/cbeer/ldp/issues/2)
42
+ * [Can't load resources from Fedora 4](https://github.com/projecthydra/ldp/issues/1)
43
+ * [orm.save with an rdf:type doesn't work with Fedora 4.0.0-alpha-3](https://github.com/projecthydra/ldp/issues/2)
44
44
 
45
45
  ## Contributing
46
46
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["chris@cbeer.info"]
11
11
  spec.description = %q{Linked Data Platform client library}
12
12
  spec.summary = spec.description
13
- spec.homepage = "https://github.com/cbeer/ldp"
13
+ spec.homepage = "https://github.com/projecthydra/ldp"
14
14
  spec.license = "APACHE2"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -4,6 +4,7 @@ module Ldp
4
4
  class Client
5
5
 
6
6
  require 'ldp/client/methods'
7
+ require 'ldp/client/prefer_headers'
7
8
  include Ldp::Client::Methods
8
9
 
9
10
  def initialize *http_client
@@ -29,17 +29,18 @@ module Ldp::Client::Methods
29
29
  logger.debug "LDP: GET [#{url}]"
30
30
  resp = http.get do |req|
31
31
  req.url munge_to_relative_url(url)
32
+ prefer_headers = ::Ldp::PreferHeaders.new
32
33
 
33
34
  if options[:minimal]
34
- req.headers["Prefer"] = "return=minimal"
35
+ prefer_headers.return = "minimal"
35
36
  else
37
+ prefer_headers.return = "representation"
36
38
  includes = Array(options[:include]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" }
37
39
  omits = Array(options[:omit]).map { |x| Ldp.send("prefer_#{x}") if Ldp.respond_to? "prefer_#{x}" }
38
- req.headers["Prefer"] = ["return=representation",
39
- ("include=\"#{includes.join(" ")}\"" unless includes.empty?),
40
- ("omit=\"#{omits.join(" ")}\"" unless omits.empty?)
41
- ].compact.join("; ")
40
+ prefer_headers.include = includes
41
+ prefer_headers.omit = omits
42
42
  end
43
+ req.headers["Prefer"] = prefer_headers.to_s
43
44
 
44
45
  yield req if block_given?
45
46
  end
@@ -0,0 +1,64 @@
1
+ module Ldp
2
+ class PreferHeaders
3
+ attr_reader :headers_string
4
+
5
+ def initialize(headers_string="")
6
+ @headers_string = headers_string
7
+ end
8
+
9
+ def omit
10
+ @omit ||= options["omit"] || []
11
+ end
12
+
13
+ def include
14
+ @include ||= options["include"] || []
15
+ end
16
+
17
+ def return
18
+ @return ||= options["return"].first || ""
19
+ end
20
+
21
+ def include=(vals)
22
+ @include = Array(vals)
23
+ serialize
24
+ end
25
+
26
+ def omit=(vals)
27
+ @omit = Array(vals)
28
+ serialize
29
+ end
30
+
31
+ def return=(vals)
32
+ @return = Array(vals).first
33
+ serialize
34
+ end
35
+
36
+ def to_s
37
+ headers_string.to_s
38
+ end
39
+
40
+ private
41
+
42
+ def serialize
43
+ head_string = []
44
+ unless self.return.empty?
45
+ head_string << "return=#{self.return}"
46
+ end
47
+ unless omit.empty?
48
+ head_string << "omit=\"#{omit.join(" ")}\""
49
+ end
50
+ unless self.include.empty?
51
+ head_string << "include=\"#{self.include.join(" ")}\""
52
+ end
53
+ @headers_string = head_string.join("; ")
54
+ end
55
+
56
+ def options
57
+ headers_string.gsub('"',"").
58
+ split(";").
59
+ map{|x| x.strip.split("=")}.
60
+ map{|x| { x[0] => x[1].split(" ") }}.
61
+ inject({}, &:merge)
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,5 @@
1
+ require 'rdf/turtle'
2
+ require 'rdf/rdfxml'
1
3
  module Ldp
2
4
  class Resource::RdfSource < Ldp::Resource
3
5
 
@@ -26,7 +28,7 @@ module Ldp
26
28
  end
27
29
 
28
30
  def graph
29
- @graph ||= new? ? build_empty_graph : build_graph(get.graph)
31
+ @graph ||= new? ? build_empty_graph : build_graph(response_as_graph(get))
30
32
  end
31
33
 
32
34
  def build_empty_graph
@@ -44,12 +46,26 @@ module Ldp
44
46
 
45
47
 
46
48
  private
47
-
49
+ ##
50
+ # @param [Faraday::Response] graph query response
51
+ # @return [RDF::Graph]
52
+ def response_as_graph(resp)
53
+ content_type = resp.headers['Content-Type'] || 'text/turtle'
54
+ content_type = Array(content_type).first
55
+ format = Array(RDF::Format.content_types[content_type]).first
56
+ source = resp.body
57
+ reader = RDF::Reader.for(content_type:content_type).new(source, base_uri:subject)
58
+ graph = build_empty_graph
59
+ reader.each_statement do |stmt|
60
+ graph << stmt
61
+ end
62
+ graph
63
+ end
48
64
  ##
49
65
  # @param [RDF::Graph] original_graph The graph returned by the LDP server
50
66
  # @return [RDF::Graph] A graph striped of any inlined resources present in the original
51
67
  def build_graph(original_graph)
52
- inlined_resources = get.graph.query(predicate: Ldp.contains).map { |x| x.object }
68
+ inlined_resources = response_as_graph(get).query(predicate: Ldp.contains).map { |x| x.object }
53
69
 
54
70
  # we want to scope this graph to just statements about this model, not contained relations
55
71
  if inlined_resources.empty?
@@ -1,3 +1,3 @@
1
1
  module Ldp
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Ldp::PreferHeaders do
4
+ let(:header_string) { "return=representation; omit=\"http://1.1.1 http://2.3/b\"; include=\"http://2.2.2\"" }
5
+ subject { described_class.new(header_string) }
6
+
7
+ describe "#return" do
8
+ it "should return what's being returned" do
9
+ expect(subject.return).to eq "representation"
10
+ end
11
+ end
12
+
13
+ describe "#omit" do
14
+ it "should return omit array" do
15
+ expect(subject.omit).to eq ["http://1.1.1", "http://2.3/b"]
16
+ end
17
+ end
18
+
19
+ describe "#include" do
20
+ it "should return include array" do
21
+ expect(subject.include).to eq ["http://2.2.2"]
22
+ end
23
+ end
24
+
25
+ describe "#include=" do
26
+ it "should set include" do
27
+ subject.include = ["http://3.3.3", "http://1.1.1"]
28
+
29
+ expect(subject.include).to eq ["http://3.3.3", "http://1.1.1"]
30
+ expect(subject.to_s).to eq "return=representation; omit=\"http://1.1.1 http://2.3/b\"; include=\"http://3.3.3 http://1.1.1\""
31
+ end
32
+ it "should be able to set a single value" do
33
+ subject.include = "http://3.3.3"
34
+ expect(subject.to_s).to eq "return=representation; omit=\"http://1.1.1 http://2.3/b\"; include=\"http://3.3.3\""
35
+ end
36
+ context "when set to nothing" do
37
+ it "should not serialize that value" do
38
+ subject.include = []
39
+ expect(subject.to_s).to eq "return=representation; omit=\"http://1.1.1 http://2.3/b\""
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#return=" do
45
+ it "should set return" do
46
+ subject.return = "bananas"
47
+
48
+ expect(subject.return).to eq "bananas"
49
+ expect(subject.to_s).to eq "return=bananas; omit=\"http://1.1.1 http://2.3/b\"; include=\"http://2.2.2\""
50
+ end
51
+ end
52
+
53
+ describe "#omit=" do
54
+ it "should set omit" do
55
+ subject.omit = ["http://3.3.3", "http://1.1.1"]
56
+
57
+ expect(subject.omit).to eq ["http://3.3.3", "http://1.1.1"]
58
+ expect(subject.to_s).to eq "return=representation; omit=\"http://3.3.3 http://1.1.1\"; include=\"http://2.2.2\""
59
+ end
60
+ context "when set to nothing" do
61
+ it "should not serialize that value" do
62
+ subject.omit = []
63
+ expect(subject.to_s).to eq "return=representation; include=\"http://2.2.2\""
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,3 +1,4 @@
1
+ require 'stringio'
1
2
  require 'spec_helper'
2
3
 
3
4
  describe Ldp::Resource::RdfSource do
@@ -5,10 +6,18 @@ describe Ldp::Resource::RdfSource do
5
6
  RDF::Graph.new << [RDF::URI.new(), RDF::DC.title, "Hello, world!"]
6
7
  end
7
8
 
9
+ let(:simple_graph_source) do
10
+ io = StringIO.new
11
+ RDF::Writer.for(content_type:'text/turtle').dump(simple_graph,io)
12
+ io.string
13
+ end
8
14
  let(:conn_stubs) do
9
15
  Faraday::Adapter::Test::Stubs.new do |stub|
10
16
  stub.post("/") { [201]}
11
17
  stub.put("/abs_url_object") { [201]}
18
+ stub.head("/abs_url_object") {[404]}
19
+ stub.head("/existing_object") {[200, {'Content-Type'=>'text/turtle'}]}
20
+ stub.get("/existing_object") {[200, {'Content-Type'=>'text/turtle'}, simple_graph_source]}
12
21
  end
13
22
  end
14
23
 
@@ -34,7 +43,6 @@ describe Ldp::Resource::RdfSource do
34
43
 
35
44
  it "should allow absolute URLs to the LDP server" do
36
45
  obj = Ldp::Resource::RdfSource.new mock_client, "http://my.ldp.server/abs_url_object"
37
- allow(obj).to receive(:new?).and_return(true)
38
46
  created_resource = obj.create
39
47
  expect(created_resource).to be_kind_of Ldp::Resource::RdfSource
40
48
  end
@@ -49,6 +57,21 @@ describe Ldp::Resource::RdfSource do
49
57
  end
50
58
  end
51
59
 
60
+ describe '#graph' do
61
+ context 'for a new object' do
62
+ subject { Ldp::Resource::RdfSource.new mock_client, nil }
63
+ it do
64
+ expect(subject.graph.size).to eql(0)
65
+ end
66
+ end
67
+ context 'for an existing object' do
68
+ subject { Ldp::Resource::RdfSource.new mock_client, "http://my.ldp.server/existing_object" }
69
+ it do
70
+ expect(subject.graph.size).to eql(1)
71
+ end
72
+ end
73
+ end
74
+
52
75
  context "When graph_class is overridden" do
53
76
  before do
54
77
  class SpecialGraph < RDF::Graph; 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.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2015-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -127,6 +127,7 @@ files:
127
127
  - lib/ldp.rb
128
128
  - lib/ldp/client.rb
129
129
  - lib/ldp/client/methods.rb
130
+ - lib/ldp/client/prefer_headers.rb
130
131
  - lib/ldp/container.rb
131
132
  - lib/ldp/container/basic.rb
132
133
  - lib/ldp/container/direct.rb
@@ -140,6 +141,7 @@ files:
140
141
  - lib/ldp/uri.rb
141
142
  - lib/ldp/version.rb
142
143
  - spec/lib/integration/integration_spec.rb
144
+ - spec/lib/ldp/client/prefer_headers_spec.rb
143
145
  - spec/lib/ldp/client_spec.rb
144
146
  - spec/lib/ldp/orm/orm_spec.rb
145
147
  - spec/lib/ldp/resource/binary_source_spec.rb
@@ -147,7 +149,7 @@ files:
147
149
  - spec/lib/ldp/resource_spec.rb
148
150
  - spec/lib/ldp/response_spec.rb
149
151
  - spec/spec_helper.rb
150
- homepage: https://github.com/cbeer/ldp
152
+ homepage: https://github.com/projecthydra/ldp
151
153
  licenses:
152
154
  - APACHE2
153
155
  metadata: {}
@@ -173,6 +175,7 @@ specification_version: 4
173
175
  summary: Linked Data Platform client library
174
176
  test_files:
175
177
  - spec/lib/integration/integration_spec.rb
178
+ - spec/lib/ldp/client/prefer_headers_spec.rb
176
179
  - spec/lib/ldp/client_spec.rb
177
180
  - spec/lib/ldp/orm/orm_spec.rb
178
181
  - spec/lib/ldp/resource/binary_source_spec.rb
@@ -180,3 +183,4 @@ test_files:
180
183
  - spec/lib/ldp/resource_spec.rb
181
184
  - spec/lib/ldp/response_spec.rb
182
185
  - spec/spec_helper.rb
186
+ has_rdoc: