Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds requirements for Fedora's alpha-6 implementation of LDP. #30

Merged
merged 1 commit into from
Jun 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/ldp/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def save
# @return [RdfSource] the new representation
def create &block
raise "Can't call create on an existing resource" unless new?
resp = client.post((subject || ""), content) do |req|
verb = subject.nil? ? :post : :put
resp = client.send(verb, (subject || ""), content) do |req|

yield req if block_given?
end
Expand All @@ -79,9 +80,11 @@ def create &block
# Update the stored graph
def update new_content = nil
new_content ||= content
client.put subject, new_content do |req|
resp = client.put subject, new_content do |req|
req.headers['If-Match'] = get.etag if retrieved_content?
end
update_cached_get(resp) if retrieved_content?
resp
end

def current? response = nil
Expand All @@ -95,5 +98,15 @@ def current? response = nil
new_response.headers['ETag'] == response.headers['ETag'] &&
new_response.headers['Last-Modified'] == response.headers['Last-Modified']
end

def update_cached_get response
Response.wrap(client, response)
if response.etag.nil? || response.last_modified.nil?
response = Response.wrap(client, client.head(subject))
end
@get.etag = response.etag
@get.last_modified = response.last_modified
end

end
end
12 changes: 10 additions & 2 deletions lib/ldp/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,21 @@ def graph
##
# Extract the ETag for the resource
def etag
headers['ETag']
@etag ||= headers['ETag']
end

def etag=(val)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a good idea to treat the headers hash as immutable/frozen, and do something like this:

def etag
  @etag ||= headers['ETag']
end

def etag= val
  @etag = val
end

@etag = val
end

##
# Extract the last modified header for the resource
def last_modified
headers['Last-Modified']
@last_modified ||= headers['Last-Modified']
end

def last_modified=(val)
@last_modified = val
end

##
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/ldp/resource/rdf_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Faraday::Adapter::Test::Stubs.new do |stub|
# stub.get('/a_resource') {[ 200, {"Link" => "<http://www.w3.org/ns/ldp#Resource>;rel=\"type\""}, simple_graph ]}
stub.post("/") { [201]}
stub.post("/abs_url_object") { [201]}
stub.put("/abs_url_object") { [201]}
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/ldp/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
context "with initial content" do
let(:path) { '/a_new_resource' }
it "should post an RDF graph" do
mock_client.should_receive(:post).with(path, "xyz").and_return(double(headers: {}))
mock_client.should_receive(:put).with(path, "xyz").and_return(double(headers: {}))
subject.content = "xyz"
subject.save
end
Expand Down