Class: Jekyll::ArchiveLink::URL
- Inherits:
-
Object
- Object
- Jekyll::ArchiveLink::URL
- Defined in:
- lib/jekyll/archive_link/url.rb
Constant Summary collapse
- ARCHIVE_HOST =
"https://web.archive.org"
- API_URI =
"wayback/available?url=%<url>s"
- API_BASE =
"https://archive.org"
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Returns the value of attribute api_client.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url, api_client: self.class.api_client) ⇒ URL
constructor
A new instance of URL.
-
#latest_archive_url ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(url, api_client: self.class.api_client) ⇒ URL
Returns a new instance of URL.
31 32 33 34 35 |
# File 'lib/jekyll/archive_link/url.rb', line 31 def initialize(url, api_client: self.class.api_client) Jekyll::ArchiveLink.debug("Initialize URL with #{url}") @api_client = api_client @url = url end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Returns the value of attribute api_client.
14 15 16 |
# File 'lib/jekyll/archive_link/url.rb', line 14 def api_client @api_client end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
14 15 16 |
# File 'lib/jekyll/archive_link/url.rb', line 14 def url @url end |
Class Method Details
.api_client ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll/archive_link/url.rb', line 18 def api_client @api_client ||= Faraday.new(API_BASE) do |config| config.request(:json) config.response(:json) config.response :logger, Jekyll::ArchiveLink.logger config.use :http_cache, store: Jekyll::ArchiveLink::TmpDirCache.new, serializer: JSON end end |
Instance Method Details
#latest_archive_url ⇒ Object
rubocop:disable Metrics/MethodLength
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jekyll/archive_link/url.rb', line 38 def latest_archive_url Jekyll::ArchiveLink.debug("latest_archive_url") if url.empty? Jekyll::ArchiveLink.debug("URL is blank") return "" end unless URI.parse(url).is_a?(URI::HTTP) raise InvalidURL, "#{url} doesn't look like an archiveable URL" end if url.start_with?(ARCHIVE_HOST) Jekyll::ArchiveLink.debug("URL is already an archive link: #{url}") return url end memento_location end |