Last active
November 16, 2016 08:32
-
-
Save tharindu/72c709e9a0d330ef8154321dea548da4 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
// | |
// HVRequest.swift | |
// Hiveage | |
// | |
// Created by Tharindu on 12/27/15. | |
// Copyright © 2015 Vesess Inc. All rights reserved. | |
// | |
import Foundation | |
import Alamofire | |
import SwiftyJSON | |
enum HVRequestType: NSInteger { | |
case get = 0, post, put, delete, custom | |
} | |
typealias HVRequestCompletionHandler = (_ success: Bool, _ request: HVRequest) -> Void | |
class HVRequest: NSObject { | |
var subdomain: String | |
var auth_token: String | |
var type: HVRequestType | |
var command: String | |
var completionHandler: HVRequestCompletionHandler | |
init(subdomain: String, token: String, type: HVRequestType, command: String, handler: @escaping HVRequestCompletionHandler) { | |
self.subdomain = subdomain | |
self.auth_token = token | |
self.type = type | |
self.command = command | |
self.completionHandler = handler | |
} | |
func request() { | |
// implements sending request | |
} | |
func handleResponse(_ response: Alamofire.DataResponse<Any>) { | |
// implements handling response | |
} | |
func validateResponse(_ json: JSON) -> Bool { | |
return false | |
} | |
func parseResponse(_ json: JSON) { | |
// implement parsing in request subclass | |
} | |
func cancelRequest() { | |
// cancels request | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment