Swiftpack.co - emvakar/EKNetworking as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by emvakar.
emvakar/EKNetworking 1.2.6
Networking
⭐️ 2
🕓 6 days ago
iOS macOS
.package(url: "https://github.com/emvakar/EKNetworking.git", from: "1.2.6")

Swift Version Build and Test

Support EKNetworking development by giving a ⭐️

Installation

Swift Package Manager

    .package(url: "https://github.com/emvakar/EKNetworking.git", from: "1.2.3")

Usage

File: NetworkRequestProvider.swift

import UIKit
import EKNetworking

// Creating NetworkRequestProvider

final class NetworkRequestProvider {

    /// Maybe your own implementation class, subcalssing from EKNetworkRequestWrapperProtocol or use default impl EKNetworkRequestWrapper()
    let networkWrapper: EKNetworkRequestWrapperProtocol = EKNetworkRequestWrapper()
    
    /// Your own implementation for token refreshing, subcalssing from EKNetworkTokenRefresherProtocol
    let tokenRefresher: EKNetworkTokenRefresherProtocol? = nil
    
    /// pass your account manager based on EKAccountWriteProtocol
    let accountWrite: EKAccountWriteProtocol
    
    /// pass your account manager based on EKAccountReadProtocol
    let accountRead: EKAccountReadProtocol
    
    init(networkWrapper: EKNetworkRequestWrapperProtocol = EKNetworkRequestWrapper(logging: logger), tokenRefresher: NetworkTokenRefresherProtocol? = nil, accountWrite: AccountWriteProtocol, accountRead: AccountReadProtocol) {
        self.networkWrapper = networkWrapper
        self.tokenRefresher = tokenRefresher
        self.accountWrite = accountWrite
        self.accountRead = accountRead
    }

}

File: ExampleRequest.swift

import EKNetworking

// Our request target ApiRequestGetTodosFeed
struct ApiRequestGetTodosFeed: EKNetworkRequest {

    let page: Int
    let per: Int
    
    var path: String { "/api/v1/posts" }

    var method: EKRequestHTTPMethod { .get }

    var urlParameters: [String : Any]? {
        return ["per": per, "page": page]
    }

    /* of course you can pass bodyParameters: [String : Any]?
    var bodyParameters: [String : Any]? {
        return ["per": per, "page": page]
    }
    */
    
    // All passed params you can see at EKNetworkRequest.swift
}

// NetworkTodoProtocol for extension

protocol NetworkTodoProtocol {
    func todosTimeline(page: Int, perPage: Int, completion: ((_ posts: [TodoModel]?, _ error: EKNetworkError?) -> Void)?)
}

extension NetworkRequestProvider: NetworkTodoProtocol {

    func todosTimeline(page: Int, perPage: Int, completion: ((_ posts: [TodoModel]?, _ error: EKNetworkError?) -> Void)?) {
        let request = ApiRequestGetTodosFeed(page: page, per: perPage)
        runRequest(request, progressResult: nil) { [weak self] statusCode, response, error in
        
            // do somthing with response
        
            // response is EKResponse aka 
            // Represents a response to a `MoyaProvider.request`.
            // final class Response: CustomDebugStringConvertible, Equatable
        }
    }
    
}

GitHub

link
Stars: 2
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Release 1.2.5
1 week ago

Version 1.2.5

What's Changed

Full Changelog: https://github.com/emvakar/EKNetworking/compare/1.2.3...1.2.5

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics