parse_caller.rb revision b09fc223dca021e237ba12a84e4527bf87f26cd1
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozekmodule Hets
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek class ParseCaller < Caller
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek # Server-Instances should be started with the following
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek # arguments: `hets +RTS -K1G -RTS -a none`
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek MODE_ARGUMENTS = {
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek fast_run: %w(just-structured),
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek default: %w(full-signatures full-theories auto),
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek }
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek CMD = 'dg'
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek METHOD = :get
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek attr_accessor :url_catalog
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek def initialize(hets_instance, url_catalog = [])
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek self.url_catalog = url_catalog
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek msg = "<#{hets_instance}> not up."
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek raise Hets::InactiveInstanceError, msg unless hets_instance.try(:up?)
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek super(hets_instance)
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek end
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek def call(iri, with_mode: :default)
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek escaped_iri = Rack::Utils.escape_path(iri)
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek arguments = [escaped_iri, *MODE_ARGUMENTS[with_mode]]
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek api_uri = build_api_uri(CMD, arguments, build_query_string)
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek perform(api_uri, METHOD)
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek rescue UnfollowableResponseError => error
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek handle_possible_hets_error(error)
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek end
27e89b6925334565c73c407a9ae2809358789c81Jakub Hrozek
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek def build_query_string
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek query_hash = {}
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek query_hash[:"url-catalog"] = url_catalog.join(',') if url_catalog.present?
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek query_hash
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek end
05d935cc9d04f03522d0bb44598d22d99b085926Jakub Hrozek
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek def handle_possible_hets_error(error)
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek HetsErrorProcess.new(error).handle
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek rescue Hets::NotAHetsError
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek raise error
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek end
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek end
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozekend
64ea4127f463798410a2c20e0261c6b15f60257fJakub Hrozek