Last active
May 12, 2018 01:35
-
-
Save yimajo/5637e7ba98e29e06af33cbc51ec86b3f to your computer and use it in GitHub Desktop.
Connpass APIのAPIKit.Request
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
import Foundation | |
import APIKit | |
struct ConnpassAPI {} | |
extension ConnpassAPI { | |
struct SearchResult: Decodable { | |
let events: [Event] | |
} | |
struct Event: Decodable { | |
let title: String | |
} | |
} | |
extension ConnpassAPI { | |
final class DecodableDataParser: DataParser { | |
var contentType: String? { | |
return "application/json" | |
} | |
func parse(data: Data) throws -> Any { | |
return data | |
} | |
} | |
} | |
extension ConnpassAPI { | |
struct SearchRequest: Request { | |
typealias Response = SearchResult | |
let baseURL = URL(string: "https://connpass.com/api/v1/")! | |
let keyword: String | |
let method: HTTPMethod = .get | |
let path = "event" | |
var dataParser: DataParser { | |
return DecodableDataParser() | |
} | |
var parameters: Any? { | |
return ["keyword": keyword] | |
} | |
func response(from object: Any, urlResponse: HTTPURLResponse) throws -> Response { | |
return try JSONDecoder().decode(Response.self, from: object as! Data) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment