Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove (url: String) methods from protocol requirements #25

Closed
danielCarlosCE opened this issue Jan 31, 2018 · 1 comment
Closed

Remove (url: String) methods from protocol requirements #25

danielCarlosCE opened this issue Jan 31, 2018 · 1 comment

Comments

@danielCarlosCE
Copy link
Contributor

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.

@amadeu01
Copy link
Contributor

Agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants