Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niyiomotoso/the-guardian-api-kotlin-client
Kotlin client library for the Guardian APIs
https://github.com/niyiomotoso/the-guardian-api-kotlin-client
api client-library kotlin kotlin-library news news-sdk news-search the-guardian-api theguardian theguardian-client-library
Last synced: 14 days ago
JSON representation
Kotlin client library for the Guardian APIs
- Host: GitHub
- URL: https://github.com/niyiomotoso/the-guardian-api-kotlin-client
- Owner: niyiomotoso
- License: apache-2.0
- Created: 2023-07-02T19:54:24.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-01T22:47:24.000Z (over 1 year ago)
- Last Synced: 2024-11-19T17:56:20.232Z (3 months ago)
- Topics: api, client-library, kotlin, kotlin-library, news, news-sdk, news-search, the-guardian-api, theguardian, theguardian-client-library
- Language: Kotlin
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# The Guardian API Kotlin Client
Kotlin client library for the Guardian APIs. See documentation [here](https://open-platform.theguardian.com/documentation/).
All available API modules are supported - Content, Tags, Sections, Editions, and Single Item.### Get API key
Sign up for an API key [here](https://open-platform.theguardian.com/access)
### Making Requests
The primary `Client\GuardianApi` class is a factory class that creates objects for each of the API modules, allowing you to make requests to any of them with your desired request parameters. You have to first create an object for it, then access your desired API module via the object. See the code snippets below:
```kotlin
val guardianApi = GuardianApi(THE_GUARDIAN_API_KEY)
```**For Content:**
```kotlin
val response = this.guardianApi.content().setQuery("12 years a slave")
.setTag("film/film,tone/reviews")
.setFromDate("2023-03-20")
.setShowTags("contributor")
.setShowFields("starRating,headline,thumbnail,short-url")
.setOrderBy("relevance").fetch()
```**For Tags:**
```kotlin
val response = this.guardianApi.tags().setQuery("apple")
.setSection("technology")
.setShowReferences("all").fetch()```
**For Sections:**
```kotlin
val response = this.guardianApi.sections().setQuery("business").fetch()
```**For Editions:**
```kotlin
val response = this.guardianApi.editions().setQuery("uk").fetch()
```**For Single Item:**
```kotlin
val response = this.guardianApi.singleItem().setId("/sport/2022/oct/07/cricket-jos-buttler-primed-for-england-comeback-while-phil-salt-stays-focused")
.setShowStoryPackage(true)
.setShowEditorsPicks(true)
.setShowMostViewed(true)
.setShowRelated(true).fetch()
```