Skip to content

Commit

Permalink
Add sources to topHeadlines
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfum committed Jul 31, 2021
1 parent 399c582 commit 1143721
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/NewsAPI/NewsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public actor NewsAPI {
}

public func getTopHeadlines(
sources: [NewsSource] = [],
sources: [String] = [],
query: String? = nil,
category: NewsSourceCategory? = nil,
language: Language = Language.en
) async throws -> [NewsArticle] {
guard let url = Endpoint.topHeadlines(key: apiKey, query: query, category: category, language: language).url else {
guard let url = Endpoint.topHeadlines(key: apiKey, query: query, sources: sources, category: category, language: language).url else {
throw ErrorResponse.invalidURL
}
do {
Expand Down
9 changes: 9 additions & 0 deletions Tests/NewsAPITests/NewsAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ final class NewsAPITests: XCTestCase {
}
}

func testGetTopHeadlinesWithSources() async throws {
do {
let articles = try await client.getTopHeadlines(sources: ["abc-news", "bbc-news"])
XCTAssertTrue(!articles.isEmpty)
} catch {
XCTFail(String(describing: error))
}
}

func testGetSources() async throws {
do {
let sources = try await client.getSources()
Expand Down

0 comments on commit 1143721

Please sign in to comment.