Created
May 3, 2017 15:07
-
-
Save popochess/ef0299ba60a67ae03bef4a24182ace69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ApiManager.swift | |
// | |
// Created by ben | |
// Copyright © 2017年 popochess. All rights reserved. | |
// | |
import UIKit | |
import Alamofire | |
public class ApiManager: NSObject,URLSessionDelegate { | |
let defaultSessionConfig :URLSessionConfiguration = URLSessionConfiguration.default | |
static func request( | |
endpoint: Endpoint.Api, | |
completionHandler: @escaping (DataResponse<Any>) -> Void) | |
-> Request | |
{ | |
let headers = [ | |
"Content-Type": "application/json", | |
"Accept": "application/json" | |
] | |
print("path:\(endpoint.path)") | |
let request = Alamofire.request( | |
endpoint.path, | |
method: endpoint.method, | |
parameters: endpoint.parameters, | |
encoding: URLEncoding.default, | |
headers: headers | |
).responseJSON { (response) -> Void in | |
switch response.result { | |
case Result.success(let value): | |
print(value) | |
break | |
case Result.failure(let encodingError): | |
print(encodingError) | |
if let resCode = response.response?.statusCode { | |
print(resCode) | |
} | |
break | |
} | |
completionHandler(response) | |
} | |
return request | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment