ronanrodrigo/Frisbee

Remove (url: String) methods from protocol requirements

danielCarlosCE opened this issue · 1 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.

Agreed.