Mixonomer-iOS/Mixonomer/Network/AuthApi.swift

69 lines
1.5 KiB
Swift
Raw Normal View History

2022-08-08 20:40:38 +01:00
//
// AuthApi.swift
// Mixonomer
//
// Created by Andy Pack on 08/08/2022.
// Copyright © 2022 Sarsoo. All rights reserved.
//
import Foundation
import Alamofire
import SwiftyJSON
public enum AuthApi {
2022-08-09 17:42:01 +01:00
case token(username: String, password: String, expiry: Int)
2022-08-10 23:18:22 +01:00
case register(username: String, password: String, password2: String)
2022-08-08 20:40:38 +01:00
}
extension AuthApi: ApiRequest {
var domain: String {
return ApiRequestDefaults.domain
}
var path: String {
switch self {
case .token:
return "auth/token"
2022-08-10 23:18:22 +01:00
case .register:
return "auth/register"
2022-08-08 20:40:38 +01:00
}
}
var httpMethod: HTTPMethod {
switch self {
case .token:
return .post
2022-08-10 23:18:22 +01:00
case .register:
return .post
2022-08-08 20:40:38 +01:00
}
}
var parameters: JSON? {
switch self {
2022-08-09 17:42:01 +01:00
case .token(let username, let password, let expiry):
return JSON(["username": username, "password": password, "expiry": expiry])
2022-08-10 23:18:22 +01:00
case .register(let username, let password, let password2):
return JSON(["username": username, "password": password, "password_again": password2])
2022-08-08 20:40:38 +01:00
}
}
var parameterType: ParameterEncoder? {
switch self {
case .token:
return JSONParameterEncoder.default
2022-08-10 23:18:22 +01:00
case.register:
return JSONParameterEncoder.default
2022-08-08 20:40:38 +01:00
}
}
var headers: HTTPHeaders? {
return nil
}
var authMethod: AuthMethod? {
return AuthMethod.none
}
}