All Downloads are FREE. Search and download functionalities are using the official Maven repository.

swift.APIs.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
// APIs.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation

public class {{projectName}}API {
    public static var basePath = "{{{basePath}}}"
    public static var credential: NSURLCredential?
    public static var customHeaders: [String:String] = [:]  
    static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory()
}

public class APIBase {
    func toParameters(encodable: JSONEncodable?) -> [String: AnyObject]? {
        let encoded: AnyObject? = encodable?.encodeToJSON()

        if encoded! is [AnyObject] {
            var dictionary = [String:AnyObject]()
            for (index, item) in (encoded as! [AnyObject]).enumerate() {
                dictionary["\(index)"] = item
            }
            return dictionary
        } else {
            return encoded as? [String:AnyObject]
        }
    }
}

public class RequestBuilder {
    var credential: NSURLCredential?
    var headers: [String:String]
    let parameters: [String:AnyObject]?
    let isBody: Bool
    let method: String
    let URLString: String
    
    /// Optional block to obtain a reference to the request's progress instance when available.
    public var onProgressReady: ((NSProgress) -> ())?

    required public init(method: String, URLString: String, parameters: [String:AnyObject]?, isBody: Bool, headers: [String:String] = [:]) {
        self.method = method
        self.URLString = URLString
        self.parameters = parameters
        self.isBody = isBody
        self.headers = headers
        
        addHeaders({{projectName}}API.customHeaders)
    }
    
    public func addHeaders(aHeaders:[String:String]) {
        for (header, value) in aHeaders {
            headers[header] = value
        }
    }
    
    public func execute(completion: (response: Response?, error: ErrorType?) -> Void) { }

    public func addHeader(name name: String, value: String) -> Self {
        if !value.isEmpty {
            headers[name] = value
        }
        return self
    }
    
    public func addCredential() -> Self {
        self.credential = {{projectName}}API.credential
        return self
    }
}

protocol RequestBuilderFactory {
    func getBuilder() -> RequestBuilder.Type
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy