FBSDKTournament.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 FBSDKGamingServicesKit
  21. import Foundation
  22. /// An internal representation of tournament graph objects.
  23. @objcMembers
  24. public final class FBSDKTournament: NSObject {
  25. /// The unique ID that is associated with this tournament.
  26. public internal(set) var identifier: String
  27. /**
  28. Timestamp when the tournament ends.
  29. If the expiration is in the past, then the tournament is already finished and has expired.
  30. */
  31. public internal(set) var endTime: Date?
  32. /// Title of the tournament provided upon the creation of the tournament.
  33. public internal(set) var title: String?
  34. /// Payload of the tournament provided upon the creation of the tournament.
  35. public var payload: String?
  36. public convenience init(tournament: Tournament) {
  37. self.init(
  38. identifier: tournament.identifier,
  39. endTime: tournament.endTime,
  40. title: tournament.title,
  41. payload: tournament.payload
  42. )
  43. }
  44. public var toDictionary: [String: String] {
  45. var dictionary = ["tournament_id": identifier]
  46. if let endTime = endTime {
  47. dictionary["end_time"] = "\(endTime.timeIntervalSince1970)"
  48. }
  49. dictionary["tournament_title"] = title
  50. dictionary["payload"] = payload
  51. return dictionary
  52. }
  53. public init(
  54. identifier: String,
  55. endTime: Date? = nil,
  56. title: String? = nil,
  57. payload: String? = nil
  58. ) {
  59. self.identifier = identifier
  60. self.endTime = endTime
  61. self.title = title
  62. self.payload = payload
  63. }
  64. }