LoginApi.swift 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //
  2. // LoginApi.swift
  3. // SolarStationSwift
  4. //
  5. // Created by weclouds on 2018/8/3.
  6. // Copyright © 2018年 weclouds. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. import Alamofire
  11. //import RxSwift
  12. //import RxCocoa
  13. let LoginProvider = MoyaProvider<LoginAPI>()
  14. enum LoginAPI {
  15. case common_login(username:String, client_key:String, password:String,os:String)
  16. }
  17. extension LoginAPI:TargetType {
  18. var base :String {
  19. return moyaBase
  20. }
  21. //请求的url
  22. public var baseURL: URL {return URL(string:base)!}
  23. //详细的路径
  24. public var path:String {
  25. switch self {
  26. case .common_login:
  27. return "/common/login"
  28. }
  29. }
  30. //请求的方式
  31. public var method: Moya.Method {
  32. switch self {
  33. case .common_login :
  34. return .post
  35. }
  36. }
  37. //单元测试用
  38. public var sampleData:Data {
  39. switch self {
  40. case .common_login:
  41. return stubbedResponse("common_login")
  42. }
  43. }
  44. //任务
  45. public var task: Task {
  46. switch self {
  47. case .common_login(let username, let client_key, let password,let os):
  48. return .requestParameters(parameters: [
  49. "username":username,
  50. "client_key": client_key,
  51. "password": password,
  52. "os":os
  53. ], encoding: URLEncoding.default)
  54. }
  55. }
  56. //请求头信息
  57. public var headers: [String : String]? {
  58. return nil
  59. }
  60. }