Class: Fastlane::FirebaseManagementApi::Manager
- Inherits:
-
Object
- Object
- Fastlane::FirebaseManagementApi::Manager
- Defined in:
- lib/fastlane/plugin/firebase_management_api/lib/manager.rb
Instance Method Summary collapse
- #select_app(project_id, app_id, type) ⇒ Object
- #select_index(text, options) ⇒ Object
- #select_project(project_id) ⇒ Object
- #serviceAccountLogin(jsonPath) ⇒ Object
- #userLogin(email, client_secrets_path) ⇒ Object
Instance Method Details
#select_app(project_id, app_id, type) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fastlane/plugin/firebase_management_api/lib/manager.rb', line 68 def select_app(project_id, app_id, type) case type when :ios apps = @api.ios_app_list(project_id) when :android apps = @api.android_app_list(project_id) end if apps.empty? then UI.user_error! "Project has no #{type} apps" return end apps = apps.sort {|left, right| left["appId"] <=> right["appId"] } if app = apps.select {|a| a["appId"] == app_id }.first then app else = apps.map { |a| "#{a["displayName"] || a["bundleId"] || a["packageName"]} (#{a["appId"]})" } index = select_index("Select app:", ) apps[index] end end |
#select_index(text, options) ⇒ Object
93 94 95 96 |
# File 'lib/fastlane/plugin/firebase_management_api/lib/manager.rb', line 93 def select_index(text, ) selected = UI.select(text, ) return .index(selected) end |
#select_project(project_id) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fastlane/plugin/firebase_management_api/lib/manager.rb', line 50 def select_project(project_id) 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["projectId"] == project_id }.first then project else = projects.map { |p| "#{p["displayName"]} (#{p["projectId"]})" } index = select_index("Select project:", ) projects[index] end end |
#serviceAccountLogin(jsonPath) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fastlane/plugin/firebase_management_api/lib/manager.rb', line 37 def serviceAccountLogin(jsonPath) scope = 'https://www.googleapis.com/auth/firebase https://www.googleapis.com/auth/cloud-platform' = Google::Auth::ServiceAccountCredentials.make_creds( json_key_io: File.open(jsonPath), scope: scope ) token = .fetch_access_token!["access_token"] @api = FirebaseManagementApi::Api.new(token) @api end |
#userLogin(email, client_secrets_path) ⇒ Object
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 |
# File 'lib/fastlane/plugin/firebase_management_api/lib/manager.rb', line 8 def userLogin(email, client_secrets_path) system 'mkdir -p ~/.google' oob_uri = "urn:ietf:wg:oauth:2.0:oob" scopes = [ 'https://www.googleapis.com/auth/firebase', 'https://www.googleapis.com/auth/cloud-platform' ] client_id = Google::Auth::ClientId.from_file(client_secrets_path) token_store = Google::Auth::Stores::FileTokenStore.new(:file => File.("~/.google/tokens.yaml")) = Google::Auth::UserAuthorizer.new(client_id, scopes, token_store) credentials = .get_credentials(email) if credentials.nil? url = .(base_url: oob_uri) UI. "Open #{url} in your browser and enter the resulting code." code = Fastlane::Actions::PromptAction.run(text: "Code: ") credentials = .get_and_store_credentials_from_code(user_id: email, code: code, base_url: oob_uri) end token = credentials.fetch_access_token!["access_token"] @api = FirebaseManagementApi::Api.new(token) @api end |