Shrimp

Shrimp is an simplify HTTP networking library.


Keywords
afnetworking, alamore, downloadmanager, http, https, ios, ios-downloader, network, networking, pause-download, resume-download, swift, swift-downloader
License
MIT
Install
pod try Shrimp

Documentation

Shrimp

Version Carthage compatible License Platform

Shrimp is an simplify HTTP networking library written in Swift.

Features

  • Chainable Request / Response Methods
  • Parameter Encoding
  • GET / POST / PUT / DELETE
  • Resume Download Datas
  • Download with Progress Notification
  • Upload files
  • Builtin JSON Request Serialization

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

GET

        ShrimpRequest().request(.GET, urlString: "https://httpbin.org/get")
        .responseString ({ (string, response) in
            debugPrint("GET: \(string)")
        })

POST

        ShrimpRequest().request(.POST, urlString: "http://www.mocky.io/v2/56c5b7a80f0000d027a204e2", parameters: ["username":"rafael",
            "password":"123456"])
        .responseJSONObject({ (json, response) in
                debugPrint(json["first_name"])
                debugPrint(json["last_name"])
                debugPrint(json["gender"])            
            }, errorHandler: { (error) in
                
        })

DOWNLOAD

Start Download

DownloadManager.download(withURL: downloadURLString, withDestPath: destPath)

Resume Download

DownloadManager.resumeDownload(withURL: downloadURLString, withDestPath: destPath)

Register Download Notifications

NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Start), object: nil)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Progress), object: nil)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Complete), object: nil)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Failed), object: nil)
NotificationCenter.default.addObserver(self, selector: SELECTOR ), name: NSNotification.Name(rawValue: Noti_DownloadManager_Cancel), object: nil)

Observe Notifications

func downloadProgress(noti:Notification) {
        let url = noti.userInfo!["url"] as! String
        let progress = noti.userInfo!["progress"] as! Float
        let bytesWritten = noti.userInfo!["bytesWritten"] as! Int64
        let totalBytesWritten = noti.userInfo!["totalBytesWritten"] as! Int64
        let totalBytesExpectedToWrite = noti.userInfo!["totalBytesExpectedToWrite"] as! Int64
        
        debugPrint("url:\(url),progress:\(progress),bytesWritten:\(bytesWritten),totalBytesWritten\(totalBytesWritten),totalBytesExpectedToWrite:\(totalBytesExpectedToWrite)")
        
        //url:http://www.abc.com/xyz.zip, progress :0.6, bytesWritten :30, totalBytesWritten :6000, totalBytesExpectedToWrite :10000 
            
}


func downloadComplete(noti:Notification) {
    let url = noti.userInfo!["url"] as! String
    let destPath = noti.userInfo!["destPath"] as! String

}

Other Methods

    DownloadManager.pauseDownload(withURL url:String)
    DownloadManager.pauseDownloadAll()
    DownloadManager.isDownloading(url:String)    
    DownloadManager.isHasResumDate(url:String)

Requirements

  • iOS 8.0+
  • Xcode 7.3
  • Swift 3.0.1

Installation

Cocoapods

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

# swift4 ,ios 10.0+
pod "Shrimp"

#swift3, ios 8.0+
pod "Shrimp", '== 0.2.1'

Carthage

If you're using Carthage, you can add a dependency on Shrimp by adding it to your Cartfile:

github "KevinZhouRafael/Shrimp"

Author

Rafael Zhou

License

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