Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Marvel.swift
- // ntierMVC
- //
- // Created by Marin Nikolić on 14/09/2018.
- // Copyright © 2018 Marin Nikolić. All rights reserved.
- //
- import Foundation
- import Moya
- public enum Marvel {
- case showUser(id: Int)
- case login(user: UserLoginRequest)
- case register(user: UserRegistrationRequest)
- }
- extension Marvel :TargetType {
- public var baseURL: URL {
- return URL(string: "https://gateway.marvel.com/v1/public")!
- }
- public var path: String {
- switch self {
- case .showUser(let id): return "/user/\(id)"
- case .login(_): return "/login"
- case .register(_): return "/register"
- }
- }
- public var method: Moya.Method {
- switch self {
- case .showUser(_): return .post
- case .login(_): return .post
- case .register(_): return .post
- }
- }
- public var sampleData: Data {
- return Data()
- }
- public var task: Task {
- switch self {
- case .showUser(let id):
- return .requestParameters(
- parameters: [
- "id": id
- ],encoding: JSONEncoding.default)
- case .login(let user):
- return .requestParameters(
- parameters: [
- "username" : user.username.value ?? "",
- "password" : user.password.value ?? ""
- ], encoding: JSONEncoding.default)
- case .register(let user):
- return .requestParameters(
- parameters: [
- "username" : user.username.value ?? "",
- "password" : user.password.value ?? "",
- "repeatedPassword" : user.repeatedPassword.value ?? "",
- "email" : user.email.value ?? ""
- ], encoding: JSONEncoding.default)
- }
- }
- public var headers: [String : String]? {
- return ["Content-Type": "application/json"]
- }
- // 7
- public var validationType: ValidationType {
- return .successCodes
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement