Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Allowing optional druid remove.
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Nov 11, 2014
1 parent d19f29f commit 0062247
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dor-fetcher.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'dor-fetcher'
s.version = '1.1.1'
s.version = '1.1.2'
s.date = '2014-11-11'
s.summary = "DorFetcher Gem"
s.description = "Wrapper for the Dor Fetcher Services RESTful API."
Expand Down
13 changes: 8 additions & 5 deletions lib/dor-fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,19 @@ def total_apo_count
#Method to parse full Hash into an array containing only the druids
#
#@param response [Hash] Hash as returned by query_api
#@param no_prefix [boolean] if true (default), remove the druid: prefix on all druids, if false, leave alone
#@return [Array] the array listing all druids in the supplied Hash
def druid_array(response)
def druid_array(response,params={})
return_list = []
j = response
j.keys.each do |key|
if key != @@counts_key
j[key].each do |item|
return_list << item['druid'] if item['druid'] != nil
if item['druid'] != nil
druid=item['druid'].downcase
druid.gsub!('druid:','') if params[:no_prefix]
return_list << druid
end
end
end
end
Expand Down Expand Up @@ -181,6 +186,4 @@ def service_url

end

end


end
8 changes: 7 additions & 1 deletion spec/dor_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,17 @@
expect(@df.add_params(@df.add_count_only_param({}))).to eq("?rows=0")
end

it "druids_array should take in JSON and return a list of just the druids" do
it "druid_array should take in JSON and return a list of just the druids" do
input = JSON['{"collections":[{"druid":"druid:yg867hg1375","latest_change":"2013-11-11T23:34:29Z","title":"Francis E. Stafford photographs, 1909-1933"}],"items":[{"druid":"druid:jf275fd6276","latest_change":"2013-11-11T23:34:29Z","title":"Album A: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."},{"druid":"druid:nz353cp1092","latest_change":"2013-11-11T23:34:29Z","title":"Album E: Photographs of the Seventh Day Adventist Church missionaries in China"},{"druid":"druid:tc552kq0798","latest_change":"2013-11-11T23:34:29Z","title":"Album D: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."},{"druid":"druid:th998nk0722","latest_change":"2013-11-11T23:34:29Z","title":"Album C: Photographs of the Chinese Revolution of 1911 and the Shanghai Commercial Press"},{"druid":"druid:ww689vs6534","latest_change":"2013-11-11T23:34:29Z","title":"Album B: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."}],"counts":{"collections":1,"items":5,"total_count":6}}']
expected_output = ["druid:yg867hg1375", "druid:jf275fd6276", "druid:nz353cp1092", "druid:tc552kq0798", "druid:th998nk0722", "druid:ww689vs6534"]
expect(@df.druid_array(input)).to eq(expected_output)
end

it "druid_array should take in JSON and return a list of just the druids, stripping off druid prefix if requested" do
input = JSON['{"collections":[{"druid":"DRUID:yg867hg1375","latest_change":"2013-11-11T23:34:29Z","title":"Francis E. Stafford photographs, 1909-1933"}],"items":[{"druid":"druid:jf275fd6276","latest_change":"2013-11-11T23:34:29Z","title":"Album A: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."},{"druid":"druid:nz353cp1092","latest_change":"2013-11-11T23:34:29Z","title":"Album E: Photographs of the Seventh Day Adventist Church missionaries in China"},{"druid":"druid:tc552kq0798","latest_change":"2013-11-11T23:34:29Z","title":"Album D: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."},{"druid":"druid:th998nk0722","latest_change":"2013-11-11T23:34:29Z","title":"Album C: Photographs of the Chinese Revolution of 1911 and the Shanghai Commercial Press"},{"druid":"druid:ww689vs6534","latest_change":"2013-11-11T23:34:29Z","title":"Album B: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."}],"counts":{"collections":1,"items":5,"total_count":6}}']
expected_output = ["yg867hg1375", "jf275fd6276", "nz353cp1092", "tc552kq0798", "th998nk0722", "ww689vs6534"]
expect(@df.druid_array(input,{:no_prefix=>true})).to eq(expected_output)
end
end

describe "Calling RESTful API and processing output" do
Expand Down

0 comments on commit 0062247

Please sign in to comment.