Class: Relaton::Calconnect::DataFetcher
- Inherits:
-
Relaton::Core::DataFetcher
- Object
- Relaton::Core::DataFetcher
- Relaton::Calconnect::DataFetcher
- Defined in:
- lib/relaton/calconnect/data_fetcher.rb
Overview
Relaton-calconnect data fetcher
Constant Summary collapse
- ENDPOINT =
"https://standards.calconnect.org/cc/index.json"
Instance Method Summary collapse
- #agent ⇒ Object
- #etagfile ⇒ Object
-
#fetch(_source = nil) ⇒ Object
fetch data form server and save it to file.
- #index ⇒ Object
- #log_error(msg) ⇒ Object
Instance Method Details
#agent ⇒ Object
29 30 31 |
# File 'lib/relaton/calconnect/data_fetcher.rb', line 29 def agent @agent ||= Mechanize.new end |
#etagfile ⇒ Object
17 18 19 |
# File 'lib/relaton/calconnect/data_fetcher.rb', line 17 def etagfile @etagfile ||= File.join @output, "etag.txt" end |
#fetch(_source = nil) ⇒ Object
fetch data form server and save it to file.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/relaton/calconnect/data_fetcher.rb', line 36 def fetch(_source = nil) # rubocop:disable Metrics/AbcSize agent.request_headers["If-None-Match"] = etag if etag resp = agent.get(ENDPOINT) # 304 Not Modified — nothing changed since the last fetch return if resp.code == "304" data = JSON.parse resp.body all_success = true Array(data["documents"]).each { |doc| all_success &&= parse_page doc } self.etag = resp.response["etag"] if all_success index.save report_errors end |
#index ⇒ Object
21 22 23 |
# File 'lib/relaton/calconnect/data_fetcher.rb', line 21 def index @index = Relaton::Index.find_or_create :CC, file: "index-v1.yaml" end |
#log_error(msg) ⇒ Object
25 26 27 |
# File 'lib/relaton/calconnect/data_fetcher.rb', line 25 def log_error(msg) Util.error msg end |