Created
October 31, 2016 18:19
-
-
Save hprobotic/f6cf42002b51b2f48730d9721bba66d2 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
// | |
// SLBKAPIRouter.swift | |
// SolarBK | |
// | |
// Created by JohnP on 11/1/16. | |
// Copyright © 2016 JohnP. All rights reserved. | |
// | |
import Foundation | |
import Alamofire | |
enum SLBKAPIRouter: URLRequestConvertible { | |
static let baseURLString: String = "https://ssoc.solarbk.vn" | |
case GetSavingData() | |
var URLRequest: NSMutableURLRequest { | |
var method: HTTPMethod { | |
switch self { | |
case .GetSavingData(): | |
return .get | |
default: | |
return .get | |
} | |
} | |
let url: NSURL = { | |
let relativePath: String? | |
switch self { | |
case .GetSavingData: | |
relativePath = "api/mobile/saving/total" | |
default: | |
relativePath = "" | |
} | |
var URL = NSURL(string: APIRouter.baseURLString)! | |
if let relativePath = relativePath { | |
URL = URL.URLByAppendingPathComponent(relativePath) | |
} | |
return URL | |
} | |
var encoding: ParameterEncoding { | |
switch self { | |
case .GetSavingData(): | |
return Alamofire.ParameterEncoding.encode(URL) as! ParameterEncoding as! ParameterEncoding | |
default: | |
return Alamofire.ParameterEncoding.encode(JSON) | |
} | |
} | |
let params: ([String: AnyObject]?) = { | |
switch self { | |
case .GetSavingData(): | |
return (nil) | |
default: | |
return (nil) | |
} | |
} | |
let URLRequest = NSMutableURLRequest(url: url) | |
let (encodedRequest, _) = encoding.encode(URLRequest, with: params) | |
encodedRequest.HTTPMethod = method.rawValue | |
return enco | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment