Yoloabdo
5/31/2018 - 12:52 AM

UserRequest

enum UserRequest: URLRequestBuilder {

    case login(email: String, password: String)
    case register(name: String, email: String, password: String, phone: String)
    case userInfo

    // MARK: - Path
    internal var path: ServerPaths {
        switch self {
        case .login:
            return .login
        case .register:
            return .register
        case .userInfo:
            return .userInfo
        }
    }

    // MARK: - Parameters
    internal var parameters: Parameters? {
        var params = defaultParams
        switch self {
        case .login(let email, let password):
            params["email"] = email
            params["password"] = password
        case let .register(fullname, email, password, phone):
            params["email"] = email
            params["password"] = password
            params["password_confirmation"] = password
            params["phone"] = phone
            params["name"] = fullname
            params["mobile_id"] = deviceId
        default: break
        }
        return params
    }

    // MARK: - Methods
    internal var method: HTTPMethod {
        return .post
    }
}