Skip to content

Instantly share code, notes, and snippets.

@DanCoughlin
Created August 12, 2015 15:45
Show Gist options
  • Save DanCoughlin/e26bc99c74b2d75e5bac to your computer and use it in GitHub Desktop.
Save DanCoughlin/e26bc99c74b2d75e5bac to your computer and use it in GitHub Desktop.
Demonstration of creating cURL to get repos from archivespace
repo_id = 3
login_url = "http://<url to hit>/users/<user name to login as>/login"
repo_url = "http://<url to hit>/repositories/#{repo_id}/"
all_repos_url = "#{repo_url}/resources?all_ids=1"
ind_repo_url = "#{repo_url}/resources/"
c = Curl::Easy.http_post(login_url, Curl::PostField.content('password', '<config var>'))
json = JSON.parse(c.body_str)
token = json['session']
repos = Curl.get(all_repos_url) do |http|
http.headers['X-ArchivesSpace-Session'] = token
end
ids = repos.body_str.tr('[]', '').split(",")
@repos_json = []
# loop over only a couple for the sake of sanity
ids[1..5].each do |id|
repo = Curl.get("#{ind_repo_url}#{id}") do |http|
http.headers['X-ArchivesSpace-Session'] = token
end
@repos_json << JSON.parse(repo.body_str)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment