diff --git a/lib/ldp/client.rb b/lib/ldp/client.rb index fc1f018..011b48c 100644 --- a/lib/ldp/client.rb +++ b/lib/ldp/client.rb @@ -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 diff --git a/lib/ldp/client/methods.rb b/lib/ldp/client/methods.rb index c423c3f..45ec882 100644 --- a/lib/ldp/client/methods.rb +++ b/lib/ldp/client/methods.rb @@ -11,6 +11,14 @@ def initialize_http_client *http_client end end + def prefix_path + @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}]" @@ -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 diff --git a/lib/ldp/resource/rdf_source.rb b/lib/ldp/resource/rdf_source.rb index a97345b..55d83d7 100644 --- a/lib/ldp/resource/rdf_source.rb +++ b/lib/ldp/resource/rdf_source.rb @@ -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'] @@ -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 diff --git a/spec/lib/ldp/orm/orm_spec.rb b/spec/lib/ldp/orm/orm_spec.rb index 13c7e7b..3c3fa02 100644 --- a/spec/lib/ldp/orm/orm_spec.rb +++ b/spec/lib/ldp/orm/orm_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/lib/ldp/resource/rdf_source_spec.rb b/spec/lib/ldp/resource/rdf_source_spec.rb index ea5b050..c92090e 100644 --- a/spec/lib/ldp/resource/rdf_source_spec.rb +++ b/spec/lib/ldp/resource/rdf_source_spec.rb @@ -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