Class: Pilot::TesterManager

Inherits:
Manager
  • Object
show all
Defined in:
lib/pilot/tester_manager.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

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

def add_tester(options)
  start(options)

  begin
    tester = Spaceship::Tunes::Tester::Internal.find(config[:email])
    tester ||= Spaceship::Tunes::Tester::External.find(config[:email])

    if tester
      UI.success("Existing tester #{tester.email}")
    else
      tester = Spaceship::Tunes::Tester::External.create!(email: config[:email],
                                                          first_name: config[:first_name],
                                                          last_name: config[:last_name])
      UI.success("Successfully invited tester: #{tester.email}")
    end

    app_filter = (config[:apple_id] || config[:app_identifier])
    if app_filter
      begin
        app = Spaceship::Application.find(app_filter)
        UI.user_error!("Couldn't find app with '#{app_filter}'") unless app
        tester.add_to_app!(app.apple_id)
        UI.success("Successfully added tester to app #{app_filter}")
      rescue => ex
        UI.error("Could not add #{tester.email} to app: #{ex}")
        raise ex
      end
    end
  rescue => ex
    UI.error("Could not create tester #{config[:email]}")
    raise ex
  end
end

#find_tester(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/pilot/tester_manager.rb', line 40

def find_tester(options)
  start(options)

  tester = Spaceship::Tunes::Tester::Internal.find(config[:email])
  tester ||= Spaceship::Tunes::Tester::External.find(config[:email])

  UI.user_error!("Tester #{config[:email]} not found") unless tester

  describe_tester(tester)
  return tester
end

#list_testers(options) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/pilot/tester_manager.rb', line 79

def list_testers(options)
  start(options)
  require 'terminal-table'

  app_filter = (config[:apple_id] || config[:app_identifier])
  if app_filter
    app = Spaceship::Application.find(app_filter)
    UI.user_error!("Couldn't find app with '#{app_filter}'") unless app
    int_testers = Spaceship::Tunes::Tester::Internal.all_by_app(app.apple_id)
    ext_testers = Spaceship::Tunes::Tester::External.all_by_app(app.apple_id)
  else
    int_testers = Spaceship::Tunes::Tester::Internal.all
    ext_testers = Spaceship::Tunes::Tester::External.all
  end

  list(int_testers, "Internal Testers")
  puts "" # new line
  list(ext_testers, "External Testers")
end

#remove_tester(options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/pilot/tester_manager.rb', line 52

def remove_tester(options)
  start(options)

  tester = Spaceship::Tunes::Tester::External.find(config[:email])
  tester ||= Spaceship::Tunes::Tester::Internal.find(config[:email])

  if tester
    app_filter = (config[:apple_id] || config[:app_identifier])
    if app_filter
      begin
        app = Spaceship::Application.find(app_filter)
        UI.user_error!("Couldn't find app with '#{app_filter}'") unless app
        tester.remove_from_app!(app.apple_id)
        UI.success("Successfully removed tester #{tester.email} from app #{app_filter}")
      rescue => ex
        UI.error("Could not remove #{tester.email} from app: #{ex}")
        raise ex
      end
    else
      tester.delete!
      UI.success("Successfully removed tester #{tester.email}")
    end
  else
    UI.error("Tester not found: #{config[:email]}")
  end
end