Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wilddylan/networksdk
Swift NetworkSDK
https://github.com/wilddylan/networksdk
network
Last synced: about 1 month ago
JSON representation
Swift NetworkSDK
- Host: GitHub
- URL: https://github.com/wilddylan/networksdk
- Owner: wilddylan
- License: mit
- Created: 2016-11-23T06:27:04.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-07T08:19:25.000Z (about 8 years ago)
- Last Synced: 2024-11-18T04:47:51.407Z (about 2 months ago)
- Topics: network
- Language: Swift
- Size: 667 KB
- Stars: 2
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Network
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)
open source NetworkSDK based on Alamofire
###### Example
```swift
import NetworkSDK
import ObjectMapper
```some configurations:
```swift
Network.defaultHeader = ["a": "b", "c": "d"]
Network.baseURL = "http://192.168.199.173"
```use objectMapper, create a model:
```swift
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:
```swift
let request = NetworkRequest("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
```swift
Network.baseURL = "http://ocef2grmj.bkt.clouddn.com"// http://ocef2grmj.bkt.clouddn.com
// LLWeChat-master.zip 75.8MB
// 1083748_3.jpg 51.67kblet documentURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentURL.appendingPathComponent("b.png")let downloadRequest = NetworkRequest>("Group.png", destination: fileURL, true)
downloadRequest.download({if $1 == nil { //
print($0)
}
}, {
debugPrint($0.fractionCompleted)
})
```###### Upload request
```swift
let multipartdata: (Data, String, String, String) = (data!, "fileData", "a.png", "image/png")
let uploadRequest = NetworkRequest>("uploadResources.json", [multipartdata], ["category": "HEAD"])
uploadRequest.baseURL = "http://your.domain.com"uploadRequest.upload({
debugPrint($0 ?? "")
debugPrint($1 ?? "")
}, {
debugPrint("upload", $0.fractionCompleted)
})```
###### Multi download request
```swift
let documentURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let fileURL = documentURL.appendingPathComponent("b.jpg")let downloadRequest0 = NetworkRequest>("Group.png", destination: fileURL, true)
let downloadRequest1 = NetworkRequest>("1083748_3.jpg", destination: fileURL, true)NetworkMultiRequest>().download([downloadRequest0, downloadRequest1], handler: { object in
print(object)
}, { progress in
print("0:", progress.fractionCompleted)
}, { progress in
print("1:", progress.fractionCompleted)
})
```###### Others
debug log:
```swift
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](http://www.devdylan.cn/NetworkSDK/0.2.3-beta/api/)
###### Installation
Network is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod "NetworkSDK", "~> 0.2.3"
```dependency version:
```ruby
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.