// // SwiftMoyaServiceCommunityApi.swift // RainbowPlanet // // Created by 南鑫林 on 2019/6/24. // Copyright © 2019 RainbowPlanet. All rights reserved. // import Foundation import Moya // MARK: - 话题组列表 /// 话题组列表 public let kCommunityTopicCategoryApi = "/community/topicCategory" // MARK: - 关注推荐话题 /// 关注推荐话题 public let kCommunityMemberFollowTopicApi = "/community/memberFollowTopic" // MARK: - 个人中心内容 /// 个人中心内容 public let kCommunityPostMyApi = "/community/post/my" // MARK: - 话题列表 /// 话题列表 public let kCommunityTopicsApi = "/community/topic" // MARK: - 内容列表 /// 内容列表 public let kCommunityPostsApi = "/community/post" /// 社区 /// /// - communityTopicCategory: 话题组列表 /// - communityMemberFollowTopic: 关注推荐话题 /// - communityPostMy: 个人中心内容 /// - communityTopics: 话题列表 /// - communityPosts: 内容列表 public enum SwiftMoyaServiceCommunityApi { case communityTopicCategory(parameters:Dictionary) case communityMemberFollowTopic(parameters:Dictionary) case communityPostMy(parameters:Dictionary) case communityTopics(parameters:Dictionary) case communityPosts(parameters:Dictionary) } extension SwiftMoyaServiceCommunityApi: TargetType { public var baseURL: URL { switch self { case .communityTopicCategory, .communityMemberFollowTopic, .communityPostMy, .communityTopics, .communityPosts : return URL(string: kApiDataPrefix())! } } public var path: String { switch self { case .communityTopicCategory: return kCommunityTopicCategoryApi case .communityMemberFollowTopic: return kCommunityMemberFollowTopicApi case .communityPostMy: return kCommunityPostMyApi case .communityTopics: return kCommunityTopicsApi case .communityPosts: return kCommunityPostsApi } } public var method: Moya.Method { switch self { case .communityMemberFollowTopic : return .post case .communityTopicCategory, .communityPostMy, .communityTopics, .communityPosts : return .get } } // MARK: - 请求任务事件(这里附带上参数) public var task: Task { switch self { case .communityTopicCategory(var parameters), .communityMemberFollowTopic(var parameters), .communityPostMy(var parameters), .communityTopics(var parameters), .communityPosts(var parameters) : let sign = SwiftSign.shared().sign(signType:.AccessToken, parameters: parameters) parameters.updateValue(sign, forKey: "sign") return .requestParameters(parameters: parameters, encoding: URLEncoding.default) } } // MARK: - 是否执行Alamofire验证 public var validate: Bool { return false } // MARK: - 这个就是做单元测试模拟的数据,只会在单元测试文件中有作用 public var sampleData: Data { return "{}".data(using: String.Encoding.utf8)! } // MARK: - 请求头 public var headers: [String : String]? { //同task,具体选择看后台 有application/x-www-form-urlencoded 、application/json switch self { case .communityTopicCategory, .communityMemberFollowTopic, .communityPostMy, .communityTopics, .communityPosts : return (headerParameters(headerType: .tokenHeader) as! [String : String]) } } }