Class: Pilot::TesterExporter

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

Instance Attribute Summary

Attributes inherited from Manager

#config

Instance Method Summary collapse

Methods inherited from Manager

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

Instance Method Details

#export_testers(options) ⇒ Object



6
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
# File 'lib/pilot/tester_exporter.rb', line 6

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

  start(options)
  require 'csv'

  app_filter = (config[:apple_id] || config[:app_identifier])
  if app_filter
    app = Spaceship::Application.find(app_filter)
    testers = Spaceship::Tunes::Tester::External.all_by_app(app.apple_id)
  else
    testers = Spaceship::Tunes::Tester::External.all
  end

  file = config[:testers_file_path]

  CSV.open(file, "w") do |csv|
    csv << ['First', 'Last', 'Email', 'Devices', 'Groups', 'Installed Version', 'Install Date']

    testers.each do |tester|
      groups = tester.raw_data.get("groups")

      group_names = ""
      if groups && groups.length > 0
        names = groups.map { |group| group["name"]["value"] }
        group_names = names.join(';')
      end

      install_version = tester.full_version || ""
      pretty_date = tester.pretty_install_date || ""

      csv << [tester.first_name, tester.last_name, tester.email, tester.devices.count, group_names, install_version, pretty_date]
    end

    UI.success("Successfully exported CSV to #{file}")
  end
end