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

Post correct path #13

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions lib/ldp/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Client
require 'ldp/client/methods'
include Ldp::Client::Methods

ENDPOINT = '/rest'

def initialize *http_client
initialize_http_client *http_client
end
Expand Down
10 changes: 9 additions & 1 deletion lib/ldp/client/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ def initialize_http_client *http_client
end
end

def prefix_path
Copy link
Member

Choose a reason for hiding this comment

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

What's wrong with just initializing the client with the full URL, e.g.:

Ldp::Client.new(url: "http://localhost:8983/fedora/rest)

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why does fedora have that /rest endpoint in the first place? Why isn't that stuff just at the context root?

@path ||= @http.url_prefix.path
end

def endpoint_path
prefix_path + Ldp::Client::ENDPOINT
end

# Get a LDP Resource by URI
def get url, options = {}
logger.debug "LDP: GET [#{url}]"
Expand Down Expand Up @@ -78,7 +86,7 @@ def check_for_errors resp
resp.tap do |resp|
unless resp.success?
raise Ldp::NotFound.new(resp.body) if resp.status == 404
raise Ldp::HttpError.new(resp.body)
raise Ldp::HttpError.new("STATUS: #{resp.status} #{resp.body[0, 1000]}...")
end
end
end
Expand Down
10 changes: 8 additions & 2 deletions lib/ldp/resource/rdf_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def initialize client, subject, graph_or_response = nil
# @return [RdfSource] the new representation
def create
raise "Can't call create on an existing resource" unless new?
resp = client.post '', graph.dump(:ttl) do |req|
req.headers['Slug'] = subject
resp = client.post client.endpoint_path, graph.dump(:ttl) do |req|
req.headers['Slug'] = slug if subject
end

@subject = resp.headers['Location']
Expand Down Expand Up @@ -86,5 +86,11 @@ def self.check_for_differences_and_reload_resource old_object

diff
end

private

def slug
subject.sub(/^.+#{client.endpoint_path}\//, '')
end
end
end
6 changes: 3 additions & 3 deletions spec/lib/ldp/orm/orm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
end

let(:mock_conn) do
Faraday.new do |builder|
Faraday.new 'http://localhost:8983/fedora' do |builder|
builder.adapter :test, conn_stubs do |stub|
end
end
Expand All @@ -39,7 +39,7 @@
describe "#create" do
let(:conn_stubs) do
Faraday::Adapter::Test::Stubs.new do |stub|
stub.post("/") { [201]}
stub.post("/fedora/rest") { [201]}
end
end
let :test_resource do
Expand All @@ -63,7 +63,7 @@

it "should return false if the response was not successful" do
conn_stubs.instance_variable_get(:@stack)[:put] = [] # erases the stubs for :put
conn_stubs.put('/a_resource') {[412]}
conn_stubs.put('/a_resource') {[412, nil, 'There was an error']}
expect(subject.save).to be_false
end
end
Expand Down
5 changes: 2 additions & 3 deletions spec/lib/ldp/resource/rdf_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

let(:conn_stubs) do
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("/fedora/rest") { [201]}
end
end

let(:mock_conn) do
Faraday.new do |builder|
Faraday.new 'http://localhost:8983/fedora' do |builder|
builder.adapter :test, conn_stubs do |stub|
end
end
Expand Down