Last active
January 15, 2016 01:44
-
-
Save paulofaria/b245ac2e44715d23c297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct GetPokemonEndpoint: EndpointType { | |
let middleware: [MiddlewareType] = [ | |
debugLogger, | |
clientContentNegotiator(JSONMediaType) | |
] | |
func serialize(id: Int) throws -> Request { | |
return Request(method: .GET, uri: URI(path: "/api/v1/pokemon/\(id)/")) | |
} | |
func parse(response: Response) throws -> Pokemon { | |
let content = response.content! | |
return Pokemon( | |
id: content["national_id"]!.int!, | |
name: content["name"]!.string! | |
) | |
} | |
func mock(id: Int) throws -> Pokemon { | |
return Pokemon(id: id, name: "Pokemon \(id)") | |
} | |
} | |
let getPokemonEndpoint = GetPokemonEndpoint() | |
let getPokemonMock = getPokemonEndpoint.createWithMock() | |
let pokemonMock = try getPokemonMock(129) | |
let client = try Client(host: "www.pokeapi.co", port: 80) | |
let getPokemon = getPokemonEndpoint.createWithClient(client) | |
let pokemon = try getPokemon(129) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment