Method: Codes::ItunesConnect#login

Defined in:
lib/codes/itunes_connect/itunes_connect_login.rb

#login(user = nil, password = nil) ⇒ bool

Loggs in a user with the given login data on the iTC Frontend. You don’t need to pass a username and password. It will Automatically be fetched using the CredentialsManager::PasswordManager. This method will also automatically be called when triggering other actions like #open_app_page

Parameters:

  • user (String) (defaults to: nil)

    (optional) The username/email address

  • password (String) (defaults to: nil)

    (optional) The password

Returns:

  • (bool)

    true if everything worked fine

Raises:



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
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/codes/itunes_connect/itunes_connect_login.rb', line 15

def (user = nil, password = nil)
  Helper.log.info "Logging into iTunesConnect"

  user ||= CredentialsManager::PasswordManager.shared_manager.username
  password ||= CredentialsManager::PasswordManager.shared_manager.password

  result = visit ITUNESCONNECT_URL
  raise "Could not open iTunesConnect" unless result['status'] == 'success'

  sleep 3

  if page.has_content? "My Apps"
    # Already logged in
    return true
  end

  begin
    wait_for_elements('#accountpassword')
  rescue
    # when the user is already logged in, this will raise an exception
  end

  fill_in "accountname", with: user
  fill_in "accountpassword", with: password

  begin
    page.evaluate_script "appleConnectForm.submit()"
    sleep 7

    if page.has_content? "My Apps"
      # Everything looks good
    else
      visit current_url # iTC sometimes is super buggy, try reloading the site
      sleep 3
      unless page.has_content? "My Apps"
        raise ItunesConnectLoginError.new("Looks like your login data was correct, but you do not have access to the apps.".red)
      end
    end
  rescue => ex
    Helper.log.debug(ex)
    raise ItunesConnectLoginError.new("Error logging in user #{user} with the given password. Make sure you entered them correctly.".red)
  end

  Helper.log.info "Successfully logged into iTunesConnect"

  true
rescue => ex
  error_occured(ex)
end