Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Add Replay link; Resolves #19 (#35)
Browse files Browse the repository at this point in the history
* Create an accessor that uses to Solr fields to query Time Travel API
* Display accessor as a field
* Create a test
* Update Rubocop to ignore somethings; TODO create tickets, and come back to this later
  • Loading branch information
ruebot authored and ianmilligan1 committed Oct 18, 2017
1 parent cfe500a commit bd65cd8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Metrics/LineLength:
Max: 120
Exclude:
- 'Gemfile'
- 'spec/models/concerns/warclight/solr_document_spec.rb'

Metrics/ModuleLength:
Max: 120
Expand All @@ -34,12 +35,17 @@ Metrics/BlockLength:
- 'spec/**/*'
- 'lib/warclight/custom_document.rb'

Metrics/AbcSize:
Exclude:
- 'app/models/concerns/warclight/solr_document.rb' #Come back to this later

Performance/RegexpMatch:
Enabled: false

Rails/OutputSafety:
Exclude:
- 'app/controllers/concerns/warclight/field_config_helpers.rb' # html_safe needs to be called to mimic BL JOIN behavior
- 'app/models/concerns/warclight/solr_document.rb'

RSpec/ExampleLength:
Enabled: false
Expand All @@ -50,6 +56,10 @@ RSpec/MultipleExpectations:
RSpec/NestedGroups:
Max: 4

Rails/TimeZone:
Exclude:
- 'app/models/concerns/warclight/solr_document.rb' #Come back to this later

Style/Documentation:
Exclude:
- 'spec/**/*'
Expand Down
13 changes: 13 additions & 0 deletions app/models/concerns/warclight/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,18 @@ module Warclight
# Extends Blacklight::Solr::Document to provide Warclight specific behavior
module SolrDocument
extend Blacklight::Solr::Document

def replay_link
time_travel_base_url = 'http://timetravel.mementoweb.org/api/json/'
time_travel_time_format = '%Y%m%d%H%M%S'
time_travel_time = (Time.parse(first(:crawl_date)).strftime time_travel_time_format).to_s
time_travel_request_url = time_travel_base_url + time_travel_time + '/' + first(:url).to_s
time_travel_request = URI(time_travel_request_url)
time_travel_response = Net::HTTP.get(time_travel_request)
time_travel_response_json = JSON.parse(time_travel_response)
replay_url = time_travel_response_json['mementos']['closest']['uri'][0]
replay_url_link = '<a href="' + "#{replay_url}" '" target="_blank">'"#{replay_url}"'</a> 🔗'
replay_url_link.html_safe
end
end
end
1 change: 1 addition & 0 deletions lib/generators/warclight/templates/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CatalogController < ApplicationController
# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
config.add_show_field 'url', label: 'URL', helper_method: :url_to_link
config.add_show_field 'replay_url', label: 'Replay URL', accessor: :replay_link
config.add_show_field 'resourcename', label: 'Resource Name', link_to_facet: true
config.add_show_field 'host', label: 'Host', link_to_facet: true
config.add_show_field 'institution', label: 'Institution', link_to_facet: true
Expand Down
17 changes: 17 additions & 0 deletions spec/models/concerns/warclight/solr_document_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Warclight::SolrDocument do
let(:document) { SolrDocument.new }

describe '#replay_link' do
let(:document) do
SolrDocument.new(crawl_date: '2015-01-13T16:36:01Z', url: 'http://www.library.yorku.ca/cms/steacie/about-the-library/hackfest/')
end

it 'writes a replay url based on memento time travel response' do
expect(document.replay_link).to eq '<a href="https://digital.library.yorku.ca/wayback/20150113163601/http://www.library.yorku.ca/cms/steacie/about-the-library/hackfest/" target="_blank">https://digital.library.yorku.ca/wayback/20150113163601/http://www.library.yorku.ca/cms/steacie/about-the-library/hackfest/</a> 🔗'
end
end
end

0 comments on commit bd65cd8

Please sign in to comment.