This library can be used to interact with the New York Times API. You need to get an API key from the New York Times to use this.
The complete API reference can be found here.
The library is hosted on jitpack.
Add this in your root build.gradle file at the end of the repositories.
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
Then, add the dependency.
dependencies {
compile 'com.github.j-em:NewYorkTimes:3.0.0'
}
Should work OOTB on Android with multidex enabled builds.
// Get a list of articles from the 2001/09/20 with "myquery" in the body, headline or byline.
getArticles("myquery", LocalDate(2001, 9, 20), LocalDate(2001, 9, 20)).run("apikey")
// Get a list of articles from the 2001/09/20 to the 2001/09/24 with "animals" in the body, headline or byline.
getArticles("animals", LocalDate(2001, 9, 20), LocalDate(2001, 9, 24)).run("apikey")
import jem.nytimes.Interop.getArticles
val page = 0
getArticles("apikey", "myquery", LocalDate(2001, 9, 20), LocalDate(2001, 9, 20), page)
The Interop object contains (unsafe) methods that makes it easier to interact with the library outside of Scala. Optionals are automatically unwrapped, the usage of Monads is hidden and the return type is a standard java list.
Running this in a shell should be enough.
$ sbt package