module RelatonOgc::DataFetcher::Utils

Constants

ENDPOINT

Public Instance Methods

etag() click to toggle source

Read ETag form file

@return [String, NilClass]

# File lib/relaton_ogc/data_fetcher.rb, line 25
def etag
  @etag ||= if File.exist? @etagfile
              File.read @etagfile, encoding: "UTF-8"
            end
end
etag=(e_tag) click to toggle source

Save ETag to file

@param tag [String]

# File lib/relaton_ogc/data_fetcher.rb, line 35
def etag=(e_tag)
  File.write @etagfile, e_tag, encoding: "UTF-8"
end
get_data() { |resp, json| ... } click to toggle source
# File lib/relaton_ogc/data_fetcher.rb, line 8
def get_data # rubocop:disable Metrics/AbcSize
  h = {}
  h["If-None-Match"] = etag if etag
  resp = Faraday.new(ENDPOINT, headers: h).get
  case resp.status
  when 200
    json = JSON.parse(resp.body)
    block_given? ? yield(resp[:etag], json) : json
  when 304 then [] # there aren't any changes since last fetching
  else raise RelatonBib::RequestError, "Could not access #{ENDPOINT}"
  end
end