FBSDKTournamentUpdater.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  3. *
  4. * You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  5. * copy, modify, and distribute this software in source code or binary form for use
  6. * in connection with the web services and APIs provided by Facebook.
  7. *
  8. * As with any software that integrates with the Facebook platform, your use of
  9. * this software is subject to the Facebook Developer Principles and Policies
  10. * [http://developers.facebook.com/policy/]. This copyright notice shall be
  11. * included in all copies or substantial portions of the software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  15. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  16. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  17. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  18. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. import FBSDKCoreKit
  21. import FBSDKGamingServicesKit
  22. import Foundation
  23. /// An internal class for fetching tournament objects.
  24. @objcMembers
  25. public final class FBSDKTournamentUpdater: NSObject {
  26. public override init() {
  27. super.init()
  28. }
  29. /**
  30. Updates the given tournament with the given score
  31. - Parameter tournamentID: The ID of the tournament you want to update
  32. - Parameter score: The new score to update within the tournament
  33. - Parameter completionHandler: The caller's completion handler to invoke once the graph request is complete. Completes with `true` if successful.
  34. */
  35. public func update(
  36. tournamentID: String,
  37. score: Int,
  38. completionHandler: @escaping (Bool, Error?) -> Void
  39. ) {
  40. guard !tournamentID.isEmpty else {
  41. return completionHandler(false, TournamentUpdaterError.invalidTournamentID)
  42. }
  43. TournamentUpdater()
  44. .update(tournamentID: tournamentID, score: score) { result in
  45. switch result {
  46. case let .success(success):
  47. completionHandler(success, nil)
  48. case let .failure(error):
  49. completionHandler(false, error)
  50. }
  51. }
  52. }
  53. /**
  54. Updates the given tournament with the given score
  55. - Parameter tournament: The tournament you want to update
  56. - Parameter score: The new score to update within the tournament
  57. - Parameter completionHandler: The caller's completion handler to invoke once the graph request is complete. Completes with `true` if successful.
  58. */
  59. public func update(
  60. tournament: FBSDKTournament,
  61. score: Int,
  62. completionHandler: @escaping (Bool, Error?) -> Void
  63. ) {
  64. update(tournamentID: tournament.identifier, score: score, completionHandler: completionHandler)
  65. }
  66. }