Skip to content

Instantly share code, notes, and snippets.

@tharindu
Last active November 16, 2016 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tharindu/72c709e9a0d330ef8154321dea548da4 to your computer and use it in GitHub Desktop.
Save tharindu/72c709e9a0d330ef8154321dea548da4 to your computer and use it in GitHub Desktop.
//
// 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