Class: Pilot::TesterImporter

Inherits:
Manager
  • Object
show all
Defined in:
pilot/lib/pilot/tester_importer.rb

Instance Attribute Summary

Attributes inherited from Manager

#config

Instance Method Summary collapse

Methods inherited from Manager

#app, #fetch_app_id, #fetch_app_identifier, #fetch_app_platform, #login, #start

Instance Method Details

#import_testers(options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'pilot/lib/pilot/tester_importer.rb', line 7

def import_testers(options)
  UI.user_error!("Import file path is required") unless options[:testers_file_path]

  start(options)

  require 'csv'

  file = config[:testers_file_path]
  tester_manager = Pilot::TesterManager.new
  imported_tester_count = 0

  groups = options[:groups]

  CSV.foreach(file, "r") do |row|
    first_name, last_name, email, testing_groups = row

    unless email
      UI.error("No email found in row: #{row}")
      next
    end

    unless email.index("@")
      UI.error("No email found in row: #{row}")
      next
    end

    # Add this the existing config hash to pass it to the TesterManager
    config[:first_name] = first_name
    config[:last_name] = last_name
    config[:email] = email
    config[:groups] = groups
    if testing_groups
      config[:groups] = testing_groups.split(";")
    end

    begin
      tester_manager.add_tester(config)
      imported_tester_count += 1
    rescue => exception
      UI.error("Error adding tester #{email}: #{exception}")
    end
  end

  UI.success("Successfully imported #{imported_tester_count} testers from #{file}")
end