Last active
August 8, 2022 15:03
-
-
Save LukaszDziwosz/e0b0c97ad8e7c805f1ed8fadc21f3b16 to your computer and use it in GitHub Desktop.
GitHub Search Alamofire
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 Combine | |
import Alamofire | |
protocol RepoAPIProtocol { | |
func getRepos(quary: String, perPage: Int, page: Int) -> AnyPublisher<Repos, AFError> | |
} | |
struct RepoAPI: RepoAPIProtocol { | |
func getRepos(quary: String, perPage: Int, page: Int) -> AnyPublisher<Repos, AFError> { | |
let url = URL(string: "https://api.github.com/search/repositories")! | |
let parameters = [ | |
"q": quary, | |
"per_page": perPage, | |
"page": page, | |
] as [String : Any] | |
let headers: HTTPHeaders = [ | |
"Accept": "application/json" | |
] | |
return AF.request(url, | |
method: .get, | |
parameters: parameters, | |
headers: headers | |
) | |
.validate() | |
.publishDecodable(type: Repos.self) | |
.value() | |
.receive(on: DispatchQueue.main) | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment