Dingle Swift
Dingle Generator for Swift
Installation
$ npm install --save dingle-swift
Dependancies
You will need the following module in your project:
pod 'SwiftyJSON' '~> 2.2.0'pod 'AFNetworking' '~> 2.0'pod 'CocoaAsyncSocket' '~> 7.4.0'
Usage
Simply require the dingle generator module and specify the directory to build into:
var dingle = http_listen: '0.0.0.0' https_listen: '0.0.0.0' tcp_listen: '0.0.0.0' udp_listen: '0.0.0.0'; var generator = ;generator;
Then simply drop the files generated into your XCode project and use like so:
var myapi = require('./MYAPI.js'); myapi.login("admin@myawesomeapi.com", password: "mypassword") { (success, message, output) -> () in println(success) println(message) println(output)}
Hostnames
When the code is generated your hostnames are automatically taken from the dingle config but you can change it like so:
var myapi = MYAPI(); myapi.hostnames["http"] = "localhost:7691"myapi.hostnames["https"] = "localhost:7692"myapi.hostnames["tcp"] = "localhost:7693"myapi.hostnames["udp"] = "localhost:7694" myapi.login("admin@myawesomeapi.com", password: "mypassword") { (success, message, output) -> () in println(success) println(message) println(output)}
File Uploads
To upload a file simply specify a NSURL as a parameter as shown below:
var myapi = ; myapi
File Downloads
When downloading a file you must specify a NSOutputStream to write to and once the download is complete the stream will be returned in the output variable callback:
var myapi = ; myapi
Choosing Method
By default dingle will auto choose each method depending on the order of which they are specified in the function but we can override this like so:
var myapi = MYAPI(); myapi.login("admin@myawesomeapi.com", password: "mypassword", methods: [ "POST", "TCP" ]) { (success, message, output) -> () in println(success) println(message) println(output)}
Methods
The following methods are supported:
- TCP
- UDP
- POST
- GET
- PUT
- DELETE
- OPTIONS
- HEAD
- PATCH
- TRACE
- CONNECT