GetProjectConfigResponse.swift 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. @objc(FIRGetProjectConfigResponse) public class GetProjectConfigResponse: NSObject,
  16. AuthRPCResponse {
  17. /** @property projectID
  18. @brief The unique ID pertaining to the current project.
  19. */
  20. @objc public var projectID: String?
  21. /** @property authorizedDomains
  22. @brief A list of domains allowlisted for the current project.
  23. */
  24. @objc public var authorizedDomains: [String]?
  25. public func setFields(dictionary: [String: AnyHashable]) throws {
  26. projectID = dictionary["projectId"] as? String
  27. if let authorizedDomains = dictionary["authorizedDomains"] as? String,
  28. let data = authorizedDomains.data(using: .utf8) {
  29. if let decoded = try? JSONSerialization.jsonObject(
  30. with: data,
  31. options: [.mutableLeaves]
  32. ), let array = decoded as? [String] {
  33. self.authorizedDomains = array
  34. }
  35. } else if let authorizedDomains = dictionary["authorizedDomains"] as? [String] {
  36. self.authorizedDomains = authorizedDomains
  37. }
  38. }
  39. }