Class: Relaton::Iec::DataFetcher

Inherits:
Core::DataFetcher
  • Object
show all
Defined in:
lib/relaton/iec/data_fetcher.rb

Constant Summary collapse

ENTRYPOINT =
"https://api.iec.ch/harmonized/publications?size=100&sortBy=urn&page=".freeze
CREDENTIAL =
"https://api.iec.ch/oauth/client_credential/accesstoken?grant_type=client_credentials".freeze
LAST_CHANGE_FILE =
"last_change.txt".freeze

Instance Method Summary collapse

Instance Method Details

#fetch(source = "iec-harmonised-latest") ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/relaton/iec/data_fetcher.rb', line 19

def fetch(source = "iec-harmonised-latest") # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  @all = source == "iec-harmonised-all"

  if @all
    FileUtils.rm_rf @output
  end
  FileUtils.mkdir_p @output
  rebuild_index
  fetch_all
  index.save
  save_last_change
  report_errors
rescue StandardError => e
  Util.error do
    "#{e.message}\n#{e.backtrace.join("\n")}"
  end
end

#log_error(msg) ⇒ Object

Fetch data from IEC.



15
16
17
# File 'lib/relaton/iec/data_fetcher.rb', line 15

def log_error(msg)
  Util.error msg
end