diff --git a/datasources/connectors/datatourisme.rb b/datasources/connectors/datatourisme.rb index 6d39571..0025111 100644 --- a/datasources/connectors/datatourisme.rb +++ b/datasources/connectors/datatourisme.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true # typed: true -require 'async' require 'sorbet-runtime' require_relative 'connector' @@ -23,22 +22,6 @@ def setup(kiba) ] })) - DatatourismeSource.fetch("#{@settings['flow_key']}/#{@settings['key']}") - .select { |data| @source_filter.nil? || data.dig('type', 'value').start_with?(@source_filter) } - .group_by { |h| h.dig('type', 'value') } - .map do |key, data| - Async do - destination_id = "#{@job_id}-#{key.split('#').last}" - name = { 'fr' => 'Datatourisme' } - - kiba.source( - self.class.source_class, - @job_id, - destination_id, - name, - self.class.source_class.const_get(:Settings).from_hash(@settings.merge({ 'destination_id' => destination_id, 'datas' => data })), - ) - end - end.each(&:wait) + super end end diff --git a/datasources/sources/datatourisme.rb b/datasources/sources/datatourisme.rb index e81d83c..8a931c8 100644 --- a/datasources/sources/datatourisme.rb +++ b/datasources/sources/datatourisme.rb @@ -14,10 +14,8 @@ class DatatourismeSource < Source class Settings < Source::SourceSettings - const :key, String, name: 'key' # API key - const :flow_key, String, name: 'flow_key' # Flow key - const :destination_id, T.nilable(String), name: 'destination_id' # Destination ID - const :datas, T.nilable(T::Array[T::Hash[String, T.untyped]]), name: 'datas' # Datas + const :app_key, String + const :source_id, String end extend T::Generic @@ -27,7 +25,7 @@ def self.fetch(path) url = "https://diffuseur.datatourisme.fr/webservice/#{path}" response = HTTP.follow.get(url) - return [url, response].inspect unless response.status.success? + raise [url, response].inspect unless response.status.success? Set.new(JSON.parse( decompress_gzip(response.body.to_s) @@ -39,25 +37,17 @@ def self.decompress_gzip(data) end def each - if ENV['NO_DATA'] - [] - else - super(@settings.datas) - end + super(ENV['NO_DATA'] ? [] : self.class.fetch("#{@settings.source_id}/#{@settings.app_key}")) end def map_updated_at(feat) feat.dig('updated_at', 'value') end - def map_source(feat) + def map_destination_id(feat) feat.dig('type', 'value').split('#').last end - def map_destination_id(_feat) - @settings.destination_id - end - def map_geometry(feat) { type: 'Point', @@ -90,7 +80,7 @@ def map_id(feat) end end -# requête SPARQL pour récupérer les données de Datatourisme +# SPARQL query _sparql = <<~SPARQL PREFIX : PREFIX dc: diff --git a/tests/datatourisme/datatourimse_fetch_test.rb b/tests/datatourisme/datatourimse_fetch_test.rb index 5860f19..790248d 100644 --- a/tests/datatourisme/datatourimse_fetch_test.rb +++ b/tests/datatourisme/datatourimse_fetch_test.rb @@ -7,11 +7,11 @@ require_relative '../../datasources/sources/datatourisme' class TestDatatourismeFetch < Test::Unit::TestCase - @@api_key = ENV.fetch('DATATOURISME_API_KEY') - @@flow_key = ENV.fetch('DATATOURISME_FLOW_KEY') + @@app_key = ENV.fetch('DATATOURISME_API_KEY') + @@source_id = ENV.fetch('DATATOURISME_FLOW_KEY') def setup - @url = "https://diffuseur.datatourisme.fr/webservice/#{@@flow_key}/#{@@api_key}" + @url = "https://diffuseur.datatourisme.fr/webservice/#{@@source_id}/#{@@app_key}" end def test_datatourisme_fetch_headers @@ -22,7 +22,7 @@ def test_datatourisme_fetch_headers end def test_datatourisme_fetch_data - datas = DatatourismeSource.fetch("#{@@flow_key}/#{@@api_key}") + datas = DatatourismeSource.fetch("#{@@source_id}/#{@@app_key}") assert_not_nil(datas) assert_true(datas.is_a?(Array)) diff --git a/tests/datatourisme/datatourisme_settings_test.rb b/tests/datatourisme/datatourisme_settings_test.rb index 3597b98..8a9be03 100644 --- a/tests/datatourisme/datatourisme_settings_test.rb +++ b/tests/datatourisme/datatourisme_settings_test.rb @@ -5,16 +5,16 @@ class TestDatatourismeSettings < Test::Unit::TestCase def test_datatourisme_expected_settings - settings = DatatourismeSource::Settings.new({ key: 'key', flow_key: 'id', destination_id: 'id', datas: [] }) + settings = DatatourismeSource::Settings.new({ app_key: 'app_key', source_id: 'id' }) instance_vars = settings.instance_variables.map(&:to_s) - expected_vars = %w[@key @flow_key] + expected_vars = %w[@app_key @source_id] assert((expected_vars - instance_vars).empty?) end def test_datatourisme_with_unexpected_settings assert_raise(ArgumentError) do - DatatourismeSource::Settings.new({ key: 'key', flow_key: 'id', unexpected: 'unexpected' }) + DatatourismeSource::Settings.new({ app_key: 'app_key', source_id: 'id', unexpected: 'unexpected' }) end end