Rename parsers to importers

This commit is contained in:
Eugene Burmakin 2025-04-23 23:36:16 +02:00
parent 411c999339
commit 07d00f189d
10 changed files with 22 additions and 27 deletions

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class Geojson::ImportParser
class Geojson::Importer
include Imports::Broadcaster
include PointValidation

View file

@ -1,11 +1,8 @@
# frozen_string_literal: true
class GoogleMaps::PhoneTakeoutParser
class GoogleMaps::PhoneTakeoutImporter
include Imports::Broadcaster
DOWNLOAD_TIMEOUT = 300 # 5 minutes timeout
MAX_RETRIES = 3
attr_reader :import, :user_id
def initialize(import, user_id)
@ -45,8 +42,6 @@ class GoogleMaps::PhoneTakeoutParser
def parse_json
# location-history.json could contain an array of data points
# or an object with semanticSegments, rawSignals and rawArray
# I guess there are no easy ways with Google since these two are
# 3rd and 4th formats of their location data exports
semantic_segments = []
raw_signals = []
raw_array = []

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class GoogleMaps::SemanticHistoryParser
class GoogleMaps::SemanticHistoryImporter
include Imports::Broadcaster
BATCH_SIZE = 1000

View file

@ -23,13 +23,13 @@ class Imports::Create
def parser(source)
# Bad classes naming by the way, they are not parsers, they are point creators
case source
when 'google_semantic_history' then GoogleMaps::SemanticHistoryParser
when 'google_phone_takeout' then GoogleMaps::PhoneTakeoutParser
when 'google_semantic_history' then GoogleMaps::SemanticHistoryImporter
when 'google_phone_takeout' then GoogleMaps::PhoneTakeoutImporter
when 'google_records' then GoogleMaps::RecordsStorageImporter
when 'owntracks' then OwnTracks::Importer
when 'gpx' then Gpx::TrackImporter
when 'geojson' then Geojson::ImportParser
when 'immich_api', 'photoprism_api' then Photos::ImportParser
when 'geojson' then Geojson::Importer
when 'immich_api', 'photoprism_api' then Photos::Importer
end
end

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class Photos::ImportParser
class Photos::Importer
include Imports::Broadcaster
include PointValidation
attr_reader :import, :user_id

View file

@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe Geojson::ImportParser do
RSpec.describe Geojson::Importer do
describe '#call' do
subject(:service) { described_class.new(import, user.id).call }

View file

@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe GoogleMaps::PhoneTakeoutParser do
RSpec.describe GoogleMaps::PhoneTakeoutImporter do
describe '#call' do
subject(:parser) { described_class.new(import, user.id).call }

View file

@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe GoogleMaps::SemanticHistoryParser do
RSpec.describe GoogleMaps::SemanticHistoryImporter do
describe '#call' do
subject(:parser) { described_class.new(import, user.id).call }

View file

@ -17,8 +17,8 @@ RSpec.describe Imports::Create do
content_type: 'application/json')
end
it 'calls the GoogleMaps::SemanticHistoryParser' do
expect(GoogleMaps::SemanticHistoryParser).to \
it 'calls the GoogleMaps::SemanticHistoryImporter' do
expect(GoogleMaps::SemanticHistoryImporter).to \
receive(:new).with(import, user.id).and_return(double(call: true))
service.call
end
@ -31,8 +31,8 @@ RSpec.describe Imports::Create do
context 'when source is google_phone_takeout' do
let(:import) { create(:import, source: 'google_phone_takeout') }
it 'calls the GoogleMaps::PhoneTakeoutParser' do
expect(GoogleMaps::PhoneTakeoutParser).to \
it 'calls the GoogleMaps::PhoneTakeoutImporter' do
expect(GoogleMaps::PhoneTakeoutImporter).to \
receive(:new).with(import, user.id).and_return(double(call: true))
service.call
end
@ -129,8 +129,8 @@ RSpec.describe Imports::Create do
context 'when source is geojson' do
let(:import) { create(:import, source: 'geojson') }
it 'calls the Geojson::ImportParser' do
expect(Geojson::ImportParser).to \
it 'calls the Geojson::Importer' do
expect(Geojson::Importer).to \
receive(:new).with(import, user.id).and_return(double(call: true))
service.call
end
@ -139,8 +139,8 @@ RSpec.describe Imports::Create do
context 'when source is immich_api' do
let(:import) { create(:import, source: 'immich_api') }
it 'calls the Photos::ImportParser' do
expect(Photos::ImportParser).to \
it 'calls the Photos::Importer' do
expect(Photos::Importer).to \
receive(:new).with(import, user.id).and_return(double(call: true))
service.call
end
@ -149,8 +149,8 @@ RSpec.describe Imports::Create do
context 'when source is photoprism_api' do
let(:import) { create(:import, source: 'photoprism_api') }
it 'calls the Photos::ImportParser' do
expect(Photos::ImportParser).to \
it 'calls the Photos::Importer' do
expect(Photos::Importer).to \
receive(:new).with(import, user.id).and_return(double(call: true))
service.call
end

View file

@ -2,7 +2,7 @@
require 'rails_helper'
RSpec.describe Photos::ImportParser do
RSpec.describe Photos::Importer do
describe '#call' do
subject(:service) { described_class.new(import, user.id).call }