Latest 1.0.0
Homepage https://github.com/GloomyMeng/GSNetwork
License MIT
Platforms ios 10.0, osx 10.12, tvos 10.0
Dependencies GSBasis, Alamofire
Authors

CI Status
Version
License
Platform

Features

  • [ ] Category, SPM installation
  • [ ] OAuth interceptor
  • [x] etc..

Usage

A simple network components, simple and clear API usage with only two files.

Support diverse data structure returns while guaranteeing type checking.

Unified error types and standard error handling.

Dependent on Alamofire

Define API list

First, initialized GSNetwork with a GSNetworkConfig

Network.config(config: GSNetworkConfig.init().then {
    $0.host = ""
    $0.customHeader = [:]
    //..//
})

Seconds, for different module need define different APIRoute

enum UserRoute: APIRoute {

    case userInfo(id: String)
    case upateInfo(user: User)
    case logout
    case login(username: String, password: String)

    var uri: String {
        switch self {
        case .userInfo(let id):                     return ""
        case .upateInfo(let user):                  return ""
        case .logout:                               return ""
        case .login(let username, let password):    return ""
        }
    }

    var parameters: [String : Any] { return [:] }

    var method: HTTPMethod {
        switch self {
        case .userInfo(let id):                     return .get
        case .upateInfo(let user):                  return .post
        case .logout:                               return .get
        case .login(let username, let password):    return .get
        }
    }

    var encodeType: HTTPEncodeType { return .json }

    func customHost() -> String? { return nil }
}

Lastly, start requst like this

UserRoute.logout.start(success: { (rs: APIReturn<Bool>) in
    // do something...
})

Requirements

  • iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
  • Xcode 10.2+
  • Swift 5+

Installation

Cocoapods

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

pod 'GSNetwork'

Author

[email protected], [email protected]

License

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

Latest podspec

{
    "name": "GSNetwork",
    "version": "1.0.0",
    "summary": "Network components of the GS series components",
    "description": "Network components of the GS series components. Depends on Alamofire.",
    "homepage": "https://github.com/GloomyMeng/GSNetwork",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "[email protected]": "[email protected]"
    },
    "source": {
        "git": "https://github.com/GloomyMeng/GSNetwork.git",
        "tag": "1.0.0"
    },
    "swift_versions": "5.0",
    "platforms": {
        "ios": "10.0",
        "osx": "10.12",
        "tvos": "10.0"
    },
    "source_files": "GSNetwork/Classes/**/*",
    "dependencies": {
        "GSBasis": [],
        "Alamofire": [
            "~> 5.0.0-beta.5"
        ]
    },
    "swift_version": "5.0"
}

Pin It on Pinterest

Share This