Class: Dmarcurator::ImportReports

Inherits:
Object
  • Object
show all
Defined in:
lib/dmarcurator/import_reports.rb

Overview

Import DMARC XML reports into DB

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db_uri:, reports_path:) ⇒ ImportReports

Returns a new instance of ImportReports.



9
10
11
12
# File 'lib/dmarcurator/import_reports.rb', line 9

def initialize(db_uri:, reports_path:)
  @db = Sequel.connect(db_uri)
  @reports_path = reports_path
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



7
8
9
# File 'lib/dmarcurator/import_reports.rb', line 7

def db
  @db
end

#reports_pathObject (readonly)

Returns the value of attribute reports_path.



7
8
9
# File 'lib/dmarcurator/import_reports.rb', line 7

def reports_path
  @reports_path
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/dmarcurator/import_reports.rb', line 14

def run
  puts "Importing #{reports_path}"
  Dir.foreach(reports_path) do |path|
    next if path == '.' || path == '..' || File.extname(path) != ".xml"
    puts "  #{path}"
    parsed_report = ::Dmarcurator::Parser::Report.new(xml: "#{reports_path}/#{path}")
    ::Dmarcurator::Store::Report.import_parsed(db: db, parsed: parsed_report)
  end
  puts "Done importing :)"
end