GoogleDataTransport+GoogleDataTransportProtocol.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // Copyright 2022 Google LLC
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. import Foundation
  16. @_implementationOnly import GoogleDataTransport
  17. enum GoogleDataTransportProtocolErrors: Error {
  18. case writeFailure
  19. }
  20. protocol GoogleDataTransportProtocol {
  21. func logGDTEvent(event: GDTCOREvent, completion: @escaping (Result<Void, Error>) -> Void)
  22. func eventForTransport() -> GDTCOREvent
  23. }
  24. extension GDTCORTransport: GoogleDataTransportProtocol {
  25. func logGDTEvent(event: GDTCOREvent, completion: @escaping (Result<Void, Error>) -> Void) {
  26. sendDataEvent(event) { wasWritten, error in
  27. if let error {
  28. completion(.failure(error))
  29. } else if !wasWritten {
  30. completion(.failure(GoogleDataTransportProtocolErrors.writeFailure))
  31. } else {
  32. completion(.success(()))
  33. }
  34. }
  35. }
  36. }