LineSDKTemplateCarouselPayload.swift 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // LineSDKTemplateCarouselPayload.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 LineSDKTemplateCarouselPayloadColumn: NSObject {
  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 imageBackgroundColor: LineSDKHexColor?
  29. public init(title: String?, text: String, actions: [LineSDKMessageAction]) {
  30. self.title = title
  31. self.text = text
  32. self.actions = actions
  33. }
  34. convenience init(_ value: TemplateCarouselPayload.Column) {
  35. self.init(title: value.title, text: value.text, actions: value.actions.map { $0.wrapped })
  36. defaultAction = value.defaultAction.map { $0.wrapped }
  37. thumbnailImageURL = value.thumbnailImageURL
  38. imageBackgroundColor = value.imageBackgroundColor.map { .init($0) }
  39. }
  40. public func addAction(_ value: LineSDKMessageAction) {
  41. actions.append(value)
  42. }
  43. var unwrapped: TemplateCarouselPayload.Column {
  44. var column = TemplateCarouselPayload.Column(title: title, text: text, actions: actions.map {$0.unwrapped })
  45. column.defaultAction = defaultAction?.unwrapped
  46. column.thumbnailImageURL = thumbnailImageURL
  47. column.imageBackgroundColor = imageBackgroundColor?.unwrapped
  48. return column
  49. }
  50. }
  51. @objcMembers
  52. public class LineSDKTemplateCarouselPayload: LineSDKTemplateMessagePayload {
  53. public var columns: [LineSDKTemplateCarouselPayloadColumn]
  54. public var imageAspectRatio: LineSDKTemplateMessagePayloadImageAspectRatio = .none
  55. public var imageContentMode: LineSDKTemplateMessagePayloadImageContentMode = .none
  56. convenience init(_ value: TemplateCarouselPayload) {
  57. self.init(columns: value.columns.map { .init($0) })
  58. imageAspectRatio = .init(value.imageAspectRatio)
  59. imageContentMode = .init(value.imageContentMode)
  60. }
  61. public init(columns: [LineSDKTemplateCarouselPayloadColumn]) {
  62. self.columns = columns
  63. }
  64. override var unwrapped: TemplateMessagePayload {
  65. let payload = TemplateCarouselPayload(columns: columns.map { $0.unwrapped })
  66. return .carousel(payload)
  67. }
  68. public func addColumn(_ column: LineSDKTemplateCarouselPayloadColumn) {
  69. columns.append(column)
  70. }
  71. }