Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
104 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Cocina | ||
# A digital repository object. See https://github.com/sul-dlss-labs/taco/blob/master/maps/DRO.json | ||
class DRO < Dry::Struct | ||
attribute :externalIdentifier, Types::Strict::String | ||
attribute :type, Types::Strict::String | ||
attribute :label, Types::Strict::String | ||
|
||
def as_json(*) | ||
{ | ||
externalIdentifier: externalIdentifier, | ||
type: type, | ||
label: label | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Cocina | ||
# This defines the data types supported by the model | ||
module Types | ||
include Dry.Types() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module Cocina | ||
# Maps Dor::Items to Cocina objects | ||
class Mapper | ||
def self.build(item) | ||
new(item).build | ||
end | ||
|
||
def initialize(item) | ||
@item = item | ||
end | ||
|
||
def build | ||
Cocina::DRO.new(externalIdentifier: item.pid, | ||
type: type, | ||
label: item.label) | ||
end | ||
|
||
private | ||
|
||
attr_reader :item | ||
|
||
# @todo This should have more speicific type such as found in identityMetadata.objectType | ||
def type | ||
case item | ||
when Dor::Item | ||
'object' | ||
when Dor::Collection | ||
'collection' | ||
else | ||
raise "Unknown type for #{item.class}" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Get the object' do | ||
let(:payload) { { sub: 'argo' } } | ||
let(:jwt) { JWT.encode(payload, Settings.dor.hmac_secret, 'HS256') } | ||
let(:basic_auth) { ActionController::HttpAuthentication::Basic.encode_credentials(user, password) } | ||
let(:object) { Dor::Item.new(pid: 'druid:1234') } | ||
|
||
before do | ||
object.descMetadata.title_info.main_title = 'Hello' | ||
object.label = 'foo' | ||
allow(Dor).to receive(:find).and_return(object) | ||
end | ||
|
||
it 'returns the object' do | ||
get '/v1/objects/druid:mk420bs7601', | ||
headers: { 'X-Auth' => "Bearer #{jwt}" } | ||
expect(response).to be_successful | ||
expect(response.body).to eq '{"externalIdentifier":"druid:1234","type":"object","label":"foo"}' | ||
end | ||
end |