Latest 0.2.3-beta
Homepage https://github.com/WildDylan/NetworkSDK
License MIT
Platforms ios 8.0
Dependencies ObjectMapper, Alamofire
Frameworks UIKit, Foundation
Authors

Network

MIT Licence

open source NetworkSDK based on Alamofire

Example
import NetworkSDK
import ObjectMapper

some configurations:

Network.defaultHeader = ["a": "b", "c": "d"]
Network.baseURL = "http://192.168.199.173"

use objectMapper, create a model:

struct Options: Mappable {
  var imageUri: String?
  var message: String?
  var dataPath: String?
  var userUri: String?
  var status: String?
  var dataVersion: String?
  var bizUri: String?

  init?(map: Map) {

  }

  mutating func mapping(map: Map) {
    imageUri    <- map["imageUri"]
    message     <- map["message"]
    dataPath    <- map["dataPath"]
    userUri     <- map["userUri"]
    status      <- map["status"]
    dataVersion <- map["dataVersion"]
    bizUri      <- map["bizUri"]
  }
}

then, fire:

let request = NetworkRequest<Options>("call.json")

request.send {
  if let option = $0 {
    print(option.toJSON())
  } else {
    print($1 ?? Error())
}

code above will send request like:

http://192.168.199.173/call.json
Download request
Network.baseURL = "http://ocef2grmj.bkt.clouddn.com"

// http://ocef2grmj.bkt.clouddn.com
// LLWeChat-master.zip 75.8MB
// 1083748_3.jpg 51.67kb

let documentURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentURL.appendingPathComponent("b.png")

let downloadRequest = NetworkRequest<NetworkModel<Any>>("Group.png", destination: fileURL, true)
downloadRequest.download({

  if $1 == nil { //
    print($0) 
  }
}, {
  debugPrint($0.fractionCompleted)
})
Upload request
let multipartdata: (Data, String, String, String) = (data!, "fileData", "a.png", "image/png")
let uploadRequest = NetworkRequest<NetworkModel<Any>>("uploadResources.json", [multipartdata], ["category": "HEAD"])
uploadRequest.baseURL = "http://your.domain.com"

uploadRequest.upload({ 
  debugPrint($0 ?? "")
  debugPrint($1 ?? "")
}, {
  debugPrint("upload", $0.fractionCompleted)
})
Multi download request
let documentURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentURL.appendingPathComponent("b.jpg")

let downloadRequest0 = NetworkRequest<NetworkModel<Any>>("Group.png", destination: fileURL, true)
let downloadRequest1 = NetworkRequest<NetworkModel<Any>>("1083748_3.jpg", destination: fileURL, true)

NetworkMultiRequest<NetworkModel<Any>>().download([downloadRequest0, downloadRequest1], handler: { object in
  print(object)
}, { progress in
  print("0:", progress.fractionCompleted)
}, { progress in
  print("1:", progress.fractionCompleted)
})
Others

debug log:

Network.debug = false
Features
  • [x] Simple for use
  • [x] Custom request
  • [x] Load from URLCache when remote load failed
  • [x] Simple for resuming a download request safer
  • [x] Simple upload
  • [X] Multi download
API docs

docs

Installation

Network is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "NetworkSDK", "~> 0.2.3"

dependency version:

dependency 'ObjectMapper', '~> 2.2.1'
dependency 'Alamofire', '~> 4.1.0'
Author

Dylan, [email protected]

License

Network is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "NetworkSDK",
    "version": "0.2.3-beta",
    "summary": "Network with object mapping and request queue.",
    "description": "Network with object mapping and muti task queue.",
    "homepage": "https://github.com/WildDylan/NetworkSDK",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Dylan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/WildDylan/NetworkSDK.git",
        "tag": "0.2.3-beta"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "NetworkSDK/*.swift",
    "frameworks": [
        "UIKit",
        "Foundation"
    ],
    "dependencies": {
        "ObjectMapper": [
            "~> 2.2.1"
        ],
        "Alamofire": [
            "~> 4.1.0"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This