| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- //
- // LineSDKAPI.swift
- //
- // Copyright (c) 2016-present, LY Corporation. All rights reserved.
- //
- // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
- // copy and distribute this software in source code or binary form for use
- // in connection with the web services and APIs provided by LY Corporation.
- //
- // As with any software that integrates with the LY Corporation platform, your use of this software
- // is subject to the LINE Developers Agreement [http://terms2.line.me/LINE_Developers_Agreement].
- // This copyright notice shall be included in all copies or substantial portions of the software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- @objcMembers
- public class LineSDKAPI: NSObject {
-
- // MARK: - getProfile
- public static func getProfile(
- completionHandler completion: @escaping (LineSDKUserProfile?, Error?) -> Void)
- {
- getProfile(callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- public static func getProfile(
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKUserProfile?, Error?) -> Void)
- {
- API.getProfile(callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKUserProfile.init).match(with: completion)
- }
- }
-
- // MARK: - getFriends
- public static func getFriends(
- pageToken: String?,
- completionHandler completion: @escaping (LineSDKGetFriendsResponse?, Error?) -> Void)
- {
- getFriends(sort: .none, pageToken: pageToken, completionHandler: completion)
- }
-
- public static func getFriends(
- sort: LineSDKGetFriendsRequestSort,
- pageToken: String?,
- completionHandler completion: @escaping (LineSDKGetFriendsResponse?, Error?) -> Void)
- {
- getFriends(sort: sort, pageToken: pageToken, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- public static func getFriends(
- sort: LineSDKGetFriendsRequestSort,
- pageToken: String?,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKGetFriendsResponse?, Error?) -> Void)
- {
- API.getFriends(sort: sort.unwrapped, pageToken: pageToken, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKGetFriendsResponse.init).match(with: completion)
- }
- }
-
- // MARK: - getApproversInFriends
- public static func getApproversInFriends(
- pageToken: String?,
- completionHandler completion: @escaping (LineSDKGetApproversInFriendsResponse?, Error?) -> Void)
- {
- getApproversInFriends(pageToken: pageToken, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- public static func getApproversInFriends(
- pageToken: String?,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKGetApproversInFriendsResponse?, Error?) -> Void)
- {
- API.getApproversInFriends(pageToken: pageToken, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKGetApproversInFriendsResponse.init).match(with: completion)
- }
- }
-
- // MARK: - getGroups
- public static func getGroups(
- pageToken: String?,
- completionHandler completion: @escaping (LineSDKGetGroupsResponse?, Error?) -> Void)
- {
- getGroups(pageToken: pageToken, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- public static func getGroups(
- pageToken: String?,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKGetGroupsResponse?, Error?) -> Void)
- {
- API.getGroups(pageToken: pageToken, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKGetGroupsResponse.init).match(with: completion)
- }
- }
-
- // MARK: - getApproversInGroups
- public static func getApproversInGroup(
- groupID: String,
- pageToken: String?,
- completionHandler completion: @escaping (LineSDKGetApproversInGroupResponse?, Error?) -> Void)
- {
- getApproversInGroup(
- groupID: groupID, pageToken: pageToken, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- public static func getApproversInGroup(
- groupID: String,
- pageToken: String?,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKGetApproversInGroupResponse?, Error?) -> Void)
- {
- API.getApproversInGroup(groupID: groupID, pageToken: pageToken, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKGetApproversInGroupResponse.init).match(with: completion)
- }
- }
-
- // MARK: - sendMessages
- public static func sendMessages(
- _ messages: [LineSDKMessage],
- to chatID: String,
- completionHandler completion: @escaping (LineSDKPostSendMessagesResponse?, Error?) -> Void)
- {
- sendMessages(messages, to: chatID, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- public static func sendMessages(
- _ messages: [LineSDKMessage],
- to chatID: String,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKPostSendMessagesResponse?, Error?) -> Void)
- {
- API.sendMessages(messages.map { $0.unwrapped }, to: chatID, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKPostSendMessagesResponse.init).match(with: completion)
- }
- }
- public static func multiSendMessages(
- _ messages: [LineSDKMessage],
- to userIDs: [String],
- completionHandler completion: @escaping (LineSDKPostMultisendMessagesResponse?, Error?) -> Void)
- {
- multiSendMessages(messages, to: userIDs, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
- public static func multiSendMessages(
- _ messages: [LineSDKMessage],
- to userIDs: [String],
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKPostMultisendMessagesResponse?, Error?) -> Void)
- {
- API.multiSendMessages(messages.map { $0.unwrapped }, to: userIDs, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKPostMultisendMessagesResponse.init).match(with: completion)
- }
- }
-
- // MARK: - Friendship
- public static func getBotFriendshipStatus(
- completionHandler completion: @escaping (LineSDKGetBotFriendshipStatusResponse?, Error?) -> Void)
- {
- getBotFriendshipStatus(callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- public static func getBotFriendshipStatus(
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKGetBotFriendshipStatusResponse?, Error?) -> Void)
- {
- API.getBotFriendshipStatus(callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKGetBotFriendshipStatusResponse.init).match(with: completion)
- }
- }
- // MARK: - Sharing
- public static func getMessageSendingOneTimeToken(
- userIDs: [String],
- completionHander completion: @escaping (LineSDKMessageSendingToken?, Error?) -> Void)
- {
- getMessageSendingOneTimeToken(
- userIDs: userIDs, callbackQueue: .currentMainOrAsync, completionHander: completion)
- }
- public static func getMessageSendingOneTimeToken(
- userIDs: [String],
- callbackQueue queue: LineSDKCallbackQueue,
- completionHander completion: @escaping (LineSDKMessageSendingToken?, Error?) -> Void)
- {
- API.getMessageSendingOneTimeToken(userIDs: userIDs, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKMessageSendingToken.init).match(with: completion)
- }
- }
- public static func multiSendMessages(
- _ messages: [LineSDKMessage],
- withMessageToken token: LineSDKMessageSendingToken,
- completionHandler completion: @escaping (Error?) -> Void)
- {
- multiSendMessages(
- messages, withMessageToken: token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
- public static func multiSendMessages(
- _ messages: [LineSDKMessage],
- withMessageToken token: LineSDKMessageSendingToken,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (Error?) -> Void)
- {
- API.multiSendMessages(
- messages.map { $0.unwrapped },
- withMessageToken: token._value,
- callbackQueue: queue.unwrapped) { result in result.matchFailure(with: completion) }
- }
-
- // MARK: - Open Chat
- public static func getOpenChatRoomStatus(
- openChatId: String,
- completionHandler completion: @escaping (LineSDKOpenChatRoomStatus?, Error?) -> Void
- )
- {
- getOpenChatRoomStatus(
- openChatId: openChatId, callbackQueue: .currentMainOrAsync, completionHandler: completion
- )
- }
-
- public static func getOpenChatRoomStatus(
- openChatId: String,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKOpenChatRoomStatus?, Error?) -> Void
- )
- {
- API.getOpenChatRoomStatus(openChatId: openChatId, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKOpenChatRoomStatus.init).match(with: completion)
- }
- }
-
- public static func getOpenChatRoomMembershipState(
- openChatId: String,
- completionHandler completion: @escaping (LineSDKOpenChatRoomMembershipState?, Error?) -> Void
- )
- {
- getOpenChatRoomMembershipState(
- openChatId: openChatId, callbackQueue: .currentMainOrAsync, completionHandler: completion
- )
- }
-
- public static func getOpenChatRoomMembershipState(
- openChatId: String,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKOpenChatRoomMembershipState?, Error?) -> Void
- )
- {
- API.getOpenChatRoomMembershipState(openChatId: openChatId, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKOpenChatRoomMembershipState.init).match(with: completion)
- }
- }
- public static func getOpenChatRoomJoinType(
- openChatId: String,
- completionHandler completion: @escaping (LineSDKOpenChatRoomJoinType?, Error?) -> Void
- )
- {
- getOpenChatRoomJoinType(openChatId: openChatId, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
- public static func getOpenChatRoomJoinType(
- openChatId: String,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKOpenChatRoomJoinType?, Error?) -> Void
- )
- {
- API.getOpenChatRoomJoinType(openChatId: openChatId, callbackQueue: queue.unwrapped) { result in
- result.map(LineSDKOpenChatRoomJoinType.init).match(with: completion)
- }
- }
- public static func postOpenChatRoomJoin(
- openChatId: String,
- displayName: String,
- completionHandler completion: @escaping (Error?) -> Void
- )
- {
- postOpenChatRoomJoin(
- openChatId: openChatId,
- displayName: displayName,
- callbackQueue: .currentMainOrAsync,
- completionHandler: completion
- )
- }
- public static func postOpenChatRoomJoin(
- openChatId: String,
- displayName: String,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (Error?) -> Void
- )
- {
- API.postOpenChatRoomJoin(openChatId: openChatId, displayName: displayName, callbackQueue: queue.unwrapped) {
- result in
- switch result {
- case .success: completion(nil)
- case .failure(let error): completion(error)
- }
- }
- }
- }
- // MARK: - getGroups
- extension LineSDKAPI {
- // MARK: - refreshAccessToken
- @available(*, deprecated,
- message: """
- Auth-related APIs don't refresh access tokens automatically.
- Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
- """,
- renamed: "LineSDKAuthAPI.refreshAccessToken"
- )
- public static func refreshAccessToken(
- completionHandler completion: @escaping (LineSDKAccessToken?, Error?) -> Void)
- {
- refreshAccessToken(callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- @available(*, deprecated,
- message: """
- Auth-related APIs don't refresh access tokens automatically.
- Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
- """,
- renamed: "LineSDKAuthAPI.refreshAccessToken"
- )
- public static func refreshAccessToken(
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKAccessToken?, Error?) -> Void)
- {
- LineSDKAuthAPI.refreshAccessToken(callbackQueue: queue, completionHandler: completion)
- }
-
- // MARK: - revokeAccessToken
- @available(*, deprecated,
- message: """
- Auth-related APIs don't refresh access tokens automatically.
- Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
- """,
- renamed: "LineSDKAuthAPI.revokeAccessToken"
- )
- public static func revokeAccessToken(
- completionHandler completion: @escaping (Error?) -> Void)
- {
- revokeAccessToken(nil, completionHandler: completion)
- }
-
- @available(*, deprecated,
- message: """
- Auth-related APIs don't refresh access tokens automatically.
- Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
- """,
- renamed: "LineSDKAuthAPI.revokeAccessToken"
- )
- public static func revokeAccessToken(
- _ token: String?,
- completionHandler completion: @escaping (Error?) -> Void)
- {
- revokeAccessToken(token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- @available(*, deprecated,
- message: """
- Auth-related APIs don't refresh access tokens automatically.
- Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
- """,
- renamed: "LineSDKAuthAPI.revokeAccessToken"
- )
- public static func revokeAccessToken(
- _ token: String?,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (Error?) -> Void)
- {
- LineSDKAuthAPI.revokeAccessToken(token, callbackQueue: queue, completionHandler: completion)
- }
-
- // MARK: - verifyAccessToken
- @available(*, deprecated,
- message: """
- Auth-related APIs don't refresh access tokens automatically.
- Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
- """,
- renamed: "LineSDKAuthAPI.verifyAccessToken"
- )
- public static func verifyAccessToken(
- completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
- {
- verifyAccessToken(nil, completionHandler: completion)
- }
-
- @available(*, deprecated,
- message: """
- Auth-related APIs don't refresh access tokens automatically.
- Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
- """,
- renamed: "LineSDKAuthAPI.verifyAccessToken"
- )
- public static func verifyAccessToken(
- _ token: String?,
- completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
- {
- verifyAccessToken(token, callbackQueue: .currentMainOrAsync, completionHandler: completion)
- }
-
- @available(*, deprecated,
- message: """
- Auth-related APIs don't refresh access tokens automatically.
- Make sure you don't need token refreshing as a side effect, then use methods in `LineSDKAuthAPI` instead.
- """,
- renamed: "LineSDKAuthAPI.verifyAccessToken"
- )
- public static func verifyAccessToken(
- _ token: String?,
- callbackQueue queue: LineSDKCallbackQueue,
- completionHandler completion: @escaping (LineSDKAccessTokenVerifyResult?, Error?) -> Void)
- {
- LineSDKAuthAPI.verifyAccessToken(token, callbackQueue: queue, completionHandler: completion)
- }
- }
|