LineSDKMessage.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // LineSDKMessage.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 LineSDKMessage: NSObject {
  23. public static func message(with input: MessageConvertible) -> LineSDKMessage? {
  24. switch input.message {
  25. case .text(let m): return LineSDKTextMessage(m)
  26. case .image(let m): return LineSDKImageMessage(m)
  27. case .video(let m): return LineSDKVideoMessage(m)
  28. case .audio(let m): return LineSDKAudioMessage(m)
  29. case .location(let m): return LineSDKLocationMessage(m)
  30. case .template(let m): return LineSDKTemplateMessage(m)
  31. case .flex(let m): return LineSDKFlexMessage(m)
  32. case .unknown: return nil
  33. }
  34. }
  35. public var textMessage: LineSDKTextMessage? {
  36. return unwrapped.asTextMessage.map { .init($0) }
  37. }
  38. public var imageMessage: LineSDKImageMessage? {
  39. return unwrapped.asImageMessage.map { .init($0) }
  40. }
  41. public var videoMessage: LineSDKVideoMessage? {
  42. return unwrapped.asVideoMessage.map { .init($0) }
  43. }
  44. public var audioMessage: LineSDKAudioMessage? {
  45. return unwrapped.asAudioMessage.map { .init($0) }
  46. }
  47. public var locationMessage: LineSDKLocationMessage? {
  48. return unwrapped.asLocationMessage.map { .init($0) }
  49. }
  50. public var templateMessage: LineSDKTemplateMessage? {
  51. return unwrapped.asTemplateMessage.map { .init($0) }
  52. }
  53. public var flexMessage: LineSDKFlexMessage? {
  54. return unwrapped.asFlexMessage.map { .init($0) }
  55. }
  56. var unwrapped: Message { Log.fatalError("Not implemented in subclass: \(type(of: self))") }
  57. }
  58. @objcMembers
  59. public class LineSDKMessageSender: NSObject {
  60. var _value: MessageSender
  61. public var label: String {
  62. get { return _value.label }
  63. set { _value.label = newValue }
  64. }
  65. public var iconURL: URL {
  66. get { return _value.iconURL }
  67. set { _value.iconURL = newValue }
  68. }
  69. public var linkURL: URL? {
  70. get { return _value.linkURL }
  71. set { _value.linkURL = newValue }
  72. }
  73. init(_ value: MessageSender) {
  74. _value = value
  75. }
  76. public init(label: String, iconURL: URL, linkURL: URL?) {
  77. _value = .init(label: label, iconURL: iconURL, linkURL: linkURL)
  78. }
  79. var unwrapped: MessageSender { return _value }
  80. }