Giter Club home page Giter Club logo

news-api-kotlin's Introduction

News-API-Kotlin

This is a Kotlin API Wrapper SDK for the https://newsapi.org. Go to the website to get your apiKey. This can be used for both Android and regular Java/Kotlin projects.

How to import:

Gradle:

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Add the dependency:

dependencies {
        implementation 'com.github.dfloureiro:news-api-kotlin:v2.1'
}

Maven:

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

Add the dependency:

<dependency>
    <groupId>com.github.dfloureiro</groupId>
    <artifactId>news-api-kotlin</artifactId>
    <version>v2.1</version>
</dependency>

How to use examples:

Create an instance of NewsApi:

    val newsApiRepository = NewsApiRepository("myApiKey")

Get top headlines by category/country/query:

    newsApiRepository.getTopHeadlines(category = Category.GENERAL, country = Country.US, q = "trump", pageSize = 20, page = 1)
            .subscribeOn(Schedulers.io())
	.toFlowable()
            .flatMapIterable { articles -> articles.articles }
            .subscribe({ article -> Log.d("getTopHead CC article", article.title) },
                    { t -> Log.d("getTopHeadlines error", t.message) })

Get top headlines by sources/query:

    newsApiRepository.getTopHeadlines(sources = "bbc-news", q = "trump", pageSize = 20, page = 1)
            .subscribeOn(Schedulers.io())
            .toFlowable()
            .flatMapIterable { articles -> articles.articles }
            .subscribe({ article -> Log.d("getTopHead S article", article.title) },
                    { t -> Log.d("getTopHeadlines error", t.message) })

Search articles from the full repo with everything:

    newsApiRepository.getEverything(q = "bitcoin", sources = "bbc-news", domains = null, from =  "2018-01-01", to = "2018-02-13", language = Language.EN, sortBy = SortBy.POPULARITY, pageSize = 20, page = 1)
            .subscribeOn(Schedulers.io())
            .toFlowable()
            .flatMapIterable { articles -> articles.articles }
            .subscribe({ article -> Log.d("getEverything article", article.title) },
                    { t -> Log.d("getEverything error", t.message) })

Get available sources:

    newsApiRepository.getSources(category = Category.GENERAL, language = Language.EN, country = Country.US)
            .subscribeOn(Schedulers.io())
            .toFlowable()
            .flatMapIterable { sources -> sources.sources }
            .subscribe({ source -> Log.d("source", source.name) },
                    { t -> Log.d("getSources error", t.message) })

Used technologies:

KOTLIN

https://github.com/JetBrains/kotlin

KODEIN

https://github.com/Kodein-Framework/Kodein-DI

RETROFIT

https://github.com/square/retrofit

RXKOTLIN

https://github.com/ReactiveX/RxKotlin

news-api-kotlin's People

Contributors

dfloureiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

news-api-kotlin's Issues

What about Retrofit?

inside lib right?
interface NewsAPI {
@get("{v2}/{top-headlines}")

fun listNews(@Path("v2") version : String,
             @Path("top-headlines") type : String,
             @Query("country") country: String,
             @Query("pageSize") pageSize: String,
             @Query("category") category: String,
             @Query("apiKey") key: String): Observable<ResponseBody>

@GET("{v2}/{everything}")
fun listSearchedNews(@Path("v2") version : String,
             @Path("everything") type : String,
             @Query("q") query: String,
             @Query("language") language: String,
             @Query("sortBy") sortBy: String,
             @Query("pageSize") pageSize: String,
             @Query("apiKey") key: String): Observable<ResponseBody>

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.