LineSDKMessageAction.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // LineSDKMessageAction.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. extension MessageAction {
  22. var wrapped: LineSDKMessageAction {
  23. switch self {
  24. case .URI(let action): return LineSDKMessageURIAction(action)
  25. case .unknown: Log.fatalError("Cannot create ObjC compatible type for \(self).")
  26. }
  27. }
  28. }
  29. @objcMembers
  30. public class LineSDKMessageAction: NSObject {
  31. public var URIAction: LineSDKMessageURIAction? {
  32. return unwrapped.asURIAction.map { .init($0) }
  33. }
  34. var unwrapped: MessageAction { Log.fatalError("Not implemented in subclass: \(type(of: self))") }
  35. }
  36. @objcMembers
  37. public class LineSDKMessageURIAction: LineSDKMessageAction {
  38. public var label: String?
  39. public var uri: URL
  40. convenience init(_ value: MessageURIAction) {
  41. self.init(label: value.label, uri: value.uri)
  42. }
  43. public init(label: String?, uri: URL) {
  44. self.label = label
  45. self.uri = uri
  46. }
  47. override var unwrapped: MessageAction {
  48. return .URI(MessageURIAction(label: label, uri: uri))
  49. }
  50. }