Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func fetchLessons(groupName: String, in container: Container) throws -> Future<KPIResponseContainer<[KPILesson]>> {
- let logger = try container.make(Logger.self)
- let client = HTTPClient.connect(scheme: .https, hostname: hostname, on: container)
- return client.flatMap(to: HTTPResponse.self) { client in
- guard
- let encodedGroupName = groupName.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
- let url = URLComponents(string: "/v2/groups/\(encodedGroupName)/lessons")?.url
- else {
- throw Abort(.badRequest, reason: "Invalid group name")
- }
- logger.debug("Sending request to http://\(self.hostname)\(url.path)")
- let request = HTTPRequest(method: .GET, url: url)
- return client.send(request)
- }.flatMap(to: KPIResponseContainer<[KPILesson]>.self) { httpResponse in
- let response = Response(http: httpResponse, using: container)
- return try response.content.decode(KPIResponseContainer<[KPILesson]>.self)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement