123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- //
- // 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<String, Any>)
- case communityMemberFollowTopic(parameters:Dictionary<String, Any>)
- case communityPostMy(parameters:Dictionary<String, Any>)
- case communityTopics(parameters:Dictionary<String, Any>)
- case communityPosts(parameters:Dictionary<String, Any>)
- }
- 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])
- }
- }
-
- }
|