This repository has been archived by the owner on May 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Adding holding location backed by bibdata location service - closes #389 #394
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class HoldingLocationAuthority | ||
include Qa::Authorities::WebServiceBase | ||
|
||
def all | ||
get_json(url).each { |loc| loc['id'] = loc['url'].sub(/\.json$/, '') } | ||
end | ||
|
||
def find(id) | ||
(all.select { |obj| obj['id'] == id } || []).first | ||
end | ||
|
||
private | ||
|
||
def url | ||
Plum.config['locations_url'] | ||
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
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,13 @@ | ||
class HoldingLocationRenderer < CurationConcerns::AttributeRenderer | ||
def initialize(value, options = {}) | ||
super(:location, value, options) | ||
end | ||
|
||
private | ||
|
||
def attribute_value_to_html(value) | ||
loc = HoldingLocationService.find(value) | ||
li_value %(#{loc.label}<br/>Contact at <a href="mailto:#{loc.email}">#{loc.email}</a>, | ||
<a href="tel:#{loc.phone}">#{loc.phone}</a>) | ||
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,30 @@ | ||
module HoldingLocationService | ||
mattr_accessor :authority | ||
self.authority = HoldingLocationAuthority.new | ||
|
||
def self.select_options | ||
authority.all.map { |element| [element['label'], element['id']] }.sort | ||
end | ||
|
||
def self.find(id) | ||
HoldingLocation.new(authority.find(id)) | ||
end | ||
|
||
class HoldingLocation | ||
def initialize(hash) | ||
@holding_location = hash || {} | ||
end | ||
|
||
def email | ||
@holding_location['contact_email'] | ||
end | ||
|
||
def label | ||
@holding_location['label'] | ||
end | ||
|
||
def phone | ||
@holding_location['phone_number'] | ||
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
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,43 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe HoldingLocationAuthority do | ||
subject { described_class.new } | ||
let(:json) { | ||
'[{ | ||
"label":"Plasma Physics Library", | ||
"phone_number":"609-243-3565", | ||
"contact_email":"ppllib@princeton.edu", | ||
"url":"https://bibdata.princeton.edu/locations/delivery_locations/1.json" | ||
},{ | ||
"label":"Architecture Library", | ||
"phone_number":"609-258-3256", | ||
"contact_email":"ues@princeton.edu", | ||
"url":"https://bibdata.princeton.edu/locations/delivery_locations/3.json" | ||
}]' | ||
} | ||
let(:id) { 'https://bibdata.princeton.edu/locations/delivery_locations/3' } | ||
let(:obj) { | ||
{ | ||
label: "Architecture Library", | ||
phone_number: "609-258-3256", | ||
contact_email: "ues@princeton.edu", | ||
url: "https://bibdata.princeton.edu/locations/delivery_locations/3.json", | ||
id: "https://bibdata.princeton.edu/locations/delivery_locations/3" | ||
} | ||
} | ||
|
||
before do | ||
allow(RestClient).to receive(:get).and_return(json) | ||
end | ||
|
||
context "with data" do | ||
it "finds a holding location by id" do | ||
expect(subject.find(id)).to eq(obj.stringify_keys) | ||
end | ||
|
||
it "lists all of the holding locations" do | ||
expect(subject.all.length).to eq(2) | ||
expect(subject.all).to include(obj.stringify_keys) | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more efficient to change the API to
location_service = HoldingLocationService.new(value)
(or .find), and then have instance methods for email/label/phone?