Skip to content

Commit

Permalink
support application/json-ld crosscite#98
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 25, 2020
1 parent 7b47260 commit 2b1e39a
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Mime::Type.register "application/vnd.crosscite.crosscite+json", :crosscite
Mime::Type.register "application/vnd.datacite.datacite+xml", :datacite, %w(application/x-datacite+xml)
Mime::Type.register "application/vnd.datacite.datacite+json", :datacite_json
Mime::Type.register "application/vnd.schemaorg.ld+json", :schema_org
Mime::Type.register "application/vnd.schemaorg.ld+json", :schema_org, %w(application/ld-json)
Mime::Type.register "application/vnd.jats+xml", :jats
Mime::Type.register "application/vnd.citationstyles.csl+json", :citeproc, %w(application/citeproc+json)
Mime::Type.register "application/vnd.codemeta.ld+json", :codemeta
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
get '/application/vnd.datacite.datacite+json/:id', :to => 'index#show', constraints: { :id => /.+/ }, defaults: { format: :datacite_json }
get '/application/vnd.crosscite.crosscite+json/:id', :to => 'index#show', constraints: { :id => /.+/ }, defaults: { format: :crosscite }
get '/application/vnd.schemaorg.ld+json/:id', :to => 'index#show', constraints: { :id => /.+/ }, defaults: { format: :schema_org }
get '/application/ld-json/:id', :to => 'index#show', constraints: { :id => /.+/ }, defaults: { format: :schema_org }
get '/application/vnd.codemeta.ld+json/:id', :to => 'index#show', constraints: { :id => /.+/ }, defaults: { format: :codemeta }
get '/application/vnd.citationstyles.csl+json/:id', :to => 'index#show', constraints: { :id => /.+/ }, defaults: { format: :citeproc }
get '/application/vnd.jats+xml/:id', :to => 'index#show', constraints: { :id => /.+/ }, defaults: { format: :jats }
Expand Down
36 changes: 36 additions & 0 deletions spec/api/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@
end
end

context "application/ld-json" do
it "header" do
get "/#{doi}", nil, { "HTTP_ACCEPT" => "application/ld-json" }

expect(last_response.status).to eq(200)
response = JSON.parse(last_response.body)
expect(response["@type"]).to eq("BlogPosting")
end

it "link" do
get "/application/ld-json/#{doi}"

expect(last_response.status).to eq(200)
response = JSON.parse(last_response.body)
expect(response["@type"]).to eq("BlogPosting")
end
end

context "application/vnd.citationstyles.csl+json" do
it "header" do
get "/#{doi}", nil, { "HTTP_ACCEPT" => "application/vnd.citationstyles.csl+json" }
Expand Down Expand Up @@ -394,6 +412,24 @@
end
end

context "application/ld-json" do
it "header" do
get "/#{doi}", nil, { "HTTP_ACCEPT" => "application/ld-json" }

expect(last_response.status).to eq(200)
response = JSON.parse(last_response.body)
expect(response["@type"]).to eq("ScholarlyArticle")
end

it "link" do
get "/application/ld-json/#{doi}"

expect(last_response.status).to eq(200)
response = JSON.parse(last_response.body)
expect(response["@type"]).to eq("ScholarlyArticle")
end
end

context "application/vnd.citationstyles.csl+json" do
it "header" do
get "/#{doi}", nil, { "HTTP_ACCEPT" => "application/vnd.citationstyles.csl+json" }
Expand Down
1 change: 1 addition & 0 deletions spec/concerns/helpable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"application/vnd.schemaorg.ld+json"=>:schema_org,
"application/vnd.citationstyles.csl+json"=>:citeproc,
"application/citeproc+json"=>:citeproc,
"application/ld-json" => :schema_org,
"application/vnd.codemeta.ld+json"=>:codemeta,
"application/x-bibtex" => :bibtex,
"application/x-research-info-systems"=>:ris,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 2b1e39a

Please sign in to comment.