jsdw_ios/QuickLocation/API/PigeonAPI.swift

74 lines
2.2 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: 1 图片 2 语音
/// - msg: 上传返回的 file id
/// - textMsg: 留言文本
/// - expireTime: 过期秒数,0 表示服务端默认 7 天
case send(groupKey: String, toUsers: [String], msgType: Int, msg: String, textMsg: String, expireTime: Int)
/// 已发送的传书记录
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, textMsg, expireTime):
var params = Parameters()
params["group_key"] = groupKey
params["to_user"] = toUsers
params["msg_type"] = msgType
params["msg"] = msg
params["text_msg"] = textMsg
params["expire_time"] = expireTime
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())
}
}
}