Skip to content

Commit

Permalink
Add chat room status and membership state to API helper
Browse files Browse the repository at this point in the history
  • Loading branch information
onevcat committed Feb 7, 2020
1 parent 3b7d414 commit d752335
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 12 deletions.
16 changes: 16 additions & 0 deletions LineSDK/LineSDK.xcodeproj/project.pbxproj
Expand Up @@ -124,6 +124,8 @@
4B813C5A2101B1450091F78E /* RequestAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B813C592101B1450091F78E /* RequestAdapter.swift */; };
4B813C5C2101B65D0091F78E /* ParametersAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B813C5B2101B65D0091F78E /* ParametersAdapter.swift */; };
4B825623224CC36000D9F63E /* ShareTargetSearchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B825622224CC36000D9F63E /* ShareTargetSearchController.swift */; };
4B8469A623EAA7AA00EE49FA /* LineSDKOpenChatRoomStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8469A523EAA7AA00EE49FA /* LineSDKOpenChatRoomStatus.swift */; };
4B8469A823EAA7BD00EE49FA /* LineSDKOpenChatRoomMembershipState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8469A723EAA7BD00EE49FA /* LineSDKOpenChatRoomMembershipState.swift */; };
4B85BB6B22C4A8E600DFE299 /* ResourceLoading.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B85BB6A22C4A8E600DFE299 /* ResourceLoading.swift */; };
4B8A965721100A5800760219 /* LoginConfigurationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8A965621100A5800760219 /* LoginConfigurationTests.swift */; };
4B8FF4862105656500890AEF /* Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B8FF4852105656500890AEF /* Delegate.swift */; };
Expand Down Expand Up @@ -472,6 +474,8 @@
4B813C592101B1450091F78E /* RequestAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestAdapter.swift; sourceTree = "<group>"; };
4B813C5B2101B65D0091F78E /* ParametersAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersAdapter.swift; sourceTree = "<group>"; };
4B825622224CC36000D9F63E /* ShareTargetSearchController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareTargetSearchController.swift; sourceTree = "<group>"; };
4B8469A523EAA7AA00EE49FA /* LineSDKOpenChatRoomStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineSDKOpenChatRoomStatus.swift; sourceTree = "<group>"; };
4B8469A723EAA7BD00EE49FA /* LineSDKOpenChatRoomMembershipState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineSDKOpenChatRoomMembershipState.swift; sourceTree = "<group>"; };
4B85BB6A22C4A8E600DFE299 /* ResourceLoading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourceLoading.swift; sourceTree = "<group>"; };
4B8A965621100A5800760219 /* LoginConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginConfigurationTests.swift; sourceTree = "<group>"; };
4B8FF4852105656500890AEF /* Delegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Delegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -937,6 +941,15 @@
path = API;
sourceTree = "<group>";
};
4B8469A423EAA77100EE49FA /* OpenChat */ = {
isa = PBXGroup;
children = (
4B8469A523EAA7AA00EE49FA /* LineSDKOpenChatRoomStatus.swift */,
4B8469A723EAA7BD00EE49FA /* LineSDKOpenChatRoomMembershipState.swift */,
);
path = OpenChat;
sourceTree = "<group>";
};
4B87E44822E55755005AA4D2 /* LineSDKUI */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1220,6 +1233,7 @@
4BBEA9AD212EAFFB00858627 /* Login */,
4BC9B2DC212FB7100071C736 /* Social */,
4BC66AE322EA8A4500546FB6 /* Sharing */,
4B8469A423EAA77100EE49FA /* OpenChat */,
4BC9B2E5212FC9E30071C736 /* Messaging */,
4B2D14FB212F9FA5000DD5BE /* Networking */,
4BC9B2D7212FAD9E0071C736 /* Utils */,
Expand Down Expand Up @@ -2187,6 +2201,7 @@
4BC9B2E0212FB7B60071C736 /* LineSDKGroup.swift in Sources */,
4B4A9AF32159FCF700915054 /* LineSDKConstant.swift in Sources */,
4BDD2C382133F34300DD563D /* LineSDKFlexBoxComponent.swift in Sources */,
4B8469A623EAA7AA00EE49FA /* LineSDKOpenChatRoomStatus.swift in Sources */,
4B2D14E9212F9270000DD5BE /* LineSDKAccessTokenVerifyResult.swift in Sources */,
4BDD2C1A2133A5E300DD563D /* LineSDKTemplateCarouselPayload.swift in Sources */,
4BC9B2DE212FB7230071C736 /* LineSDKUser.swift in Sources */,
Expand Down Expand Up @@ -2214,6 +2229,7 @@
4BDD2C2E2133F2EA00DD563D /* LineSDKFlexImageComponent.swift in Sources */,
4BDD2C322133F30A00DD563D /* LineSDKFlexIconComponent.swift in Sources */,
4BBEA9B6212EB41000858627 /* LineSDKAccessToken.swift in Sources */,
4B8469A823EAA7BD00EE49FA /* LineSDKOpenChatRoomMembershipState.swift in Sources */,
4BC4B3DD212FED4300750794 /* LineSDKVideoMessage.swift in Sources */,
4BC66AE522EA8A6900546FB6 /* LineSDKMessageSendingToken.swift in Sources */,
4BC4B3E4212FF86100750794 /* LineSDKAudioMessage.swift in Sources */,
Expand Down
26 changes: 24 additions & 2 deletions LineSDK/LineSDK/Networking/API/API.swift
Expand Up @@ -43,7 +43,8 @@ public enum API {
///
public static func getProfile(
callbackQueue queue: CallbackQueue = .currentMainOrAsync,
completionHandler completion: @escaping (Result<UserProfile, LineSDKError>) -> Void)
completionHandler completion: @escaping (Result<UserProfile, LineSDKError>) -> Void
)
{
let request = GetUserProfileRequest()
Session.shared.send(request, callbackQueue: queue, completionHandler: completion)
Expand All @@ -59,9 +60,30 @@ public enum API {
///
public static func getBotFriendshipStatus(
callbackQueue queue: CallbackQueue = .currentMainOrAsync,
completionHandler completion: @escaping (Result<GetBotFriendshipStatusRequest.Response, LineSDKError>) -> Void)
completionHandler completion: @escaping (Result<GetBotFriendshipStatusRequest.Response, LineSDKError>) -> Void
)
{
let request = GetBotFriendshipStatusRequest()
Session.shared.send(request, callbackQueue: queue, completionHandler: completion)
}

public static func getOpenChatRoomStatus(
squareMid: EntityID,
callbackQueue queue: CallbackQueue = .currentMainOrAsync,
completionHandler completion: @escaping (Result<GetOpenChatRoomStatusRequest.Response, LineSDKError>) -> Void
)
{
let request = GetOpenChatRoomStatusRequest(squareMid: squareMid)
Session.shared.send(request, callbackQueue: queue, completionHandler: completion)
}

public static func getOpenChatRoomMembershipState(
squareMid: EntityID,
callbackQueue queue: CallbackQueue = .currentMainOrAsync,
completionHandler completion: @escaping (Result<GetOpenChatRoomMembershipStateRequest.Response, LineSDKError>) -> Void
)
{
let request = GetOpenChatRoomMembershipStateRequest(squareMid: squareMid)
Session.shared.send(request, callbackQueue: queue, completionHandler: completion)
}
}
Expand Up @@ -29,7 +29,7 @@ public struct GetOpenChatRoomMembershipStateRequest: Request {
}

public struct Response: Decodable {
let state: State?
public let state: State
}

public let method: HTTPMethod = .get
Expand Down
Expand Up @@ -22,15 +22,16 @@
import Foundation

public struct GetOpenChatRoomStatusRequest: Request {

public enum Status: String, Decodable {
case alive = "ALIVE"
case deleted = "DELETED"
case suspended = "SUSPENDED"
}

public struct Response: Decodable {
let status: Status?

public struct Response: Codable {

public enum Status: String, Codable {
case alive = "ALIVE"
case deleted = "DELETED"
case suspended = "SUSPENDED"
}

public let status: Status
}

public let method: HTTPMethod = .get
Expand Down
43 changes: 43 additions & 0 deletions LineSDK/LineSDKObjC/Networking/LineSDKAPI.swift
Expand Up @@ -220,6 +220,49 @@ public class LineSDKAPI: NSObject {
withMessageToken: token._value,
callbackQueue: queue.unwrapped) { result in result.matchFailure(with: completion) }
}

// MARK: - Open Chat
public static func getOpenChatRoomStatus(
squareMid: String,
completionHandler completion: @escaping (LineSDKOpenChatRoomStatus?, Error?) -> Void
)
{
getOpenChatRoomStatus(
squareMid: squareMid, callbackQueue: .currentMainOrAsync, completionHandler: completion
)
}

public static func getOpenChatRoomStatus(
squareMid: String,
callbackQueue queue: LineSDKCallbackQueue,
completionHandler completion: @escaping (LineSDKOpenChatRoomStatus?, Error?) -> Void
)
{
API.getOpenChatRoomStatus(squareMid: squareMid, callbackQueue: queue.unwrapped) { result in
result.map(LineSDKOpenChatRoomStatus.init).match(with: completion)
}
}

public static func getOpenChatRoomMembershipState(
squareMid: String,
completionHandler completion: @escaping (LineSDKOpenChatRoomMembershipState?, Error?) -> Void
)
{
getOpenChatRoomMembershipState(
squareMid: squareMid, callbackQueue: .currentMainOrAsync, completionHandler: completion
)
}

public static func getOpenChatRoomMembershipState(
squareMid: String,
callbackQueue queue: LineSDKCallbackQueue,
completionHandler completion: @escaping (LineSDKOpenChatRoomMembershipState?, Error?) -> Void
)
{
API.getOpenChatRoomMembershipState(squareMid: squareMid, callbackQueue: queue.unwrapped) { result in
result.map(LineSDKOpenChatRoomMembershipState.init).match(with: completion)
}
}
}

// MARK: - getGroups
Expand Down
@@ -0,0 +1,32 @@
//
// LineSDKOpenChatRoomMembershipState.swift
//
// Copyright (c) 2016-present, LINE 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 LINE Corporation.
//
// As with any software that integrates with the LINE 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.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKOpenChatRoomMembershipState: NSObject {
let _value: GetOpenChatRoomMembershipStateRequest.Response
init(_ value: GetOpenChatRoomMembershipStateRequest.Response) { _value = value }

public var state: String { return _value.state.rawValue }
}
33 changes: 33 additions & 0 deletions LineSDK/LineSDKObjC/OpenChat/LineSDKOpenChatRoomStatus.swift
@@ -0,0 +1,33 @@
//
// LineSDKOpenChatRoomStatus.swift
//
// Copyright (c) 2016-present, LINE 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 LINE Corporation.
//
// As with any software that integrates with the LINE 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.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKOpenChatRoomStatus: NSObject {
let _value: GetOpenChatRoomStatusRequest.Response
init(_ value: GetOpenChatRoomStatusRequest.Response) { _value = value }
public var status: String { return _value.status.rawValue }

public var json: String? { return toJSON(_value) }
}
30 changes: 30 additions & 0 deletions LineSDK/LineSDKObjCInterfaceTests/LineSDKAPIInterfaceTests.m
Expand Up @@ -162,4 +162,34 @@ - (void)_testMultiSendMessageWithMessageTokenInterface {
completionHandler:^(NSError *error) {}];
}

- (void)_testGetOpenChatRoomStatusInterface {
[LineSDKAPI
getOpenChatRoomStatusWithSquareMid:@""
completionHandler:^(LineSDKOpenChatRoomStatus *result, NSError *error) {
NSLog(@"%@", result.status);
}];

[LineSDKAPI
getOpenChatRoomStatusWithSquareMid:@""
callbackQueue:[LineSDKCallbackQueue asyncMain]
completionHandler:^(LineSDKOpenChatRoomStatus *result, NSError *error) {
NSLog(@"%@", result.status);
}];
}

- (void)_testGetOpenChatRoomMembershipState {
[LineSDKAPI
getOpenChatRoomMembershipStateWithSquareMid:@""
completionHandler:^(LineSDKOpenChatRoomMembershipState *result, NSError *error) {
NSLog(@"%@", result.state);
}];

[LineSDKAPI
getOpenChatRoomMembershipStateWithSquareMid:@""
callbackQueue:[LineSDKCallbackQueue asyncMain]
completionHandler:^(LineSDKOpenChatRoomMembershipState *result, NSError *error) {
NSLog(@"%@", result.state);
}];
}

@end

0 comments on commit d752335

Please sign in to comment.