You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

86 lines
3.3 KiB

//
// APIManager.swift
// Lookfit
//
// Created by lemo. on 2020/4/22.
// Copyright © 2020 Sheldon. All rights reserved.
//
import Foundation
import Moya
enum APIManager {
///
case getLastAppUpgrade(packageName: String)
///
case getHeFengLiveWeather(lang: String = "en", lat: String, lon: String, unit: String = "m")
///
case getHeFengForecastWeather(lang: String = "en", lat: String, lon: String, unit: String = "m")
///
case downLoad(url: String)
///
case wechatGetCode(deviceMac: String)
///
case dialList(performType: String = "APP", appType: Int)
///
case getDeviceFunByBrandCode(brandCode: Int)
}
extension APIManager: TargetType {
var baseURL: URL {
return URL(string: baseUrl)!
}
var path: String {
switch self {
case .getLastAppUpgrade: return getLastAppUpgradeLogUrl
case .getHeFengLiveWeather: return getHeFengLiveWeatherUrl
case .getHeFengForecastWeather: return getHeFengForecastWeatherUrl
case .downLoad(let url): return url
case .wechatGetCode: return wechatGetCodeUrl
case .dialList: return dialListUrl
case .getDeviceFunByBrandCode: return getDeviceFunByBrandCodeUrl
}
}
var method: Moya.Method {
switch self {
case .downLoad: return .get
default: return .post
}
}
var sampleData: Data {
return "".data(using: String.Encoding.utf8)!
}
var task: Task {
switch self {
case .getLastAppUpgrade(let packageName):
let params = ["packageName": packageName, "performType": "BLE"]
return .requestParameters(parameters: params, encoding: JSONEncoding.default)
case let .getHeFengLiveWeather(lang, lat, lon, unit):
let params = ["lang": lang, "lat": lat, "lon": lon, "unit": unit]
return .requestParameters(parameters: params, encoding: JSONEncoding.default)
case let .getHeFengForecastWeather(lang, lat, lon, unit):
let params = ["lang": lang, "lat": lat, "lon": lon, "unit": unit]
return .requestParameters(parameters: params, encoding: JSONEncoding.default)
case .downLoad: return .requestPlain
case .wechatGetCode(deviceMac: let deviceMac):
let mac = deviceMac.components(separatedBy: ":").joined()
let params = ["deviceId": mac.lowercased(), "deviceMac": mac.lowercased()]
return .requestParameters(parameters: params, encoding: JSONEncoding.default)
case .dialList(performType: let performType, appType: let appType):
let params = ["performType": performType, "appType": ("1" + "\(appType)").integerValue] as [String : Any]
return .requestParameters(parameters: params, encoding: JSONEncoding.default)
case .getDeviceFunByBrandCode(brandCode: let brandCode):
let params = ["brandCode": brandCode]
return .requestParameters(parameters: params, encoding: JSONEncoding.default)
}
}
var headers: [String : String]? {
return ["Content-Type": "application/json"]
}
}