jsdw_ios/QuickLocation/API/PigeonAPI.swift

85 lines
2.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PigeonAPI.swift
// QuickLocation
//
import Moya
internal import Alamofire
enum PigeonAPI {
///
/// - Parameters:
/// - groupKey: key
/// - toUsers: id
/// - msgType: 2 3
/// - msg: file id
/// - bgImg: file id 0
/// - expireTime: 0 7
case send(
groupKey: String,
toUsers: [String],
msgType: Int,
msg: String,
bgImg: Int64,
expireTime: Int,
extra: [String: Any]?
)
///
case sent(groupKey: String)
///
case inbox
///
case burn(messageUUID: String)
}
extension PigeonAPI: MultiTargetProtocol {
var path: String {
switch self {
case .send:
return "mapi/pigeon/send"
case .sent:
return "mapi/pigeon/sent"
case .inbox:
return "mapi/pigeon/inbox/messages"
case .burn:
return "mapi/pigeon/burn"
}
}
var method: Moya.Method {
switch self {
case .sent, .inbox:
return .get
case .send, .burn:
return .post
}
}
var task: Moya.Task {
switch self {
case let .send(groupKey, toUsers, msgType, msg, bgImg, expireTime, extra):
var params = Parameters()
params["group_key"] = groupKey
params["to_user"] = toUsers
params["msg_type"] = msgType
params["msg"] = msg
params["bg_img"] = bgImg
params["expire_time"] = expireTime
if let extra {
params["extra"] = extra
}
return .requestParameters(parameters: params, encoding: JSONEncoding())
case let .sent(groupKey):
var params = Parameters()
if !groupKey.isEmpty {
params["group_key"] = groupKey
}
return .requestParameters(parameters: params, encoding: URLEncoding())
case .inbox:
return .requestParameters(parameters: Parameters(), encoding: URLEncoding())
case let .burn(messageUUID):
return .requestParameters(parameters: ["message_uuid": messageUUID], encoding: JSONEncoding())
}
}
}