Skip to content

Commit

Permalink
Show purl endpoint
Browse files Browse the repository at this point in the history
This will allow purl to know whether an item should be crawlable or not
  • Loading branch information
jcoyne committed Apr 16, 2024
1 parent e8630ec commit 0d976c1
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 6 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,37 @@ rake rubocop

### Purls

#### `/purls/:druid`
#### GET `/purls/:druid`

`GET /purls/:druid`

##### Summary

Display a single purl

##### Description

The GET `/purls/:druid` endpoint provides the ability to display a PURL document. This endpoint is used by [purl](https://github.com/sul-dlss/purl/) to know if an item should be in the sitemap

##### Parameters

| Name | Located In | Description | Required | Schema | Default |
| --------- | ---------- | ------------------------------------------ | -------- | ------------------------------- | ------- |
| `druid` | url | Druid of a specific PURL | Yes | string eg(`druid:cc1111dd2222`) | null |
| `version` | header | Version of the API request eg(`version=1`) | No | integer | 1 |

##### Example Response

```json
{
"druid": "druid:dd111ee2222",
"latest_change": "2014-01-01T00:00:00Z",
"true_targets": ["PURL sitemap"],
"collections": ["druid:oo000oo0001"]
}
```

#### POST `/purls/:druid`

`POST /purls/:druid`

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def per_page_params

def druid_param
druid = params.require(:druid)
druid = "druid:#{druid}" unless druid.include?('druid:')
druid = "druid:#{druid}" unless druid.start_with?('druid:')
druid
end
end
6 changes: 6 additions & 0 deletions app/controllers/v1/purls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module V1
class PurlsController < ApplicationController
# Show the public json for the object. Used by purl to know if this object should be indexed by crawlers.
def show
purl = Purl.find_by(druid: druid_param)
render json: purl.as_public_json
end

##
# Update the database purl record from the passed in cocina
def update
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

resources :released, only: :show

resources :purls, only: [:destroy], param: :druid do
resources :purls, only: [:destroy, :show], param: :druid do
member do
post '/', action: 'update'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/purl.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryBot.define do
factory :purl do
sequence :druid do |n|
"druid:zz#{n.to_s * 3}yy#{n.to_s * 4}"
"druid:zz#{format('%03d', n)}yy0000"
end
published_at { 1.day.ago }
end
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/release_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
purl
name { 'Searchworks' }
release_type { true }

trait :sitemap do
name { 'PURL sitemap' }
end
end
end
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# https://relishapp.com/rspec/rspec-rails/docs
config.infer_spec_type_from_file_location!

config.fixture_paths = ["#{::Rails.root}/test/fixtures"]
config.fixture_paths = [Rails.root.join('test/fixtures')]

config.use_transactional_fixtures = true

Expand Down
13 changes: 13 additions & 0 deletions spec/requests/v1/purls_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
require 'rails_helper'

RSpec.describe V1::PurlsController do
describe 'GET show' do
let!(:release_tag) { create(:release_tag, :sitemap) }
let(:purl_object) { release_tag.purl }
let(:druid) { purl_object.druid }

it 'displays the purl data' do
get "/purls/#{druid}"

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include("true_targets" => ["PURL sitemap", "SearchWorksPreview", "ContentSearch"])
end
end

describe 'POST update' do
context 'with cocina json' do
before do
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/v1/released_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe V1::ReleasedController do
describe '#show' do
let!(:release_tag) { create(:release_tag, name: "PURL sitemap") }
let!(:release_tag) { create(:release_tag, :sitemap) }
let(:purl) { release_tag.purl }

it 'returns list of druids' do
Expand Down

0 comments on commit 0d976c1

Please sign in to comment.