-
Notifications
You must be signed in to change notification settings - Fork 37
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
Feature [RM77] Api Service #78
Conversation
the RickAndMortyService returns a Dictionary from the requested api endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple comments to prepare it for testability and use more modern APIs 👍
if let data = data { | ||
if let jsonResponse = try? JSONSerialization.jsonObject(with: data, options: []) as? Dictionary<String, Any> { | ||
DispatchQueue.main.async { | ||
success(jsonResponse) | ||
} | ||
} else { | ||
error(ParseError.invalidJSON) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little out of date, idd consider implementing it with the JSONDecoder and using a try-catch instead.
|
||
import Foundation | ||
|
||
final class RickAndMortyService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not make this conform to a RickAndMortyServiceProtocol
that contains func fetchData(url: URL, success: @escaping (Dictionary<String, Any>) -> (), error: @escaping (Error?) -> ())
that way you are better prepared for dependency injection and testing :)
The RickAndMortyService now decodes for generic types
https://github.com/orgs/novoda/projects/1#card-66572850
The RickAndMortyService provides data from api endpoints.