Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mtfum/newsapi
An unofficial supported Swift client library for accessing News API.
https://github.com/mtfum/newsapi
api-client async-await swift swift-package-manager
Last synced: about 1 month ago
JSON representation
An unofficial supported Swift client library for accessing News API.
- Host: GitHub
- URL: https://github.com/mtfum/newsapi
- Owner: mtfum
- License: mit
- Created: 2021-07-07T18:09:01.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-31T18:13:23.000Z (over 3 years ago)
- Last Synced: 2023-02-28T16:32:48.919Z (almost 2 years ago)
- Topics: api-client, async-await, swift, swift-package-manager
- Language: Swift
- Homepage:
- Size: 17.6 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NewsAPI
An API framework for [newsapi.org](https://newsapi.org/) with Swift.
## Requirement
- Swift5.5+
## Installation
### Swift Package Manager
```swift
.package(url: "https://github.com/mtfum/NewsAPI.git", from: "0.1.0")
```## Usage
### Setup
```Swift
import NewsAPI
let client = NewsAPI(apiKey: "YOUR_API_KEY")
```
### Get Sources
```Swift
let articles = try await client.getSources(
sources: [String] = [], // abc-news, bbc-news, etc...
query: String? = nil,
category: NewsSourceCategory? = nil,
language: Language = Language.en
)
```### Search
```Swift
let articles = try await client.search(
query: "",
sources: [String] = [],
sortBy: SortBy? = nil, // relevancy, popularity, publishedAt
language: Language? = nil
)
```### Top-Headlines
```Swift
let articles = try await client.getTopHeadlines(
category: NewsSourceCategory? = nil,
language: Language? = nil,
country: Country? = nil
)
```