Module: RelatonOgc::DataFetcher::Utils
- Included in:
- RelatonOgc::DataFetcher
- Defined in:
- lib/relaton_ogc/data_fetcher.rb
Constant Summary collapse
- ENDPOINT =
"https://raw.githubusercontent.com/opengeospatial/NamingAuthority/master/definitions/docs/docs.json"
Instance Method Summary collapse
-
#etag ⇒ String, NilClass
Read ETag form file.
-
#etag=(e_tag) ⇒ Object
Save ETag to file.
-
#get_data ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#etag ⇒ String, NilClass
Read ETag form file
25 26 27 28 29 |
# 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) ⇒ Object
Save ETag to file
35 36 37 |
# File 'lib/relaton_ogc/data_fetcher.rb', line 35 def etag=(e_tag) File.write @etagfile, e_tag, encoding: "UTF-8" end |
#get_data ⇒ Object
rubocop:disable Metrics/AbcSize
8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 |