Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #430 from sul-dlss/deprecate_sdr_content
Browse files Browse the repository at this point in the history
Deprecate Sdr::Client.get_preserved_file_content
  • Loading branch information
jcoyne committed Dec 21, 2018
2 parents a5884ba + 9df6aa5 commit 34513bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/dor/models/concerns/contentable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def replace_file(file, file_name)
def get_preserved_file(file, version)
Sdr::Client.get_preserved_file_content(pid, file, version)
end
deprecation_deprecate get_preserved_file: 'use dor-services-app/v1/sdr/objects/:druid/content/:filename instead'
deprecation_deprecate get_preserved_file: 'Use Dor::Services::Client.preserved_content instead'

def get_file(file)
druid_tools = DruidTools::Druid.new(pid, Config.content.content_base_dir)
Expand Down
4 changes: 4 additions & 0 deletions lib/dor/utils/sdr_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'moab'
module Sdr
class Client
extend Deprecation

class << self
# @param [String] druid id of the object you want the version of
# @return [Integer] the current version from SDR
Expand Down Expand Up @@ -60,6 +62,8 @@ def get_content_diff(druid, current_content, subset = 'all', version = nil)

# This is used by Argo
def get_preserved_file_content(druid, filename, version)
Deprecation.warn(self, 'Sdr::Client.get_preserved_file_content is deprecated and will be removed in dor-services 7. Use Dor::Services::Client.preserved_content instead')

client["objects/#{druid}/content/#{URI.encode(filename)}?version=#{version}"].get
end

Expand Down
4 changes: 2 additions & 2 deletions spec/utils/sdr_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
it 'properly encodes filename and passes along the sdr response with the correct content type and status code' do
resource = Sdr::Client.client["objects/#{druid}/content/#{URI.encode(filename_with_spaces)}?version=#{item_version}"]
stub_request(:get, resource.url).to_return(body: sdr_resp_body, headers: { content_type: sdr_resp_content_type })

expect(Deprecation).to receive(:warn)
preserved_content = Sdr::Client.get_preserved_file_content(druid, filename_with_spaces, item_version)
expect(preserved_content).to eq(sdr_resp_body)
expect(preserved_content.body).to eq(sdr_resp_body)
Expand All @@ -86,7 +86,7 @@
it 'passes errors through to the caller' do
resource = Sdr::Client.client["objects/#{druid}/content/bogus_filename?version=#{item_version}"]
stub_request(:get, resource.url).to_return(status: 404)

expect(Deprecation).to receive(:warn)
expect { Sdr::Client.get_preserved_file_content(druid, filename_with_spaces, item_version) }.to raise_error RestClient::ResourceNotFound
end
end
Expand Down

0 comments on commit 34513bc

Please sign in to comment.