Class: OpenehrRails::Opt::RemoteFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/openehr_rails/opt/remote_fetcher.rb

Overview

Fetches an OPT file over HTTP(S) (used for URL arguments to the scaffold/fhir_profile generators and the admin UI's URL-import field). Validates that the response actually parses as an operational template before handing it back, so callers never write garbage into app/templates/operational.

Defined Under Namespace

Classes: FetchError

Constant Summary collapse

MAX_REDIRECTS =
5
MAX_BODY_BYTES =
10 * 1024 * 1024
OPEN_TIMEOUT =
10
READ_TIMEOUT =
20
ALLOWED_SCHEMES =
%w[http https].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ RemoteFetcher

Returns a new instance of RemoteFetcher.



27
28
29
# File 'lib/openehr_rails/opt/remote_fetcher.rb', line 27

def initialize(url)
  @url = url
end

Class Method Details

.fetch(url) ⇒ Object



23
24
25
# File 'lib/openehr_rails/opt/remote_fetcher.rb', line 23

def self.fetch(url)
  new(url).fetch
end

Instance Method Details

#fetchObject



31
32
33
34
35
36
# File 'lib/openehr_rails/opt/remote_fetcher.rb', line 31

def fetch
  body = get(@url, MAX_REDIRECTS)
  validate_size!(body)
  validate_opt!(body)
  body
end