Class: SetupWizard

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

Overview

Setup wizard

Instance Method Summary collapse

Instance Method Details

#configure_jira_urlObject

Promts for the JIRA server url until user enters a valid value.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/setup_wizard.rb', line 36

def configure_jira_url
  loop do
    begin
      Configuration::ConfigurationManager
        .instance.update_jira_server_url prompt.ask("Please enter the JIRA Server URL:")
      break
    rescue LogworkException::InvalidURL
      Utilities.log("Invalid URL", { type: :error })
      # Break in case of rspec
      Utilities.rspec_running? && break
    end
  end
end

#configure_login_credentialsObject

Prompts for login credentials and executes login API call.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/setup_wizard.rb', line 84

def 
  # Clear saved cookie
  Utilities.remove_cookie

   = 
  Utilities.log("Trying to login...")
  session = Communication::SessionManager.new()
  session.(force: true) do
    Utilities.log("Success (#{session.myself[:full_name]}).", { type: :success })
  end
rescue LogworkException::InvalidCredentials
  Utilities.log("Invalid username or password.", { type: :error })
rescue LogworkException::APIResourceNotFound, LogworkException::NotSuccessStatusCode
  Utilities.log("Seems that you have entered an invalid JIRA Server URL.", { type: :error })
end

#configure_shift_endObject

Promts for shift end until user enters a valid value.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/setup_wizard.rb', line 67

def configure_shift_end
  loop do
    begin
      Configuration::ShiftConfiguration.new.update_shift_end(
        prompt.ask("What time is your shift finished? (24h format, e.g. 18:00):")
      )
      break
    rescue LogworkException::InvalidTime
      Utilities.log("Invalid time format", { type: :error })

      # Break in case of rspec
      Utilities.rspec_running? && break
    end
  end
end

#configure_shift_startObject

Promts for shift start until user enters a valid value.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/setup_wizard.rb', line 51

def configure_shift_start
  loop do
    begin
      Configuration::ShiftConfiguration.new.update_shift_start(
        prompt.ask("What time is your shift started? (24h format, e.g. 10:00):")
      )
      break
    rescue LogworkException::InvalidTime
      Utilities.log("Invalid time format", { type: :error })
      # Break in case of rspec
      Utilities.rspec_running? && break
    end
  end
end

#runObject



27
28
29
30
31
32
33
# File 'lib/setup_wizard.rb', line 27

def run
  Utilities.log("Welcome to jira-logwork configuration wizard.\n")
  configure_jira_url
  configure_shift_start
  configure_shift_end
  
end