ronanrodrigo / Frisbee

Another network wrapper for URLSession. Built to be simple, small and easy to create tests at the network layer of your application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove (url: String) methods from protocol requirements

danielCarlosCE opened this issue · comments

Both Getable and Postable have methods that conveniently receives a url as String. The problem with this is that any object that adopts those protocols will have to add those methods as wells, and we can't be sure they will implement the right way - just validate the url and call the version with url: URl.

We could just create extensions to the protocols with those convenient methods implemented like so:

extension Getable {
    @discardableResult
    public func get<T: Decodable>(url: String, onComplete: @escaping OnComplete<T>) -> Cancellable {
        guard let url = URL(string: url) else {
            onComplete(.fail(FrisbeeError.invalidUrl))
            return NilCancellable()
        }
        return get(url: url, onComplete: onComplete)
    }
}

That way the client can still use URL as strings and we are sure it behaves correctly.