From 9560aa2903a7504f92964f19ff2cbf385edbff37 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 12 Apr 2017 18:54:56 +0200 Subject: [PATCH] intial commit --- .env | 4 + .travis.yml | 14 ++ CHANGELOG.md | 0 Dockerfile | 45 ++++ Gemfile | 30 +++ Gemfile.lock | 175 +++++++++++++ LICENSE | 2 +- README.md | 4 +- app.rb | 161 ++++++++++++ config.ru | 9 + docker-compose.yml | 13 + lib/content_negotiation.rb | 7 + lib/helpers.rb | 101 ++++++++ spec/api_spec.rb | 164 +++++++++++++ .../get_registered_content_types/absent.yml | 40 +++ .../get_registered_content_types/present.yml | 40 +++ .../available_content_type.yml | 38 +++ .../registered_content_type.yml | 40 +++ .../unsupported_content_type.yml | 73 ++++++ .../Helpers/should_pass_thru/doi.yml | 38 +++ .../vnd_citationstyles_csl_json/header.yml | 38 +++ .../vnd_citationstyles_csl_json/link.yml | 40 +++ .../vnd_citationstyles_csl_json/redirect.yml | 232 ++++++++++++++++++ .../vnd_datacite_datacite_json/header.yml | 40 +++ .../vnd_datacite_datacite_json/link.yml | 38 +++ .../vnd_datacite_datacite_json/redirect.yml | 232 ++++++++++++++++++ .../vnd_datacite_datacite_xml/header.yml | 38 +++ .../vnd_datacite_datacite_xml/link.yml | 40 +++ .../vnd_datacite_datacite_xml/redirect.yml | 232 ++++++++++++++++++ .../vnd_schemaorg_ld_json/header.yml | 40 +++ .../vnd_schemaorg_ld_json/link.yml | 38 +++ .../vnd_schemaorg_ld_json/redirect.yml | 232 ++++++++++++++++++ .../application/x-bibtex/header.yml | 40 +++ .../application/x-bibtex/link.yml | 40 +++ .../application/x-bibtex/redirect.yml | 232 ++++++++++++++++++ .../x-research-info-systems/header.yml | 38 +++ .../x-research-info-systems/link.yml | 40 +++ .../x-research-info-systems/redirect.yml | 232 ++++++++++++++++++ spec/heartbeat_spec.rb | 10 + spec/helpers_spec.rb | 89 +++++++ spec/spec_helper.rb | 60 +++++ vendor/docker/00_app_env.conf | 2 + vendor/docker/cors.conf | 3 + vendor/docker/ntp.conf | 4 + vendor/docker/webapp.conf | 10 + 45 files changed, 3036 insertions(+), 2 deletions(-) create mode 100644 .env create mode 100644 .travis.yml create mode 100644 CHANGELOG.md create mode 100644 Dockerfile create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 app.rb create mode 100644 config.ru create mode 100644 docker-compose.yml create mode 100644 lib/content_negotiation.rb create mode 100644 lib/helpers.rb create mode 100644 spec/api_spec.rb create mode 100644 spec/fixtures/vcr_cassettes/Helpers/get_registered_content_types/absent.yml create mode 100644 spec/fixtures/vcr_cassettes/Helpers/get_registered_content_types/present.yml create mode 100644 spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/available_content_type.yml create mode 100644 spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/registered_content_type.yml create mode 100644 spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/unsupported_content_type.yml create mode 100644 spec/fixtures/vcr_cassettes/Helpers/should_pass_thru/doi.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/header.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/link.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/redirect.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/header.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/link.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/redirect.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/header.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/link.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/redirect.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/header.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/link.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/redirect.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/header.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/link.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/redirect.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/header.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/link.yml create mode 100644 spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/redirect.yml create mode 100644 spec/heartbeat_spec.rb create mode 100644 spec/helpers_spec.rb create mode 100644 spec/spec_helper.rb create mode 100644 vendor/docker/00_app_env.conf create mode 100644 vendor/docker/cors.conf create mode 100644 vendor/docker/ntp.conf create mode 100644 vendor/docker/webapp.conf diff --git a/.env b/.env new file mode 100644 index 0000000..88e07db --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +TRUSTED_IP=127.0.0.1 +SEARCH_URL=https://search.datacite.org/ +CITEPROC_URL=https://citation.datacite.org/format +LOG_LEVEL=debug diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..0d5442a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: ruby +rvm: +- 2.3.3 + +addons: + code_climate: + repo_token: $CODECLIMATE_REPO_TOKEN + +install: +- travis_retry bundle install + +script: +- bundle exec rspec +- bundle exec codeclimate-test-reporter diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a79d31f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM phusion/passenger-full:0.9.20 +MAINTAINER Martin Fenner "mfenner@datacite.org" + +# Set correct environment variables. +ENV HOME /home/app + +# Allow app user to read /etc/container_environment +RUN usermod -a -G docker_env app + +# Use baseimage-docker's init process. +CMD ["/sbin/my_init"] + +# Install Ruby 2.3.3 +RUN bash -lc 'rvm --default use ruby-2.3.3' + +# Update installed APT packages +RUN apt-get update && apt-get upgrade -y -o Dpkg::Options::="--force-confold" && \ + apt-get install ntp -y && \ + apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Enable Passenger and Nginx and remove the default site +# Preserve env variables for nginx +RUN rm -f /etc/service/nginx/down && \ + rm /etc/nginx/sites-enabled/default +COPY vendor/docker/webapp.conf /etc/nginx/sites-enabled/webapp.conf +COPY vendor/docker/00_app_env.conf /etc/nginx/conf.d/00_app_env.conf +COPY vendor/docker/cors.conf /etc/nginx/conf.d/cors.conf + +# Use Amazon NTP servers +COPY vendor/docker/ntp.conf /etc/ntp.conf + +# Copy webapp folder +COPY . /home/app/webapp/ +RUN mkdir -p /home/app/webapp/vendor/bundle && \ + chown -R app:app /home/app/webapp && \ + chmod -R 755 /home/app/webapp + +# Install Ruby gems +WORKDIR /home/app/webapp +RUN gem update --system && \ + gem install bundler && \ + /sbin/setuser app bundle install --path vendor/bundle + +# Expose web +EXPOSE 80 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..46b8c33 --- /dev/null +++ b/Gemfile @@ -0,0 +1,30 @@ +source 'http://rubygems.org' + +gem 'dotenv' +gem 'bugsnag' +gem 'awesome_print' +gem 'activesupport' +gem 'sinatra' +gem 'sinatra-contrib' +gem 'multi_json' +gem 'json', '~> 1.8', '>= 1.8.5' +gem 'oj', '~> 2.18', '>= 2.18.1' +gem 'iso8601', '~> 0.9.0' +gem 'maremma', '~> 3.0' +gem 'bolognese', '~> 0.8.5' +gem 'nokogiri', '~> 1.6.8' + +group :development do + gem "better_errors" + gem "binding_of_caller" + gem 'thin', '~> 1.7' +end + +group :test do + gem 'rspec' + gem 'capybara' + gem 'webmock', '~> 1.20.0' + gem 'vcr', '~> 3.0.3' + gem 'codeclimate-test-reporter', '~> 1.0.0' + gem 'simplecov' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..7bceed9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,175 @@ +GEM + remote: http://rubygems.org/ + specs: + activesupport (4.2.8) + i18n (~> 0.7) + minitest (~> 5.1) + thread_safe (~> 0.3, >= 0.3.4) + tzinfo (~> 1.1) + addressable (2.5.1) + public_suffix (~> 2.0, >= 2.0.2) + awesome_print (1.7.0) + backports (3.7.0) + better_errors (2.1.1) + coderay (>= 1.0.0) + erubis (>= 2.6.6) + rack (>= 0.9.0) + bibtex-ruby (4.4.3) + latex-decode (~> 0.0) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) + bolognese (0.8.14) + activesupport (~> 4.2, >= 4.2.5) + bibtex-ruby (~> 4.1) + builder (~> 3.2, >= 3.2.2) + colorize (~> 0.8.1) + loofah (~> 2.0, >= 2.0.3) + maremma (~> 3.5) + namae (~> 0.10.2) + nokogiri (~> 1.6, >= 1.6.8) + postrank-uri (~> 1.0, >= 1.0.18) + thor (~> 0.19) + bugsnag (5.3.0) + builder (3.2.3) + capybara (2.13.0) + addressable + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + codeclimate-test-reporter (1.0.8) + simplecov (<= 0.13) + coderay (1.1.1) + colorize (0.8.1) + crack (0.4.3) + safe_yaml (~> 1.0.0) + daemons (1.2.4) + debug_inspector (0.0.2) + diff-lcs (1.3) + docile (1.1.5) + dotenv (2.2.0) + erubis (2.7.0) + eventmachine (1.2.3) + excon (0.45.4) + faraday (0.9.2) + multipart-post (>= 1.2, < 3) + faraday-encoding (0.0.4) + faraday + faraday_middleware (0.10.1) + faraday (>= 0.7.4, < 1.0) + i18n (0.8.1) + iso8601 (0.9.1) + json (1.8.6) + latex-decode (0.2.2) + unicode (~> 0.4) + loofah (2.0.3) + nokogiri (>= 1.5.9) + maremma (3.5.6) + activesupport (~> 4.2, >= 4.2.5) + addressable (>= 2.3.6) + builder (~> 3.2, >= 3.2.2) + excon (~> 0.45.0) + faraday (~> 0.9.2) + faraday-encoding (~> 0.0.1) + faraday_middleware (~> 0.10.0) + multi_json (~> 1.11.2) + nokogiri (~> 1.6, >= 1.6.8) + oj (~> 2.18, >= 2.18.1) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.10.1) + multi_json (1.11.3) + multipart-post (2.0.0) + namae (0.10.2) + nokogiri (1.6.8.1) + mini_portile2 (~> 2.1.0) + oj (2.18.5) + postrank-uri (1.0.22) + addressable (>= 2.3.0, < 2.6) + nokogiri (>= 1.6.1, < 1.8) + public_suffix (>= 2.0.0, < 2.1) + public_suffix (2.0.5) + rack (1.6.5) + rack-protection (1.5.3) + rack + rack-test (0.6.3) + rack (>= 1.0) + rspec (3.5.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-core (3.5.4) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + safe_yaml (1.0.4) + simplecov (0.13.0) + docile (~> 1.1.0) + json (>= 1.8, < 3) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) + sinatra (1.4.8) + rack (~> 1.5) + rack-protection (~> 1.4) + tilt (>= 1.3, < 3) + sinatra-contrib (1.4.7) + backports (>= 2.0) + multi_json + rack-protection + rack-test + sinatra (~> 1.4.0) + tilt (>= 1.3, < 3) + thin (1.7.0) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) + thor (0.19.4) + thread_safe (0.3.6) + tilt (2.0.7) + tzinfo (1.2.3) + thread_safe (~> 0.1) + unicode (0.4.4.4) + vcr (3.0.3) + webmock (1.20.4) + addressable (>= 2.3.6) + crack (>= 0.3.2) + xpath (2.0.0) + nokogiri (~> 1.3) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport + awesome_print + better_errors + binding_of_caller + bolognese (~> 0.8.5) + bugsnag + capybara + codeclimate-test-reporter (~> 1.0.0) + dotenv + iso8601 (~> 0.9.0) + json (~> 1.8, >= 1.8.5) + maremma (~> 3.0) + multi_json + nokogiri (~> 1.6.8) + oj (~> 2.18, >= 2.18.1) + rspec + simplecov + sinatra + sinatra-contrib + thin (~> 1.7) + vcr (~> 3.0.3) + webmock (~> 1.20.0) + +BUNDLED WITH + 1.12.5 diff --git a/LICENSE b/LICENSE index 87a03af..2e4df08 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 crosscite +Copyright (c) 2017 DataCite Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8f0bf4e..6dc1565 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# content-resolver \ No newline at end of file +# content-resolver + +[![Build Status](https://travis-ci.org/crosscite/content-negotiation.svg?branch=master)](https://travis-ci.org/crosscite/content-negotiation) diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..c355b19 --- /dev/null +++ b/app.rb @@ -0,0 +1,161 @@ +# # load ENV variables from .env file if it exists +env_file = File.expand_path("../.env", __FILE__) +if File.exist?(env_file) + require 'dotenv' + Dotenv.load! env_file +end + +# load ENV variables from container environment if json file exists +# see https://github.com/phusion/baseimage-docker#envvar_dumps +env_json_file = "/etc/container_environment.json" +if File.exist?(env_json_file) + env_vars = JSON.parse(File.read(env_json_file)) + env_vars.each { |k, v| ENV[k] = v } +end + +require 'active_support/all' + +# required ENV variables, can be set in .env file +ENV['APPLICATION'] ||= "content-negotiation" +ENV['SITE_TITLE'] ||= "DataCite Content Resolver" +ENV['LOG_LEVEL'] ||= "info" +ENV['API_URL'] ||= "https://api.datacite.org" +ENV['SEARCH_URL'] ||= "https://search.datacite.org" + +env_vars = %w(SITE_TITLE LOG_LEVEL API_URL) +env_vars.each { |env| fail ArgumentError, "ENV[#{env}] is not set" unless ENV[env].present? } + +require 'sinatra' +require 'sinatra/json' +require 'sinatra/contrib' +require 'sinatra/config_file' +require 'cgi' +require 'maremma' +require 'bolognese' +require 'open-uri' +require 'uri' +require 'better_errors' + +Dir[File.join(File.dirname(__FILE__), 'lib', '*.rb')].each { |f| require f } + +LOG_LEVELS = { + "debug" => ::Logger::DEBUG, + "info" => ::Logger::INFO, + "warn" => ::Logger::WARN, +} + +configure do + set :app_file, __FILE__ + + # Work around rack protection referrer bug + set :protection, except: :json_csrf + + # Set log level + set :logging, LOG_LEVELS[ENV['LOG_LEVEL']] + + # include bolognese utility methods + include Bolognese::Utils + include Bolognese::DoiUtils + + # optionally use Bugsnag for error tracking + if ENV['BUGSNAG_KEY'] + require 'bugsnag' + Bugsnag.configure do |config| + config.api_key = ENV['BUGSNAG_KEY'] + config.project_root = settings.root + config.app_version = App::VERSION + config.release_stage = ENV['RACK_ENV'] + config.notify_release_stages = %w(production stage development) + end + + use Bugsnag::Rack + enable :raise_errors + end +end + +configure :development do + use BetterErrors::Middleware + BetterErrors::Middleware.allow_ip! ENV['TRUSTED_IP'] + BetterErrors.application_root = File.expand_path('..', __FILE__) + + enable :raise_errors, :dump_errors + # disable :show_exceptions +end + +after do + response.headers['Access-Control-Allow-Origin'] = '*' +end + +get '/heartbeat' do + content_type 'text/html' + + 'OK' +end + +# return content in one of the formats supported by bolognese gem +get %r{/content/([^/]+/[^/]+)/(.+)} do + # id can be DOI or DOI expressed as URL + id = Bolognese::Utils.normalize_id(params[:captures].last) + halt 404, "#{params[:captures].last} not found" unless id.present? + + # from is DOI registration agency name + from = Bolognese::Utils.find_from_format(id: id) + + content_type = params[:captures].first + to = available_content_types[content_type] + halt 404, "content for #{content_type} not supported" unless to.present? + + logger.info "#{id} as #{content_type}" + + content_type content_type + + # generate metadata + generate(id: id, from: from, to: to) +end + +# legacy support for link-based text/html +# text/html in accept header is handled by handle proxy +get %r{/text/html/(.+)} do + # id can be DOI or DOI expressed as URL + id = Bolognese::Utils.normalize_id(params[:captures].first) + halt 404, "#{params[:captures].first} not found" unless id.present? + + url = ENV['SEARCH_URL'] + "works/" + doi_from_url(id) + logger.info "#{id} as text/html" + + content_type "text/html" + + redirect url, 303 +end + +# link-based content type +get %r{/([^/]+/[^/]+)/(.+)} do + # id can be DOI or DOI expressed as URL + id = Bolognese::Utils.normalize_id(params[:captures].last) + halt 404, "#{params[:captures].last} not found" unless id.present? + + accept_header = [params[:captures].first] + url = redirect_by_content_type(id: id, accept_header: accept_header) + + logger.info "#{id} as #{accept_header.first}" + + content_type accept_header.first + + redirect url, 303 +end + +# content type via accept header +get %r{/(.+)} do + # id can be DOI or DOI expressed as URL + id = Bolognese::Utils.normalize_id(params[:captures].first) + halt 404, "#{params[:captures].first} not found" unless id.present? + + accept_header = request.accept.map { |a| a.to_s } + url = redirect_by_content_type(id: id, accept_header: accept_header) + + logger.info "#{id} as #{accept_header.first}" + + content_type accept_header.first + + redirect url, 303 +end diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..7e4e031 --- /dev/null +++ b/config.ru @@ -0,0 +1,9 @@ +Encoding.default_external = Encoding::UTF_8 + +require 'rubygems' +require 'bundler' + +Bundler.require +require './app' + +run Sinatra::Application diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b4d1dec --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '2' + +services: + content-negotiation: + env_file: + - .env + image: crosscite/content-negotiation + build: . + ports: + - "8080:80" + volumes: + - ./spec:/home/app/webapp/spec + - ./app:/home/app/webapp/app diff --git a/lib/content_negotiation.rb b/lib/content_negotiation.rb new file mode 100644 index 0000000..11496cf --- /dev/null +++ b/lib/content_negotiation.rb @@ -0,0 +1,7 @@ +require 'sinatra/base' +require_relative 'helpers' + +# convenience class for testing +class ContentNegotiation + include Sinatra::Helpers +end diff --git a/lib/helpers.rb b/lib/helpers.rb new file mode 100644 index 0000000..2860a76 --- /dev/null +++ b/lib/helpers.rb @@ -0,0 +1,101 @@ +module Sinatra + module Helpers + def normalize_id(id) + Bolognese::Utils.normalize_id(id) + end + + def doi_from_url(id) + Bolognese::DoiUtils.doi_from_url(id) + end + + def validate_doi(id) + Bolognese::DoiUtils.validate_doi(id) + end + + def generate(id: nil, from: nil, to: nil) + Bolognese::Utils.generate(id: id, from: from, to: to) + end + + # determine content-type for the response, in that order: + # 1. content-type registered for DOI + # 2. content-type available in content negotiation + # 3. formatted citation via DOI formatter service + # 4. no content-type found, pass through to URL registered in handle system + # then redirect based on content_type + def redirect_by_content_type(id: nil, accept_header: nil) + should_redirect_registered(id: id, accept_header: accept_header) || + should_redirect_available(id: id, accept_header: accept_header) || + should_redirect_citation(id: nil, accept_header: nil) || + should_pass_thru(id: id) + end + + def should_redirect_registered(id: nil, accept_header: nil) + registered_content_types = get_registered_content_types(id) + + content_type = (accept_header & registered_content_types.keys).first + registered_content_types[content_type] + end + + def should_redirect_citation(id: nil, accept_header: nil) + content_type = accept_header.find { |i| i.start_with?("text/x-bibliography") } + return nil unless content_type.present? + + hsh = content_type.split("; ").reduce({}) do |sum, i| + k, v = i.split("=") + sum[k] = v if v.present? + sum + end + + params = { doi: doi_from_url(id), + style: hsh["style"] || "apa", + locale: hsh["locale"] || "en-US" } + + ENV['CITEPROC_URL'] + "?" + URI.encode_www_form(params) + end + + def should_redirect_available(id: nil, accept_header: nil) + content_type = (accept_header & available_content_types.keys).first + return nil unless content_type.present? + + "/content/" + content_type + "/" + doi_from_url(id) + end + + def should_pass_thru(id: nil) + return nil unless validate_doi(id) + + response = Maremma.head id, limit: 0 + response.headers["location"] + end + + # content-types registered for that DOI + def get_registered_content_types(id) + doi = doi_from_url(id) + media_url = ENV['SEARCH_URL'] + "api?q=doi:#{doi}&fl=doi,media&wt=json" + response = Maremma.get media_url + doc = response.body.dig("data", "response", "docs").first + if doc.present? + doc.fetch("media", []).reduce({}) do|sum, i| + content_type, url = i.split(":", 2) + sum[content_type] = url + sum + end + else + {} + end + end + + # content-types supported by bolognese gem + def available_content_types + { + 'application/vnd.datacite.datacite+xml' => 'datacite', + 'application/vnd.datacite.datacite+json' => 'datacite_json', + 'application/vnd.schemaorg.ld+json' => 'schema_org', + 'application/vnd.citationstyles.csl+json' => 'citeproc', + 'application/x-research-info-systems' => 'ris', + 'application/x-bibtex' => 'bibtex' + } + end + end +end + +Sinatra::Application.helpers Sinatra::Helpers diff --git a/spec/api_spec.rb b/spec/api_spec.rb new file mode 100644 index 0000000..d2a915f --- /dev/null +++ b/spec/api_spec.rb @@ -0,0 +1,164 @@ +require 'spec_helper' + +describe 'content negotiation', vcr: true do + context "application/vnd.datacite.datacite+xml" do + it "header" do + get '/10.5061/dryad.8515', nil, { "HTTP_ACCEPT" => "application/vnd.datacite.datacite+xml" } + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.datacite.datacite+xml/10.5061/dryad.8515") + end + + it "link" do + get '/application/vnd.datacite.datacite+xml/10.5061/dryad.8515' + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.datacite.datacite+xml/10.5061/dryad.8515") + end + + it "redirect" do + get '/content/application/vnd.datacite.datacite+xml/10.5061/dryad.8515' + + expect(last_response.status).to eq(200) + expect(last_response.body).to eq("http://example.org/content/application/vnd.datacite.datacite+xml/10.5061/dryad.8515") + end + end + + context "application/vnd.datacite.datacite+xml" do + it "header" do + get '/10.5061/dryad.8515', nil, { "HTTP_ACCEPT" => "application/vnd.datacite.datacite+xml" } + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.datacite.datacite+xml/10.5061/dryad.8515") + end + + it "link" do + get '/application/vnd.datacite.datacite+xml/10.5061/dryad.8515' + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.datacite.datacite+xml/10.5061/dryad.8515") + end + + it "redirect" do + get '/content/application/vnd.datacite.datacite+xml/10.5061/dryad.8515' + + expect(last_response.status).to eq(200) + expect(last_response.body).to eq("") + end + end + + context "application/vnd.datacite.datacite+json" do + it "header" do + get '/10.5061/dryad.8515', nil, { "HTTP_ACCEPT" => "application/vnd.datacite.datacite+json" } + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.datacite.datacite+json/10.5061/dryad.8515") + end + + it "link" do + get '/application/vnd.datacite.datacite+json/10.5061/dryad.8515' + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.datacite.datacite+json/10.5061/dryad.8515") + end + + it "redirect" do + get '/content/application/vnd.datacite.datacite+json/10.5061/dryad.8515' + + expect(last_response.status).to eq(200) + expect(last_response.body).to eq("") + end + end + + context "application/vnd.schemaorg.ld+json" do + it "header" do + get '/10.5061/dryad.8515', nil, { "HTTP_ACCEPT" => "application/vnd.schemaorg.ld+json" } + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.schemaorg.ld+json/10.5061/dryad.8515") + end + + it "link" do + get '/application/vnd.schemaorg.ld+json/10.5061/dryad.8515' + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.schemaorg.ld+json/10.5061/dryad.8515") + end + + it "redirect" do + get '/content/application/vnd.schemaorg.ld+json/10.5061/dryad.8515' + + expect(last_response.status).to eq(200) + expect(last_response.body).to eq("") + end + end + + context "application/vnd.citationstyles.csl+json" do + it "header" do + get '/10.5061/dryad.8515', nil, { "HTTP_ACCEPT" => "application/vnd.citationstyles.csl+json" } + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.citationstyles.csl+json/10.5061/dryad.8515") + end + + it "link" do + get '/application/vnd.citationstyles.csl+json/10.5061/dryad.8515' + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/vnd.citationstyles.csl+json/10.5061/dryad.8515") + end + + it "redirect" do + get '/content/application/vnd.citationstyles.csl+json/10.5061/dryad.8515' + + expect(last_response.status).to eq(200) + expect(last_response.body).to eq("") + end + end + + context "application/x-research-info-systems" do + it "header" do + get '/10.5061/dryad.8515', nil, { "HTTP_ACCEPT" => "application/x-research-info-systems" } + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/x-research-info-systems/10.5061/dryad.8515") + end + + it "link" do + get '/application/x-research-info-systems/10.5061/dryad.8515' + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/x-research-info-systems/10.5061/dryad.8515") + end + + it "redirect" do + get '/content/application/x-research-info-systems/10.5061/dryad.8515' + + expect(last_response.status).to eq(200) + expect(last_response.body).to eq("") + end + end + + context "application/x-bibtex" do + it "header" do + get '/10.5061/dryad.8515', nil, { "HTTP_ACCEPT" => "application/x-bibtex" } + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/x-bibtex/10.5061/dryad.8515") + end + + it "link" do + get '/application/x-bibtex/10.5061/dryad.8515' + + expect(last_response.status).to eq(303) + expect(last_response.headers["Location"]).to eq("http://example.org/content/application/x-bibtex/10.5061/dryad.8515") + end + + it "redirect" do + get '/content/application/x-bibtex/10.5061/dryad.8515' + + expect(last_response.status).to eq(200) + expect(last_response.body).to eq("") + end + end +end diff --git a/spec/fixtures/vcr_cassettes/Helpers/get_registered_content_types/absent.yml b/spec/fixtures/vcr_cassettes/Helpers/get_registered_content_types/absent.yml new file mode 100644 index 0000000..6153f6c --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Helpers/get_registered_content_types/absent.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:09 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '116' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":6},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:09 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Helpers/get_registered_content_types/present.yml b/spec/fixtures/vcr_cassettes/Helpers/get_registered_content_types/present.yml new file mode 100644 index 0000000..c670cc1 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Helpers/get_registered_content_types/present.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5284/1015681&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:10 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '282' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":6},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5284/1015681","media":["application/pdf:http://archaeologydataservice.ac.uk/catalogue/adsdata/arch-1045-1/dissemination/pdf/356_ThewatertreatmentplantSaltersfordGrantham_Little.pdf"]}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:10 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/available_content_type.yml b/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/available_content_type.yml new file mode 100644 index 0000000..970d46a --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/available_content_type.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5438/0000-0c2g&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:11 GMT + Server: + - openresty/1.11.2.2 + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":3},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5438/0000-0C2G","media":["application/xml:https://blog.datacite.org/oi-project-underway-for-open-org-id-registry/oi-project-underway-for-open-org-id-registry.xml"]}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:10 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/registered_content_type.yml b/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/registered_content_type.yml new file mode 100644 index 0000000..1c8fce4 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/registered_content_type.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5284/1015681&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:10 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '282' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5284/1015681","media":["application/pdf:http://archaeologydataservice.ac.uk/catalogue/adsdata/arch-1045-1/dissemination/pdf/356_ThewatertreatmentplantSaltersfordGrantham_Little.pdf"]}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:10 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/unsupported_content_type.yml b/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/unsupported_content_type.yml new file mode 100644 index 0000000..d7f472f --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Helpers/redirect_by_content_type/unsupported_content_type.yml @@ -0,0 +1,73 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5438/0000-0c2g&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:11 GMT + Server: + - openresty/1.11.2.2 + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":1},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5438/0000-0C2G","media":["application/xml:https://blog.datacite.org/oi-project-underway-for-open-org-id-registry/oi-project-underway-for-open-org-id-registry.xml"]}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:11 GMT +- request: + method: head + uri: https://doi.org/10.5438/0000-0C2G + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 303 + message: '' + headers: + Server: + - Apache-Coyote/1.1 + Vary: + - Accept + Location: + - https://blog.datacite.org/oi-project-underway-for-open-org-id-registry/ + Expires: + - Wed, 12 Apr 2017 13:23:04 GMT + Content-Type: + - text/html;charset=utf-8 + Content-Length: + - '227' + Date: + - Wed, 12 Apr 2017 13:22:10 GMT + body: + encoding: UTF-8 + string: '' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:11 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/Helpers/should_pass_thru/doi.yml b/spec/fixtures/vcr_cassettes/Helpers/should_pass_thru/doi.yml new file mode 100644 index 0000000..c453567 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Helpers/should_pass_thru/doi.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: head + uri: https://doi.org/10.5284/1015681 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 303 + message: '' + headers: + Server: + - Apache-Coyote/1.1 + Vary: + - Accept + Location: + - http://archaeologydataservice.ac.uk/archives/view/greylit/details.cfm?id=13979 + Expires: + - Wed, 12 Apr 2017 13:23:04 GMT + Content-Type: + - text/html;charset=utf-8 + Content-Length: + - '241' + Date: + - Wed, 12 Apr 2017 13:22:09 GMT + body: + encoding: UTF-8 + string: '' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:10 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/header.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/header.yml new file mode 100644 index 0000000..7a63b41 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/header.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:22 GMT + Server: + - openresty/1.11.2.2 + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":1},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:22 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/link.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/link.yml new file mode 100644 index 0000000..1cb5e7e --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/link.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:22 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '116' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:22 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/redirect.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/redirect.yml new file mode 100644 index 0000000..0f8cd51 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_citationstyles_csl_json/redirect.yml @@ -0,0 +1,232 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.datacite.org/prefixes/10.5061 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Headers: + - Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Max-Age: + - '1728000' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/vnd.api+json; charset=utf-8 + Date: + - Wed, 12 Apr 2017 13:22:21 GMT + Etag: + - W/"1eb3f4f371821b1becc6cd25a71755ce" + Server: + - openresty/1.11.2.2 + Status: + - 200 OK + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Powered-By: + - Phusion Passenger 5.1.2 + X-Request-Id: + - cb855ff6-4cf8-407f-8557-131c347bab6b + X-Runtime: + - '0.211004' + X-Xss-Protection: + - 1; mode=block + Content-Length: + - '124' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"data":{"id":"10.5061","type":"prefixes","attributes":{"registration-agency":"DataCite","updated":"2016-09-21T20:27:07Z"}}}' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:21 GMT +- request: + method: get + uri: https://doi.org/10.5061/dryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 303 + message: '' + headers: + Server: + - Apache-Coyote/1.1 + Vary: + - Accept + Location: + - http://data.datacite.org/10.5061%2Fdryad.8515 + Expires: + - Wed, 12 Apr 2017 13:23:04 GMT + Content-Type: + - text/html;charset=utf-8 + Content-Length: + - '175' + Date: + - Wed, 12 Apr 2017 13:22:21 GMT + body: + encoding: UTF-8 + string: |- + Handle Redirect + http://data.datacite.org/10.5061%2Fdryad.8515 + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:22 GMT +- request: + method: get + uri: http://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 301 + message: '' + headers: + Content-Type: + - text/html + Date: + - Wed, 12 Apr 2017 13:22:22 GMT + Location: + - https://data.datacite.org/10.5061%2Fdryad.8515 + Server: + - openresty/1.11.2.2 + Content-Length: + - '191' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: "\r\n301 Moved Permanently\r\n\r\n

301 Moved Permanently

\r\n
openresty/1.11.2.2
\r\n\r\n\r\n" + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:22 GMT +- request: + method: get + uri: https://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - no-transform, max-age=3600 + Content-Type: + - application/vnd.datacite.datacite+xml + Date: + - Wed, 12 Apr 2017 13:22:22 GMT + Last-Modified: + - Sat, 04 Feb 2017 17:54:37 GMT + Server: + - openresty/1.11.2.2 + Vary: + - Accept + Content-Length: + - '2601' + Connection: + - keep-alive + body: + encoding: ASCII-8BIT + string: !binary |- + PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHJlc291 + cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwt + MyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVt + YS1pbnN0YW5jZSIgeG1sbnM6bWV0cz0iaHR0cDovL3d3dy5sb2MuZ292L01F + VFMvIiB4bWxuczpkc3BhY2U9Imh0dHA6Ly93d3cuZHNwYWNlLm9yZy94bWxu + cy9kc3BhY2UvZGltIiB4bWxuczpkaW09Imh0dHA6Ly93d3cuZHNwYWNlLm9y + Zy94bWxucy9kc3BhY2UvZGltIiB4bWxuczpkcnlhZD0iaHR0cDovL3B1cmwu + b3JnL2RyeWFkL3Rlcm1zLyIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8v + ZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyBodHRwOi8vc2NoZW1hLmRh + dGFjaXRlLm9yZy9tZXRhL2tlcm5lbC0zL21ldGFkYXRhLnhzZCI+ICA8aWRl + bnRpZmllciBpZGVudGlmaWVyVHlwZT0iRE9JIj4xMC41MDYxL0RSWUFELjg1 + MTU8L2lkZW50aWZpZXI+ICA8dmVyc2lvbj4xPC92ZXJzaW9uPiAgPGNyZWF0 + b3JzPiAgICA8Y3JlYXRvcj4gIC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AgICA8 + cmVsYXRlZElkZW50aWZpZXIgcmVsYXRlZElkZW50aWZpZXJUeXBlPSJET0ki + IHJlbGF0aW9uVHlwZT0iSGFzUGFydCI+MTAuNTA2MS9EUllBRC44NTE1LzI8 + L3JlbGF0ZWRJZGVudGlmaWVyPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVs + YXRlZElkZW50aWZpZXJUeXBlPSJET0kiIHJlbGF0aW9uVHlwZT0iSXNSZWZl + cmVuY2VkQnkiPjEwLjEzNzEvSk9VUk5BTC5QUEFULjEwMDA0NDY8L3JlbGF0 + ZWRJZGVudGlmaWVyPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVsYXRlZElk + ZW50aWZpZXJUeXBlPSJQTUlEIiByZWxhdGlvblR5cGU9IklzUmVmZXJlbmNl + ZEJ5Ij4xOTQ3ODg3NzwvcmVsYXRlZElkZW50aWZpZXI+ICA8L3JlbGF0ZWRJ + ZGVudGlmaWVycz4gIDxyaWdodHNMaXN0PiAgICA8cmlnaHRzIHJpZ2h0c1VS + ST0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvcHVibGljZG9tYWluL3pl + cm8vMS4wLyIvPiAgPC9yaWdodHNMaXN0PjwvcmVzb3VyY2U+ + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:22 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/header.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/header.yml new file mode 100644 index 0000000..940368e --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/header.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:20 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '116' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:20 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/link.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/link.yml new file mode 100644 index 0000000..3c165d8 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/link.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:21 GMT + Server: + - openresty/1.11.2.2 + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:21 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/redirect.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/redirect.yml new file mode 100644 index 0000000..fdd1887 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_json/redirect.yml @@ -0,0 +1,232 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.datacite.org/prefixes/10.5061 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Headers: + - Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Max-Age: + - '1728000' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/vnd.api+json; charset=utf-8 + Date: + - Wed, 12 Apr 2017 13:22:19 GMT + Etag: + - W/"1eb3f4f371821b1becc6cd25a71755ce" + Server: + - openresty/1.11.2.2 + Status: + - 200 OK + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Powered-By: + - Phusion Passenger 5.1.2 + X-Request-Id: + - 0143c3df-3994-487f-a47d-3fb1b8ffa7a5 + X-Runtime: + - '0.631837' + X-Xss-Protection: + - 1; mode=block + Content-Length: + - '124' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"data":{"id":"10.5061","type":"prefixes","attributes":{"registration-agency":"DataCite","updated":"2016-09-21T20:27:07Z"}}}' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:19 GMT +- request: + method: get + uri: https://doi.org/10.5061/dryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 303 + message: '' + headers: + Server: + - Apache-Coyote/1.1 + Vary: + - Accept + Location: + - http://data.datacite.org/10.5061%2Fdryad.8515 + Expires: + - Wed, 12 Apr 2017 13:23:04 GMT + Content-Type: + - text/html;charset=utf-8 + Content-Length: + - '175' + Date: + - Wed, 12 Apr 2017 13:22:20 GMT + body: + encoding: UTF-8 + string: |- + Handle Redirect + http://data.datacite.org/10.5061%2Fdryad.8515 + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:20 GMT +- request: + method: get + uri: http://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 301 + message: '' + headers: + Content-Type: + - text/html + Date: + - Wed, 12 Apr 2017 13:22:20 GMT + Location: + - https://data.datacite.org/10.5061%2Fdryad.8515 + Server: + - openresty/1.11.2.2 + Content-Length: + - '191' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: "\r\n301 Moved Permanently\r\n\r\n

301 Moved Permanently

\r\n
openresty/1.11.2.2
\r\n\r\n\r\n" + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:20 GMT +- request: + method: get + uri: https://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - no-transform, max-age=3600 + Content-Type: + - application/vnd.datacite.datacite+xml + Date: + - Wed, 12 Apr 2017 13:22:20 GMT + Last-Modified: + - Sat, 04 Feb 2017 17:54:37 GMT + Server: + - openresty/1.11.2.2 + Vary: + - Accept + Content-Length: + - '2601' + Connection: + - keep-alive + body: + encoding: ASCII-8BIT + string: !binary |- + PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHJlc291 + cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpd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ByZWxhdGlvblR5cGU9IklzUmVmZXJlbmNl + ZEJ5Ij4xOTQ3ODg3NzwvcmVsYXRlZElkZW50aWZpZXI+ICA8L3JlbGF0ZWRJ + ZGVudGlmaWVycz4gIDxyaWdodHNMaXN0PiAgICA8cmlnaHRzIHJpZ2h0c1VS + ST0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvcHVibGljZG9tYWluL3pl + cm8vMS4wLyIvPiAgPC9yaWdodHNMaXN0PjwvcmVzb3VyY2U+ + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:20 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/header.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/header.yml new file mode 100644 index 0000000..1faea4a --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/header.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:14 GMT + Server: + - openresty/1.11.2.2 + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:14 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/link.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/link.yml new file mode 100644 index 0000000..b6b34e8 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/link.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:15 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '116' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:14 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/redirect.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/redirect.yml new file mode 100644 index 0000000..7be7e89 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_datacite_datacite_xml/redirect.yml @@ -0,0 +1,232 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.datacite.org/prefixes/10.5061 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Headers: + - Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Max-Age: + - '1728000' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/vnd.api+json; charset=utf-8 + Date: + - Wed, 12 Apr 2017 13:22:13 GMT + Etag: + - W/"1eb3f4f371821b1becc6cd25a71755ce" + Server: + - openresty/1.11.2.2 + Status: + - 200 OK + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Powered-By: + - Phusion Passenger 5.1.2 + X-Request-Id: + - 6335d3bb-1323-4b1c-a473-5e9db132fe75 + X-Runtime: + - '1.643180' + X-Xss-Protection: + - 1; mode=block + Content-Length: + - '124' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"data":{"id":"10.5061","type":"prefixes","attributes":{"registration-agency":"DataCite","updated":"2016-09-21T20:27:07Z"}}}' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:13 GMT +- request: + method: get + uri: https://doi.org/10.5061/dryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 303 + message: '' + headers: + Server: + - Apache-Coyote/1.1 + Vary: + - Accept + Location: + - http://data.datacite.org/10.5061%2Fdryad.8515 + Expires: + - Wed, 12 Apr 2017 13:23:04 GMT + Content-Type: + - text/html;charset=utf-8 + Content-Length: + - '175' + Date: + - Wed, 12 Apr 2017 13:22:14 GMT + body: + encoding: UTF-8 + string: |- + Handle Redirect + http://data.datacite.org/10.5061%2Fdryad.8515 + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:14 GMT +- request: + method: get + uri: http://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 301 + message: '' + headers: + Content-Type: + - text/html + Date: + - Wed, 12 Apr 2017 13:22:14 GMT + Location: + - https://data.datacite.org/10.5061%2Fdryad.8515 + Server: + - openresty/1.11.2.2 + Content-Length: + - '191' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: "\r\n301 Moved Permanently\r\n\r\n

301 Moved Permanently

\r\n
openresty/1.11.2.2
\r\n\r\n\r\n" + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:14 GMT +- request: + method: get + uri: https://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - no-transform, max-age=3600 + Content-Type: + - application/vnd.datacite.datacite+xml + Date: + - Wed, 12 Apr 2017 13:22:14 GMT + Last-Modified: + - Sat, 04 Feb 2017 17:54:37 GMT + Server: + - openresty/1.11.2.2 + Vary: + - Accept + Content-Length: + - '2601' + Connection: + - keep-alive + body: + encoding: ASCII-8BIT + string: !binary |- + PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHJlc291 + cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwt + MyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVt + YS1pbnN0YW5jZSIgeG1sbnM6bWV0cz0iaHR0cDovL3d3dy5sb2MuZ292L01F + VFMvIiB4bWxuczpkc3BhY2U9Imh0dHA6Ly93d3cuZHNwYWNlLm9yZy94bWxu + cy9kc3BhY2UvZGltIiB4bWxuczpkaW09Imh0dHA6Ly93d3cuZHNwYWNlLm9y + Zy94bWxucy9kc3BhY2UvZGltIiB4bWxuczpkcnlhZD0iaHR0cDovL3B1cmwu + b3JnL2RyeWFkL3Rlcm1zLyIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodH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aG9nZW5zIDUoNSk6IGUxMDAwNDQ2LjwvYWx0ZXJu + YXRlSWRlbnRpZmllcj4gIDwvYWx0ZXJuYXRlSWRlbnRpZmllcnM+ICA8cmVs + YXRlZElkZW50aWZpZXJzPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVsYXRl + ZElkZW50aWZpZXJUeXBlPSJET0kiIHJlbGF0aW9uVHlwZT0iSGFzUGFydCI+ + MTAuNTA2MS9EUllBRC44NTE1LzE8L3JlbGF0ZWRJZGVudGlmaWVyPiAgICA8 + cmVsYXRlZElkZW50aWZpZXIgcmVsYXRlZElkZW50aWZpZXJUeXBlPSJET0ki + IHJlbGF0aW9uVHlwZT0iSGFzUGFydCI+MTAuNTA2MS9EUllBRC44NTE1LzI8 + L3JlbGF0ZWRJZGVudGlmaWVyPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVs + YXRlZElkZW50aWZpZXJUeXBlPSJET0kiIHJlbGF0aW9uVHlwZT0iSXNSZWZl + cmVuY2VkQnkiPjEwLjEzNzEvSk9VUk5BTC5QUEFULjEwMDA0NDY8L3JlbGF0 + ZWRJZGVudGlmaWVyPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVsYXRlZElk + ZW50aWZpZXJUeXBlPSJQTUlEIiByZWxhdGlvblR5cGU9IklzUmVmZXJlbmNl + ZEJ5Ij4xOTQ3ODg3NzwvcmVsYXRlZElkZW50aWZpZXI+ICA8L3JlbGF0ZWRJ + ZGVudGlmaWVycz4gIDxyaWdodHNMaXN0PiAgICA8cmlnaHRzIHJpZ2h0c1VS + ST0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvcHVibGljZG9tYWluL3pl + cm8vMS4wLyIvPiAgPC9yaWdodHNMaXN0PjwvcmVzb3VyY2U+ + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:14 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/header.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/header.yml new file mode 100644 index 0000000..1cb5e7e --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/header.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:22 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '116' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:22 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/link.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/link.yml new file mode 100644 index 0000000..f537c76 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/link.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:24 GMT + Server: + - openresty/1.11.2.2 + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:24 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/redirect.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/redirect.yml new file mode 100644 index 0000000..4714848 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/vnd_schemaorg_ld_json/redirect.yml @@ -0,0 +1,232 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.datacite.org/prefixes/10.5061 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Headers: + - Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Max-Age: + - '1728000' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/vnd.api+json; charset=utf-8 + Date: + - Wed, 12 Apr 2017 13:22:23 GMT + Etag: + - W/"1eb3f4f371821b1becc6cd25a71755ce" + Server: + - openresty/1.11.2.2 + Status: + - 200 OK + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Powered-By: + - Phusion Passenger 5.1.2 + X-Request-Id: + - 73c02928-25d6-47ab-8eff-b65108f1097f + X-Runtime: + - '0.313188' + X-Xss-Protection: + - 1; mode=block + Content-Length: + - '124' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"data":{"id":"10.5061","type":"prefixes","attributes":{"registration-agency":"DataCite","updated":"2016-09-21T20:27:07Z"}}}' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:23 GMT +- request: + method: get + uri: https://doi.org/10.5061/dryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 303 + message: '' + headers: + Server: + - Apache-Coyote/1.1 + Vary: + - Accept + Location: + - http://data.datacite.org/10.5061%2Fdryad.8515 + Expires: + - Wed, 12 Apr 2017 13:23:04 GMT + Content-Type: + - text/html;charset=utf-8 + Content-Length: + - '175' + Date: + - Wed, 12 Apr 2017 13:22:23 GMT + body: + encoding: UTF-8 + string: |- + Handle Redirect + http://data.datacite.org/10.5061%2Fdryad.8515 + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:23 GMT +- request: + method: get + uri: http://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 301 + message: '' + headers: + Content-Type: + - text/html + Date: + - Wed, 12 Apr 2017 13:22:24 GMT + Location: + - https://data.datacite.org/10.5061%2Fdryad.8515 + Server: + - openresty/1.11.2.2 + Content-Length: + - '191' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: "\r\n301 Moved Permanently\r\n\r\n

301 Moved Permanently

\r\n
openresty/1.11.2.2
\r\n\r\n\r\n" + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:24 GMT +- request: + method: get + uri: https://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - no-transform, max-age=3600 + Content-Type: + - application/vnd.datacite.datacite+xml + Date: + - Wed, 12 Apr 2017 13:22:24 GMT + Last-Modified: + - Sat, 04 Feb 2017 17:54:37 GMT + Server: + - openresty/1.11.2.2 + Vary: + - Accept + Content-Length: + - '2601' + Connection: + - keep-alive + body: + encoding: ASCII-8BIT + string: !binary |- + PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHJlc291 + cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwt + MyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVt + YS1pbnN0YW5jZSIgeG1sbnM6bWV0cz0iaHR0cDovL3d3dy5sb2MuZ292L01F + VFMvIiB4bWxuczpkc3BhY2U9Imh0dHA6Ly93d3cuZHNwYWNlLm9yZy94bWxu + cy9kc3BhY2UvZGltIiB4bWxuczpkaW09Imh0dHA6Ly93d3cuZHNwYWNlLm9y + Zy94bWxucy9kc3BhY2UvZGltIiB4bWxuczpkcnlhZD0iaHR0cDovL3B1cmwu + b3JnL2RyeWFkL3Rlcm1zLyIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8v + ZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyBodHRwOi8vc2NoZW1hLmRh + dGFjaXRlLm9yZy9tZXRhL2tlcm5lbC0zL21ldGFkYXRhLnhzZCI+ICA8aWRl + bnRpZmllciBpZGVudGlmaWVyVHlwZT0iRE9JIj4xMC41MDYxL0RSWUFELjg1 + MTU8L2lkZW50aWZpZXI+ICA8dmVyc2lvbj4xPC92ZXJzaW9uPiAgPGNyZWF0 + b3JzPiAgICA8Y3JlYXRvcj4gICAgICA8Y3JlYXRvck5hbWU+T2xsb21vLCBC + ZW5qYW1pbjwvY3JlYXRvck5hbWU+ICAgIDwvY3JlYXRvcj4gICAgPGNyZWF0 + b3I+ICAgICAgPG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llBRC44NTE1LzI8 + L3JlbGF0ZWRJZGVudGlmaWVyPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVs + YXRlZElkZW50aWZpZXJUeXBlPSJET0kiIHJlbGF0aW9uVHlwZT0iSXNSZWZl + cmVuY2VkQnkiPjEwLjEzNzEvSk9VUk5BTC5QUEFULjEwMDA0NDY8L3JlbGF0 + ZWRJZGVudGlmaWVyPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVsYXRlZElk + ZW50aWZpZXJUeXBlPSJQTUlEIiByZWxhdGlvblR5cGU9IklzUmVmZXJlbmNl + ZEJ5Ij4xOTQ3ODg3NzwvcmVsYXRlZElkZW50aWZpZXI+ICA8L3JlbGF0ZWRJ + ZGVudGlmaWVycz4gIDxyaWdodHNMaXN0PiAgICA8cmlnaHRzIHJpZ2h0c1VS + ST0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvcHVibGljZG9tYWluL3pl + cm8vMS4wLyIvPiAgPC9yaWdodHNMaXN0PjwvcmVzb3VyY2U+ + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:24 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/header.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/header.yml new file mode 100644 index 0000000..f4c9a49 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/header.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:16 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '116' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:16 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/link.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/link.yml new file mode 100644 index 0000000..ed7c928 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/link.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:17 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '116' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:16 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/redirect.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/redirect.yml new file mode 100644 index 0000000..e178f88 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-bibtex/redirect.yml @@ -0,0 +1,232 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.datacite.org/prefixes/10.5061 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Headers: + - Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Max-Age: + - '1728000' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/vnd.api+json; charset=utf-8 + Date: + - Wed, 12 Apr 2017 13:22:18 GMT + Etag: + - W/"1eb3f4f371821b1becc6cd25a71755ce" + Server: + - openresty/1.11.2.2 + Status: + - 200 OK + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Powered-By: + - Phusion Passenger 5.1.2 + X-Request-Id: + - 85ce8228-1d2c-4981-a71c-2c6f8b69ec1a + X-Runtime: + - '0.763422' + X-Xss-Protection: + - 1; mode=block + Content-Length: + - '124' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"data":{"id":"10.5061","type":"prefixes","attributes":{"registration-agency":"DataCite","updated":"2016-09-21T20:27:07Z"}}}' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:17 GMT +- request: + method: get + uri: https://doi.org/10.5061/dryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 303 + message: '' + headers: + Server: + - Apache-Coyote/1.1 + Vary: + - Accept + Location: + - http://data.datacite.org/10.5061%2Fdryad.8515 + Expires: + - Wed, 12 Apr 2017 13:23:04 GMT + Content-Type: + - text/html;charset=utf-8 + Content-Length: + - '175' + Date: + - Wed, 12 Apr 2017 13:22:18 GMT + body: + encoding: UTF-8 + string: |- + Handle Redirect + http://data.datacite.org/10.5061%2Fdryad.8515 + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:18 GMT +- request: + method: get + uri: http://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 301 + message: '' + headers: + Content-Type: + - text/html + Date: + - Wed, 12 Apr 2017 13:22:18 GMT + Location: + - https://data.datacite.org/10.5061%2Fdryad.8515 + Server: + - openresty/1.11.2.2 + Content-Length: + - '191' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: "\r\n301 Moved Permanently\r\n\r\n

301 Moved Permanently

\r\n
openresty/1.11.2.2
\r\n\r\n\r\n" + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:18 GMT +- request: + method: get + uri: https://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - no-transform, max-age=3600 + Content-Type: + - application/vnd.datacite.datacite+xml + Date: + - Wed, 12 Apr 2017 13:22:19 GMT + Last-Modified: + - Sat, 04 Feb 2017 17:54:37 GMT + Server: + - openresty/1.11.2.2 + Vary: + - Accept + Content-Length: + - '2601' + Connection: + - keep-alive + body: + encoding: ASCII-8BIT + string: !binary |- + PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHJlc291 + cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwt + MyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVt + YS1pbnN0YW5jZSIgeG1sbnM6bWV0cz0iaHR0cDovL3d3dy5sb2MuZ292L01F + VFMvIiB4bWx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+ ST0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvcHVibGljZG9tYWluL3pl + cm8vMS4wLyIvPiAgPC9yaWdodHNMaXN0PjwvcmVzb3VyY2U+ + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:18 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/header.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/header.yml new file mode 100644 index 0000000..f0f70be --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/header.yml @@ -0,0 +1,38 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:16 GMT + Server: + - openresty/1.11.2.2 + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":1},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:16 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/link.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/link.yml new file mode 100644 index 0000000..f4c9a49 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/link.yml @@ -0,0 +1,40 @@ +--- +http_interactions: +- request: + method: get + uri: https://search.datacite.org/api?fl=doi,media&q=doi:10.5061/dryad.8515&wt=json + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 12 Apr 2017 13:22:16 GMT + Server: + - openresty/1.11.2.2 + Content-Length: + - '116' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"responseHeader":{"status":0,"QTime":0},"response":{"numFound":1,"start":0,"docs":[{"doi":"10.5061/DRYAD.8515"}]}} + +' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:16 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/redirect.yml b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/redirect.yml new file mode 100644 index 0000000..76cded5 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/content_negotiation/application/x-research-info-systems/redirect.yml @@ -0,0 +1,232 @@ +--- +http_interactions: +- request: + method: get + uri: https://api.datacite.org/prefixes/10.5061 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Headers: + - Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Access-Control-Max-Age: + - '1728000' + Cache-Control: + - max-age=0, private, must-revalidate + Content-Type: + - application/vnd.api+json; charset=utf-8 + Date: + - Wed, 12 Apr 2017 13:22:15 GMT + Etag: + - W/"1eb3f4f371821b1becc6cd25a71755ce" + Server: + - openresty/1.11.2.2 + Status: + - 200 OK + Vary: + - Accept-Encoding + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - SAMEORIGIN + X-Powered-By: + - Phusion Passenger 5.1.2 + X-Request-Id: + - f83743de-9777-4f36-af56-346d3e0ecb56 + X-Runtime: + - '0.272175' + X-Xss-Protection: + - 1; mode=block + Content-Length: + - '124' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: '{"data":{"id":"10.5061","type":"prefixes","attributes":{"registration-agency":"DataCite","updated":"2016-09-21T20:27:07Z"}}}' + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:15 GMT +- request: + method: get + uri: https://doi.org/10.5061/dryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 303 + message: '' + headers: + Server: + - Apache-Coyote/1.1 + Vary: + - Accept + Location: + - http://data.datacite.org/10.5061%2Fdryad.8515 + Expires: + - Wed, 12 Apr 2017 13:23:04 GMT + Content-Type: + - text/html;charset=utf-8 + Content-Length: + - '175' + Date: + - Wed, 12 Apr 2017 13:22:15 GMT + body: + encoding: UTF-8 + string: |- + Handle Redirect + http://data.datacite.org/10.5061%2Fdryad.8515 + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:16 GMT +- request: + method: get + uri: http://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 301 + message: '' + headers: + Content-Type: + - text/html + Date: + - Wed, 12 Apr 2017 13:22:16 GMT + Location: + - https://data.datacite.org/10.5061%2Fdryad.8515 + Server: + - openresty/1.11.2.2 + Content-Length: + - '191' + Connection: + - keep-alive + body: + encoding: UTF-8 + string: "\r\n301 Moved Permanently\r\n\r\n

301 Moved Permanently

\r\n
openresty/1.11.2.2
\r\n\r\n\r\n" + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:16 GMT +- request: + method: get + uri: https://data.datacite.org/10.5061%2Fdryad.8515 + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - Maremma - https://github.com/datacite/maremma + Accept: + - application/vnd.datacite.datacite+xml + response: + status: + code: 200 + message: '' + headers: + Access-Control-Allow-Methods: + - GET, POST, OPTIONS + Access-Control-Allow-Origin: + - "*" + Cache-Control: + - no-transform, max-age=3600 + Content-Type: + - application/vnd.datacite.datacite+xml + Date: + - Wed, 12 Apr 2017 13:22:16 GMT + Last-Modified: + - Sat, 04 Feb 2017 17:54:37 GMT + Server: + - openresty/1.11.2.2 + Vary: + - Accept + Content-Length: + - '2601' + Connection: + - keep-alive + body: + encoding: ASCII-8BIT + string: !binary |- + PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHJlc291 + cmNlIHhtbG5zPSJodHRwOi8vZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwt + MyIgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVt + YS1pbnN0YW5jZSIgeG1sbnM6bWV0cz0iaHR0cDovL3d3dy5sb2MuZ292L01F + VFMvIiB4bWxuczpkc3BhY2U9Imh0dHA6Ly93d3cuZHNwYWNlLm9yZy94bWxu + cy9kc3BhY2UvZGltIiB4bWxuczpkaW09Imh0dHA6Ly93d3cuZHNwYWNlLm9y + Zy94bWxucy9kc3BhY2UvZGltIiB4bWxuczpkcnlhZD0iaHR0cDovL3B1cmwu + b3JnL2RyeWFkL3Rlcm1zLyIgeHNpOnNjaGVtYUxvY2F0aW9uPSJodHRwOi8v + ZGF0YWNpdGUub3JnL3NjaGVtYS9rZXJuZWwtMyBodHRwOi8vc2NoZW1hLmRh + dGFjaXRlLm9yZy9tZXRhL2tlcm5lbC0zL21ldGFkYXRhLnhzZCI+ICA8aWRl + bnRpZmllciBpZGVudGlmaWVyVHlwZT0iRE9JIj4xMC41MDYxL0RSWUFELjg1 + MTU8L2lkZW50aWZpZXI+ICA8dmVyc2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CI+ + MTAuNTA2MS9EUllBRC44NTE1LzE8L3JlbGF0ZWRJZGVudGlmaWVyPiAgICA8 + cmVsYXRlZElkZW50aWZpZXIgcmVsYXRlZElkZW50aWZpZXJUeXBlPSJET0ki + IHJlbGF0aW9uVHlwZT0iSGFzUGFydCI+MTAuNTA2MS9EUllBRC44NTE1LzI8 + L3JlbGF0ZWRJZGVudGlmaWVyPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVs + YXRlZElkZW50aWZpZXJUeXBlPSJET0kiIHJlbGF0aW9uVHlwZT0iSXNSZWZl + cmVuY2VkQnkiPjEwLjEzNzEvSk9VUk5BTC5QUEFULjEwMDA0NDY8L3JlbGF0 + ZWRJZGVudGlmaWVyPiAgICA8cmVsYXRlZElkZW50aWZpZXIgcmVsYXRlZElk + ZW50aWZpZXJUeXBlPSJQTUlEIiByZWxhdGlvblR5cGU9IklzUmVmZXJlbmNl + ZEJ5Ij4xOTQ3ODg3NzwvcmVsYXRlZElkZW50aWZpZXI+ICA8L3JlbGF0ZWRJ + ZGVudGlmaWVycz4gIDxyaWdodHNMaXN0PiAgICA8cmlnaHRzIHJpZ2h0c1VS + ST0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvcHVibGljZG9tYWluL3pl + cm8vMS4wLyIvPiAgPC9yaWdodHNMaXN0PjwvcmVzb3VyY2U+ + http_version: + recorded_at: Wed, 12 Apr 2017 13:22:16 GMT +recorded_with: VCR 3.0.3 diff --git a/spec/heartbeat_spec.rb b/spec/heartbeat_spec.rb new file mode 100644 index 0000000..72c7193 --- /dev/null +++ b/spec/heartbeat_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe '/heartbeat' do + it "get heartbeat" do + get '/heartbeat' + + expect(last_response.status).to eq(200) + expect(last_response.body).to eq("OK") + end +end diff --git a/spec/helpers_spec.rb b/spec/helpers_spec.rb new file mode 100644 index 0000000..e32aa95 --- /dev/null +++ b/spec/helpers_spec.rb @@ -0,0 +1,89 @@ +require 'spec_helper' + +describe "Helpers", type: :model, vcr: true do + let(:fixture_path) { "#{Sinatra::Application.root}/spec/fixtures/" } + subject { ContentNegotiation.new } + + context "normalize_id" do + it "doi" do + id = subject.normalize_id("10.5061/DRYAD.8515") + expect(id).to eq("https://doi.org/10.5061/dryad.8515") + end + + it "http dx.doi.org" do + id = subject.normalize_id("http://dx.doi.org/10.5284/1015681") + expect(id).to eq("https://doi.org/10.5284/1015681") + end + end + + context "doi_from_url" do + it "url" do + doi = subject.doi_from_url("https://doi.org/10.5061/dryad.8515") + expect(doi).to eq("10.5061/dryad.8515") + end + + it "doi" do + doi = subject.doi_from_url("10.5061/dryad.8515") + expect(doi).to eq("10.5061/dryad.8515") + end + + it "not a doi" do + doi = subject.doi_from_url("https://doi.org/10.5061") + expect(doi).to be nil + end + end + + context "get_registered_content_types" do + it "present" do + content_types = subject.get_registered_content_types("https://doi.org/10.5284/1015681") + expect(content_types).to eq("application/pdf" => "http://archaeologydataservice.ac.uk/catalogue/adsdata/arch-1045-1/dissemination/pdf/356_ThewatertreatmentplantSaltersfordGrantham_Little.pdf") + end + + it "absent" do + content_types= subject.get_registered_content_types("https://doi.org/10.5061/dryad.8515") + expect(content_types).to be_empty + end + end + + context "redirect_by_content_type" do + it "registered content_type" do + id = "https://doi.org/10.5284/1015681" + accept_header = ["application/pdf"] + redirect_url = subject.redirect_by_content_type(id: id, accept_header: accept_header) + expect(redirect_url).to eq("http://archaeologydataservice.ac.uk/catalogue/adsdata/arch-1045-1/dissemination/pdf/356_ThewatertreatmentplantSaltersfordGrantham_Little.pdf") + end + + it "available content_type" do + id = "https://doi.org/10.5438/0000-0C2G" + accept_header = ["application/vnd.datacite.datacite+xml"] + redirect_url = subject.redirect_by_content_type(id: id, accept_header: accept_header) + expect(redirect_url).to eq("/content/application/vnd.datacite.datacite+xml/10.5438/0000-0c2g") + end + + it "citation" do + id = "https://doi.org/10.5438/0000-0C2G" + accept_header = ["text/x-bibliography; style=modern-language-association-8th-edition; locale=fr-FR"] + redirect_url = subject.should_redirect_citation(id: id, accept_header: accept_header) + expect(redirect_url).to eq("/content/application/vnd.datacite.datacite+xml/10.5438/0000-0c2g") + end + + it "unsupported content_type" do + id = "https://doi.org/10.5438/0000-0C2G" + accept_header = ["application/vnd.crossref.unixref+xml"] + redirect_url = subject.redirect_by_content_type(id: id, accept_header: accept_header) + expect(redirect_url).to eq("https://blog.datacite.org/oi-project-underway-for-open-org-id-registry/") + end + end + + context "should_pass_thru" do + it "doi" do + url = subject.should_pass_thru(id: "https://doi.org/10.5284/1015681") + expect(url).to eq("http://archaeologydataservice.ac.uk/archives/view/greylit/details.cfm?id=13979") + end + + it "no doi" do + url = subject.should_pass_thru(id: "http://archaeologydataservice.ac.uk/archives/view/greylit/details.cfm?id=13979") + expect(url).to be nil + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..6b33b1b --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,60 @@ +ENV['RACK_ENV'] = 'test' + +# set up Code Climate +require 'simplecov' +SimpleCov.start + +require 'sinatra' +require 'rspec' +require 'rack/test' +require 'webmock/rspec' +require 'vcr' + +require File.join(File.dirname(__FILE__), '..', 'app.rb') + +# require files in lib folder +Dir[File.join(File.dirname(__FILE__), '../lib/**/*.rb')].each { |f| require f } + +# setup test environment +set :environment, :test +set :run, false +set :raise_errors, true +set :logging, false +set :dump_errors, false +set :show_exceptions, false + +def app + Sinatra::Application +end + +RSpec.configure do |config| + config.include Rack::Test::Methods + config.order = :random +end + +WebMock.disable_net_connect!( + allow: ['codeclimate.com:443', ENV['PRIVATE_IP'], ENV['HOSTNAME']], + allow_localhost: true +) + +VCR.configure do |c| + c.cassette_library_dir = 'spec/fixtures/vcr_cassettes' + c.hook_into :webmock + c.ignore_localhost = true + c.ignore_hosts 'codeclimate.com' + c.filter_sensitive_data('') { ENV['ORCID_UPDATE_KEY'] } + c.filter_sensitive_data('') { ENV['ORCID_UPDATE_TOKEN'] } + c.allow_http_connections_when_no_cassette = false + c.configure_rspec_metadata! +end + +def capture_stdout(&block) + stdout, string = $stdout, StringIO.new + $stdout = string + + yield + + string.tap(&:rewind).read +ensure + $stdout = stdout +end diff --git a/vendor/docker/00_app_env.conf b/vendor/docker/00_app_env.conf new file mode 100644 index 0000000..c4a9494 --- /dev/null +++ b/vendor/docker/00_app_env.conf @@ -0,0 +1,2 @@ +# File will be overwritten if user runs the container with `-e PASSENGER_APP_ENV=...`! +passenger_app_env development; diff --git a/vendor/docker/cors.conf b/vendor/docker/cors.conf new file mode 100644 index 0000000..faaeffe --- /dev/null +++ b/vendor/docker/cors.conf @@ -0,0 +1,3 @@ +# enable CORS +more_set_headers 'Access-Control-Allow-Origin: *'; +more_set_headers 'Access-Control-Allow-Headers: Content-Type,Accept,Accept-Encoding,Origin,User-Agent,Cache-Control,Keep-Alive'; diff --git a/vendor/docker/ntp.conf b/vendor/docker/ntp.conf new file mode 100644 index 0000000..b075221 --- /dev/null +++ b/vendor/docker/ntp.conf @@ -0,0 +1,4 @@ +server 0.amazon.pool.ntp.org iburst +server 1.amazon.pool.ntp.org iburst +server 2.amazon.pool.ntp.org iburst +server 3.amazon.pool.ntp.org iburst diff --git a/vendor/docker/webapp.conf b/vendor/docker/webapp.conf new file mode 100644 index 0000000..fb67ac2 --- /dev/null +++ b/vendor/docker/webapp.conf @@ -0,0 +1,10 @@ +server { + listen 80 default_server; + server_name _; + root /home/app/webapp/public; + + passenger_enabled on; + passenger_user app; + passenger_ruby /usr/bin/ruby; + merge_slashes off; +}