Skip to content

Instantly share code, notes, and snippets.

@joejulian
Last active December 21, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joejulian/6275783 to your computer and use it in GitHub Desktop.
Save joejulian/6275783 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "rexml/document"
include REXML
service_document = Document.new `tools/scripts/data-deposit-api/test-service-document`
collection = XPath.first(service_document, "//collection/@href")
feed_of_studies = Document.new `tools/scripts/data-deposit-api/test-collection-get #{collection}`
first_study = XPath.first(feed_of_studies, "//entry")
id = first_study.elements["id"].text
study_edit_uri = first_study.attributes["xml:base"]
entry = Document.new `tools/scripts/data-deposit-api/test-edit-get #{study_edit_uri}`
statement_uri = XPath.first(entry,"//link[@rel='http://purl.org/net/sword/terms/statement']").attributes["href"]
zip_of_files_to_add = "example.zip"
puts "adding #{zip_of_files_to_add} to #{study_edit_uri}"
out = Document.new `tools/scripts/data-deposit-api/test-edit-post-binary #{zip_of_files_to_add} #{study_edit_uri}`
error_summary = XPath.first(out, "//atom:summary").text
if 'http://purl.org/net/sword/error/ErrorBadRequest' == error_summary
# error comes from https://github.com/swordapp/JavaServer2.0/blob/31e625ac97be13f794e1b98512f8d1c48d751652/src/main/java/org/swordapp/server/ContainerAPI.java#L364
# entryOnly or headersOnly expected (apparently)... not a binary
puts "As expected, error when POSTing binary to #{study_edit_uri}"
threshold = 6
puts "Printing first #{threshold} lines of the stacktrace:"
puts XPath.first(out, "//sword:verboseDescription").text.take(threshold).join("\n")
else
puts "Did not receive expected error when POSTing binary to #{study_edit_uri}"
end
#puts "id from out: " + out.root.elements["id"].text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment