Class: Fastlane::Firebase::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/firebase/lib/manager.rb

Instance Method Summary collapse

Instance Method Details

#login(username) ⇒ Object



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/fastlane/plugin/firebase/lib/manager.rb', line 10

def (username)
  item = Security::InternetPassword.find(server: server_name(), account: username)
     keychain_password = item.password if item

     password = keychain_password
     begin 
       password = UI.password("Password for #{username}") unless password
       
       #Api instance
       @api = Firebase::Api.new(username, password)
       
       #Store password
       Security::InternetPassword.add(server_name(), username, password) unless keychain_password == password

       @api
     rescue Firebase::Api::LoginError => e
       UI.error e.message

       if UI.confirm "Do you want to re-enter your password?" then
        password = nil
         if keychain_password then
           puts "Removing Keychain entry for user '#{username}'...".yellow
           Security::InternetPassword.delete(server: server_name(), account: username)
         end
         keychain_password = nil
         retry
       end
     end
end

#select_client(project, client_id) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fastlane/plugin/firebase/lib/manager.rb', line 56

def select_client(project, client_id)
  if project["clientSummary"] == nil then
    UI.user_error! "Project has no clients"
    return
  end

  clients = (project["clientSummary"] || []).sort {|left, right| left["clientId"] <=> right["clientId"] }

  if client = clients.select {|c| c["clientId"] == client_id }.first then
    client
  else
    options = clients.map { |p| "#{p["clientId"]} (#{p["displayName"]})" }
    index = select_index("Select client:", options)
    clients[index]
 end
end

#select_index(text, options) ⇒ Object



73
74
75
76
# File 'lib/fastlane/plugin/firebase/lib/manager.rb', line 73

def select_index(text, options)
  selected = UI.select(text, options)
  return options.index(selected)
end

#select_project(project_number) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fastlane/plugin/firebase/lib/manager.rb', line 40

def select_project(project_number)
        projects = @api.project_list()
  if projects.count == 0 then
    UI.user_error! "No projects exist under the account"
    return
  end

        if project = projects.select {|p| p["projectNumber"] == project_number }.first then
          project
        else 
    options = projects.map { |p| p["displayName"] }
    index = select_index("Select project:", options)
    projects[index]
  end
end

#server_nameObject



6
7
8
# File 'lib/fastlane/plugin/firebase/lib/manager.rb', line 6

def server_name
  "firebase.google.com"
end