class EL_WEB_ARCHIVE_HTTP_CONNECTION

(source code)

Client examples: HTTP_CONNECTION_TEST_SET

Description

Class to find archive URL in the Wayback Machine

note
	description: "Class to find archive URL in the Wayback Machine"

	author: "Finnian Reilly"
	copyright: "Copyright (c) 2001-2022 Finnian Reilly"
	contact: "finnian at eiffel hyphen loop dot com"

	license: "MIT license (See: en.wikipedia.org/wiki/MIT_License)"
	date: "2023-03-19 16:00:01 GMT (Sunday 19th March 2023)"
	revision: "10"

class
	EL_WEB_ARCHIVE_HTTP_CONNECTION

inherit
	EL_HTTP_CONNECTION
		export
			{NONE} all
		end

create
	make

feature -- Access

	wayback (a_url: STRING): EL_WAYBACK_CLOSEST
		local
			json_list: JSON_NAME_VALUE_LIST
		do
			Parameter_table [once "url"] := a_url
			open_with_parameters (Wayback_available_url, Parameter_table)
			read_string_get
			if has_error then
				create Result.make_default
			else
				create json_list.make (last_string)
				json_list.find_field (Param_url)
				if json_list.after then
					create Result.make_default
				else
					json_list.remove -- the first url field because the 2nd is the wayback one
					create Result.make (json_list)
				end
			end
			close
		end

feature -- Status query

	is_wayback_available (a_url: like url): BOOLEAN
			-- `True' is wayback is availabe for `a_url'
		do
			Result := wayback (a_url).available
		end

feature {NONE} -- Constants

	Parameter_table: HASH_TABLE [STRING, STRING]
		once
			create Result.make (1)
		end

	Param_url: STRING = "url"

	Wayback_available_url: STRING = "http://archive.org/wayback/available"

end