123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- //
- // JPushAPI.swift
- // O2Platform
- //
- // Created by FancyLou on 2019/11/8.
- // Copyright © 2019 zoneland. All rights reserved.
- //
- import Moya
- // x_jpush_assemble_control 极光推送模块
- enum JPushAPI {
- case bindDevice(JPushDevice)
- case unBindDevice(String)
-
- }
- // 上下文根
- extension JPushAPI: OOAPIContextCapable {
- var apiContextKey: String {
- return "x_jpush_assemble_control"
- }
- }
- // 是否需要xtoken
- extension JPushAPI: OOAccessTokenAuthorizable {
- var shouldAuthorize: Bool {
- return true
- }
- }
- extension JPushAPI: TargetType {
-
-
- var baseURL: URL {
- let model = O2AuthSDK.shared.o2APIServer(context: .x_jpush_assemble_control)
- let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
- return URL(string: baseURLString)!
- }
-
-
- var path: String {
- switch self {
- case .bindDevice(_):
- return "/jaxrs/device/bind"
- case .unBindDevice(let deviceName):
- return "/jaxrs/device/unbind/\(deviceName)/ios"
- }
- }
-
- var method: Moya.Method {
- switch self {
- case .bindDevice(_):
- return .post
- case .unBindDevice(_):
- return .delete
- }
- }
-
- var sampleData: Data {
- return "".data(using: String.Encoding.utf8)!
- }
-
- var task: Task {
- switch self {
- case .bindDevice(let device):
- return .requestParameters(parameters: device.toJSON()!, encoding: JSONEncoding.default)
- case .unBindDevice:
- return .requestPlain
- }
- }
-
- var headers: [String : String]? {
- return nil
- }
-
- }
|