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
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"] |
|
} |
|
|
|
}
|
|
|