parse_caller.rb revision 511ba3e3d7deb4a13a03ce522a99a0395acc61b7
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenmodule Hets
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen class ParseCaller < Caller
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # Server-Instances should be started with the following
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen # arguments: `hets +RTS -K1G -RTS -a none`
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen MODE_ARGUMENTS = {
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen fast_run: %w(just-structured),
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen default: %w(full-signatures full-theories)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen }
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainen CMD = 'dg'
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen METHOD = :get
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen attr_accessor :url_catalog
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen def initialize(hets_instance, url_catalog = [])
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen self.url_catalog = url_catalog
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen msg = "<#{hets_instance}> not up."
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen raise Hets::InactiveInstanceError, msg unless hets_instance.up?
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen super(hets_instance)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen end
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen def call(iri, with_mode: :default)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen escaped_iri = Rack::Utils.escape_path(iri)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen arguments = [escaped_iri, *MODE_ARGUMENTS[with_mode]]
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen api_uri = build_api_uri(CMD, arguments, build_query_string)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen perform(api_uri, METHOD)
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen end
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen def build_query_string
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen query_hash = {}
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen query_hash[:"url-catalog"] = url_catalog.join(',') if url_catalog.present?
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen end
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen end
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainenend
2a34e2be33f8a17d21384a5527ed9f75f4d270e0Timo Sirainen