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

Feature [RM77] Api Service #78

Merged
merged 3 commits into from
Aug 12, 2021
Merged

Feature [RM77] Api Service #78

merged 3 commits into from
Aug 12, 2021

Conversation

swg99
Copy link
Contributor

@swg99 swg99 commented Aug 10, 2021

https://github.com/orgs/novoda/projects/1#card-66572850
The RickAndMortyService provides data from api endpoints.

the RickAndMortyService returns a Dictionary from the requested api endpoint
@swg99 swg99 linked an issue Aug 10, 2021 that may be closed by this pull request
Copy link
Contributor

@wrumble wrumble left a 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 👍

Comment on lines 26 to 33
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)
}
Copy link
Contributor

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 {
Copy link
Contributor

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
@swg99 swg99 merged commit c5999c0 into scottie-main Aug 12, 2021
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

Successfully merging this pull request may close these issues.

Build Rick and Morty service
2 participants