LineSDKTemplateButtonsPayload.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // LineSDKTemplateButtonsPayload.swift
  3. //
  4. // Copyright (c) 2016-present, LY Corporation. All rights reserved.
  5. //
  6. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  7. // copy and distribute this software in source code or binary form for use
  8. // in connection with the web services and APIs provided by LY Corporation.
  9. //
  10. // As with any software that integrates with the LY Corporation platform, your use of this software
  11. // is subject to the LINE Developers Agreement [http://terms2.line.me/LINE_Developers_Agreement].
  12. // This copyright notice shall be included in all copies or substantial portions of the software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  15. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. @objcMembers
  22. public class LineSDKTemplateButtonsPayload: LineSDKTemplateMessagePayload {
  23. public var text: String
  24. public var title: String?
  25. public var actions: [LineSDKMessageAction]
  26. public var defaultAction: LineSDKMessageAction?
  27. public var thumbnailImageURL: URL?
  28. public var imageAspectRatio: LineSDKTemplateMessagePayloadImageAspectRatio = .none
  29. public var imageContentMode: LineSDKTemplateMessagePayloadImageContentMode = .none
  30. public var imageBackgroundColor: LineSDKHexColor?
  31. public var sender: LineSDKMessageSender?
  32. public init(title: String?, text: String, actions: [LineSDKMessageAction]) {
  33. self.title = title
  34. self.text = text
  35. self.actions = actions
  36. }
  37. convenience init(_ value: TemplateButtonsPayload) {
  38. self.init(title: value.title, text: value.text, actions: value.actions.map { $0.wrapped })
  39. defaultAction = value.defaultAction.map { $0.wrapped }
  40. thumbnailImageURL = value.thumbnailImageURL
  41. imageAspectRatio = .init(value.imageAspectRatio)
  42. imageContentMode = .init(value.imageContentMode)
  43. imageBackgroundColor = value.imageBackgroundColor.map { .init($0) }
  44. sender = value.sender.map { .init($0) }
  45. }
  46. override var unwrapped: TemplateMessagePayload {
  47. var payload = TemplateButtonsPayload(title: title, text: text, actions: actions.map { $0.unwrapped })
  48. payload.defaultAction = defaultAction?.unwrapped
  49. payload.thumbnailImageURL = thumbnailImageURL
  50. payload.imageAspectRatio = imageAspectRatio.unwrapped
  51. payload.imageContentMode = imageContentMode.unwrapped
  52. payload.imageBackgroundColor = imageBackgroundColor?.unwrapped
  53. payload.sender = sender?.unwrapped
  54. return .buttons(payload)
  55. }
  56. }