LineSDKAPI.swift 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. //
  2. // LineSDKAPI.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 LineSDKAPI: NSObject {
  23. // MARK: - getProfile
  24. public static func getProfile(
  25. completionHandler completion: @escaping (LineSDKUserProfile?, Error?) -> Void)
  26. {
  27. getProfile(callbackQueue: .currentMainOrAsync, completionHandler: completion)
  28. }
  29. public static func getProfile(
  30. callbackQueue queue: LineSDKCallbackQueue,
  31. completionHandler completion: @escaping (LineSDKUserProfile?, Error?) -> Void)
  32. {
  33. API.getProfile(callbackQueue: queue.unwrapped) { result in
  34. result.map(LineSDKUserProfile.init).match(with: completion)
  35. }
  36. }
  37. // MARK: - getFriends
  38. public static func getFriends(
  39. pageToken: String?,
  40. completionHandler completion: @escaping (LineSDKGetFriendsResponse?, Error?) -> Void)
  41. {
  42. getFriends(sort: .none, pageToken: pageToken, completionHandler: completion)
  43. }
  44. public static func getFriends(
  45. sort: LineSDKGetFriendsRequestSort,
  46. pageToken: String?,
  47. completionHandler completion: @escaping (LineSDKGetFriendsResponse?, Error?) -> Void)
  48. {
  49. getFriends(sort: sort, pageToken: pageToken, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  50. }
  51. public static func getFriends(
  52. sort: LineSDKGetFriendsRequestSort,
  53. pageToken: String?,
  54. callbackQueue queue: LineSDKCallbackQueue,
  55. completionHandler completion: @escaping (LineSDKGetFriendsResponse?, Error?) -> Void)
  56. {
  57. API.getFriends(sort: sort.unwrapped, pageToken: pageToken, callbackQueue: queue.unwrapped) { result in
  58. result.map(LineSDKGetFriendsResponse.init).match(with: completion)
  59. }
  60. }
  61. // MARK: - getApproversInFriends
  62. public static func getApproversInFriends(
  63. pageToken: String?,
  64. completionHandler completion: @escaping (LineSDKGetApproversInFriendsResponse?, Error?) -> Void)
  65. {
  66. getApproversInFriends(pageToken: pageToken, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  67. }
  68. public static func getApproversInFriends(
  69. pageToken: String?,
  70. callbackQueue queue: LineSDKCallbackQueue,
  71. completionHandler completion: @escaping (LineSDKGetApproversInFriendsResponse?, Error?) -> Void)
  72. {
  73. API.getApproversInFriends(pageToken: pageToken, callbackQueue: queue.unwrapped) { result in
  74. result.map(LineSDKGetApproversInFriendsResponse.init).match(with: completion)
  75. }
  76. }
  77. // MARK: - getGroups
  78. public static func getGroups(
  79. pageToken: String?,
  80. completionHandler completion: @escaping (LineSDKGetGroupsResponse?, Error?) -> Void)
  81. {
  82. getGroups(pageToken: pageToken, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  83. }
  84. public static func getGroups(
  85. pageToken: String?,
  86. callbackQueue queue: LineSDKCallbackQueue,
  87. completionHandler completion: @escaping (LineSDKGetGroupsResponse?, Error?) -> Void)
  88. {
  89. API.getGroups(pageToken: pageToken, callbackQueue: queue.unwrapped) { result in
  90. result.map(LineSDKGetGroupsResponse.init).match(with: completion)
  91. }
  92. }
  93. // MARK: - getApproversInGroups
  94. public static func getApproversInGroup(
  95. groupID: String,
  96. pageToken: String?,
  97. completionHandler completion: @escaping (LineSDKGetApproversInGroupResponse?, Error?) -> Void)
  98. {
  99. getApproversInGroup(
  100. groupID: groupID, pageToken: pageToken, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  101. }
  102. public static func getApproversInGroup(
  103. groupID: String,
  104. pageToken: String?,
  105. callbackQueue queue: LineSDKCallbackQueue,
  106. completionHandler completion: @escaping (LineSDKGetApproversInGroupResponse?, Error?) -> Void)
  107. {
  108. API.getApproversInGroup(groupID: groupID, pageToken: pageToken, callbackQueue: queue.unwrapped) { result in
  109. result.map(LineSDKGetApproversInGroupResponse.init).match(with: completion)
  110. }
  111. }
  112. // MARK: - sendMessages
  113. public static func sendMessages(
  114. _ messages: [LineSDKMessage],
  115. to chatID: String,
  116. completionHandler completion: @escaping (LineSDKPostSendMessagesResponse?, Error?) -> Void)
  117. {
  118. sendMessages(messages, to: chatID, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  119. }
  120. public static func sendMessages(
  121. _ messages: [LineSDKMessage],
  122. to chatID: String,
  123. callbackQueue queue: LineSDKCallbackQueue,
  124. completionHandler completion: @escaping (LineSDKPostSendMessagesResponse?, Error?) -> Void)
  125. {
  126. API.sendMessages(messages.map { $0.unwrapped }, to: chatID, callbackQueue: queue.unwrapped) { result in
  127. result.map(LineSDKPostSendMessagesResponse.init).match(with: completion)
  128. }
  129. }
  130. public static func multiSendMessages(
  131. _ messages: [LineSDKMessage],
  132. to userIDs: [String],
  133. completionHandler completion: @escaping (LineSDKPostMultisendMessagesResponse?, Error?) -> Void)
  134. {
  135. multiSendMessages(messages, to: userIDs, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  136. }
  137. public static func multiSendMessages(
  138. _ messages: [LineSDKMessage],
  139. to userIDs: [String],
  140. callbackQueue queue: LineSDKCallbackQueue,
  141. completionHandler completion: @escaping (LineSDKPostMultisendMessagesResponse?, Error?) -> Void)
  142. {
  143. API.multiSendMessages(messages.map { $0.unwrapped }, to: userIDs, callbackQueue: queue.unwrapped) { result in
  144. result.map(LineSDKPostMultisendMessagesResponse.init).match(with: completion)
  145. }
  146. }
  147. // MARK: - Friendship
  148. public static func getBotFriendshipStatus(
  149. completionHandler completion: @escaping (LineSDKGetBotFriendshipStatusResponse?, Error?) -> Void)
  150. {
  151. getBotFriendshipStatus(callbackQueue: .currentMainOrAsync, completionHandler: completion)
  152. }
  153. public static func getBotFriendshipStatus(
  154. callbackQueue queue: LineSDKCallbackQueue,
  155. completionHandler completion: @escaping (LineSDKGetBotFriendshipStatusResponse?, Error?) -> Void)
  156. {
  157. API.getBotFriendshipStatus(callbackQueue: queue.unwrapped) { result in
  158. result.map(LineSDKGetBotFriendshipStatusResponse.init).match(with: completion)
  159. }
  160. }
  161. // MARK: - Sharing
  162. public static func getMessageSendingOneTimeToken(
  163. userIDs: [String],
  164. completionHander completion: @escaping (LineSDKMessageSendingToken?, Error?) -> Void)
  165. {
  166. getMessageSendingOneTimeToken(
  167. userIDs: userIDs, callbackQueue: .currentMainOrAsync, completionHander: completion)
  168. }
  169. public static func getMessageSendingOneTimeToken(
  170. userIDs: [String],
  171. callbackQueue queue: LineSDKCallbackQueue,
  172. completionHander completion: @escaping (LineSDKMessageSendingToken?, Error?) -> Void)
  173. {
  174. API.getMessageSendingOneTimeToken(userIDs: userIDs, callbackQueue: queue.unwrapped) { result in
  175. result.map(LineSDKMessageSendingToken.init).match(with: completion)
  176. }
  177. }
  178. public static func multiSendMessages(
  179. _ messages: [LineSDKMessage],
  180. withMessageToken token: LineSDKMessageSendingToken,
  181. completionHandler completion: @escaping (Error?) -> Void)
  182. {
  183. multiSendMessages(
  184. messages, withMessageToken: token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  185. }
  186. public static func multiSendMessages(
  187. _ messages: [LineSDKMessage],
  188. withMessageToken token: LineSDKMessageSendingToken,
  189. callbackQueue queue: LineSDKCallbackQueue,
  190. completionHandler completion: @escaping (Error?) -> Void)
  191. {
  192. API.multiSendMessages(
  193. messages.map { $0.unwrapped },
  194. withMessageToken: token._value,
  195. callbackQueue: queue.unwrapped) { result in result.matchFailure(with: completion) }
  196. }
  197. // MARK: - Open Chat
  198. public static func getOpenChatRoomStatus(
  199. openChatId: String,
  200. completionHandler completion: @escaping (LineSDKOpenChatRoomStatus?, Error?) -> Void
  201. )
  202. {
  203. getOpenChatRoomStatus(
  204. openChatId: openChatId, callbackQueue: .currentMainOrAsync, completionHandler: completion
  205. )
  206. }
  207. public static func getOpenChatRoomStatus(
  208. openChatId: String,
  209. callbackQueue queue: LineSDKCallbackQueue,
  210. completionHandler completion: @escaping (LineSDKOpenChatRoomStatus?, Error?) -> Void
  211. )
  212. {
  213. API.getOpenChatRoomStatus(openChatId: openChatId, callbackQueue: queue.unwrapped) { result in
  214. result.map(LineSDKOpenChatRoomStatus.init).match(with: completion)
  215. }
  216. }
  217. public static func getOpenChatRoomMembershipState(
  218. openChatId: String,
  219. completionHandler completion: @escaping (LineSDKOpenChatRoomMembershipState?, Error?) -> Void
  220. )
  221. {
  222. getOpenChatRoomMembershipState(
  223. openChatId: openChatId, callbackQueue: .currentMainOrAsync, completionHandler: completion
  224. )
  225. }
  226. public static func getOpenChatRoomMembershipState(
  227. openChatId: String,
  228. callbackQueue queue: LineSDKCallbackQueue,
  229. completionHandler completion: @escaping (LineSDKOpenChatRoomMembershipState?, Error?) -> Void
  230. )
  231. {
  232. API.getOpenChatRoomMembershipState(openChatId: openChatId, callbackQueue: queue.unwrapped) { result in
  233. result.map(LineSDKOpenChatRoomMembershipState.init).match(with: completion)
  234. }
  235. }
  236. public static func getOpenChatRoomJoinType(
  237. openChatId: String,
  238. completionHandler completion: @escaping (LineSDKOpenChatRoomJoinType?, Error?) -> Void
  239. )
  240. {
  241. getOpenChatRoomJoinType(openChatId: openChatId, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  242. }
  243. public static func getOpenChatRoomJoinType(
  244. openChatId: String,
  245. callbackQueue queue: LineSDKCallbackQueue,
  246. completionHandler completion: @escaping (LineSDKOpenChatRoomJoinType?, Error?) -> Void
  247. )
  248. {
  249. API.getOpenChatRoomJoinType(openChatId: openChatId, callbackQueue: queue.unwrapped) { result in
  250. result.map(LineSDKOpenChatRoomJoinType.init).match(with: completion)
  251. }
  252. }
  253. public static func postOpenChatRoomJoin(
  254. openChatId: String,
  255. displayName: String,
  256. completionHandler completion: @escaping (Error?) -> Void
  257. )
  258. {
  259. postOpenChatRoomJoin(
  260. openChatId: openChatId,
  261. displayName: displayName,
  262. callbackQueue: .currentMainOrAsync,
  263. completionHandler: completion
  264. )
  265. }
  266. public static func postOpenChatRoomJoin(
  267. openChatId: String,
  268. displayName: String,
  269. callbackQueue queue: LineSDKCallbackQueue,
  270. completionHandler completion: @escaping (Error?) -> Void
  271. )
  272. {
  273. API.postOpenChatRoomJoin(openChatId: openChatId, displayName: displayName, callbackQueue: queue.unwrapped) {
  274. result in
  275. switch result {
  276. case .success: completion(nil)
  277. case .failure(let error): completion(error)
  278. }
  279. }
  280. }
  281. }
  282. // MARK: - getGroups
  283. extension LineSDKAPI {
  284. // MARK: - refreshAccessToken
  285. @available(*, deprecated,
  286. message: """
  287. Auth-related APIs don't refresh access tokens automatically.
  288. Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
  289. """,
  290. renamed: "LineSDKAuthAPI.refreshAccessToken"
  291. )
  292. public static func refreshAccessToken(
  293. completionHandler completion: @escaping (LineSDKAccessToken?, Error?) -> Void)
  294. {
  295. refreshAccessToken(callbackQueue: .currentMainOrAsync, completionHandler: completion)
  296. }
  297. @available(*, deprecated,
  298. message: """
  299. Auth-related APIs don't refresh access tokens automatically.
  300. Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
  301. """,
  302. renamed: "LineSDKAuthAPI.refreshAccessToken"
  303. )
  304. public static func refreshAccessToken(
  305. callbackQueue queue: LineSDKCallbackQueue,
  306. completionHandler completion: @escaping (LineSDKAccessToken?, Error?) -> Void)
  307. {
  308. LineSDKAuthAPI.refreshAccessToken(callbackQueue: queue, completionHandler: completion)
  309. }
  310. // MARK: - revokeAccessToken
  311. @available(*, deprecated,
  312. message: """
  313. Auth-related APIs don't refresh access tokens automatically.
  314. Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
  315. """,
  316. renamed: "LineSDKAuthAPI.revokeAccessToken"
  317. )
  318. public static func revokeAccessToken(
  319. completionHandler completion: @escaping (Error?) -> Void)
  320. {
  321. revokeAccessToken(nil, completionHandler: completion)
  322. }
  323. @available(*, deprecated,
  324. message: """
  325. Auth-related APIs don't refresh access tokens automatically.
  326. Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
  327. """,
  328. renamed: "LineSDKAuthAPI.revokeAccessToken"
  329. )
  330. public static func revokeAccessToken(
  331. _ token: String?,
  332. completionHandler completion: @escaping (Error?) -> Void)
  333. {
  334. revokeAccessToken(token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  335. }
  336. @available(*, deprecated,
  337. message: """
  338. Auth-related APIs don't refresh access tokens automatically.
  339. Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
  340. """,
  341. renamed: "LineSDKAuthAPI.revokeAccessToken"
  342. )
  343. public static func revokeAccessToken(
  344. _ token: String?,
  345. callbackQueue queue: LineSDKCallbackQueue,
  346. completionHandler completion: @escaping (Error?) -> Void)
  347. {
  348. LineSDKAuthAPI.revokeAccessToken(token, callbackQueue: queue, completionHandler: completion)
  349. }
  350. // MARK: - verifyAccessToken
  351. @available(*, deprecated,
  352. message: """
  353. Auth-related APIs don't refresh access tokens automatically.
  354. Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
  355. """,
  356. renamed: "LineSDKAuthAPI.verifyAccessToken"
  357. )
  358. public static func verifyAccessToken(
  359. completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
  360. {
  361. verifyAccessToken(nil, completionHandler: completion)
  362. }
  363. @available(*, deprecated,
  364. message: """
  365. Auth-related APIs don't refresh access tokens automatically.
  366. Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
  367. """,
  368. renamed: "LineSDKAuthAPI.verifyAccessToken"
  369. )
  370. public static func verifyAccessToken(
  371. _ token: String?,
  372. completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
  373. {
  374. verifyAccessToken(token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
  375. }
  376. @available(*, deprecated,
  377. message: """
  378. Auth-related APIs don't refresh access tokens automatically.
  379. Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
  380. """,
  381. renamed: "LineSDKAuthAPI.verifyAccessToken"
  382. )
  383. public static func verifyAccessToken(
  384. _ token: String?,
  385. callbackQueue queue: LineSDKCallbackQueue,
  386. completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
  387. {
  388. LineSDKAuthAPI.verifyAccessToken(token, callbackQueue: queue, completionHandler: completion)
  389. }
  390. }