Sha256: 52e39a7d43b363d8e1e721423df8732b25469132aae90eda1adc3efcf47b0b64

Contents?: true

Size: 915 Bytes

Versions: 11

Compression:

Stored size: 915 Bytes

Contents

# frozen_string_literal: true

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_request_url = time_travel_base_url + first(:wayback_date).to_s + '/' + first(:url).to_s
      time_travel_request = URI(time_travel_request_url)
      time_travel_response = Net::HTTP.get(time_travel_request)
      if time_travel_response.present?
        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
      else
        replay_url = 'Not Available.'
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
warclight-0.9.0 app/models/concerns/warclight/solr_document.rb
warclight-0.8.3 app/models/concerns/warclight/solr_document.rb
warclight-0.8.2 app/models/concerns/warclight/solr_document.rb
warclight-0.8.1 app/models/concerns/warclight/solr_document.rb
warclight-0.8.0 app/models/concerns/warclight/solr_document.rb
warclight-0.7.1 app/models/concerns/warclight/solr_document.rb
warclight-0.7.0 app/models/concerns/warclight/solr_document.rb
warclight-0.6.3 app/models/concerns/warclight/solr_document.rb
warclight-0.6.2 app/models/concerns/warclight/solr_document.rb
warclight-0.6.1 app/models/concerns/warclight/solr_document.rb
warclight-0.6.0 app/models/concerns/warclight/solr_document.rb