ibmendoza / nyt-go

Golang wrapper for New York Times API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nyt-go

nyt-go is a Golang client implementation of the New York Times API.

Documentation: GoDoc

Install via go get github.com/gtkesh/nyt-go.

Currently supported NYT APIs:

TODO:

  • Complete README
  • Add tests
  • Support more APIs

Usage:

nytClient := nyt.NewClient("api_secret")

// Search articles with "Barack Obama" mentioned in them.
// https://api.nytimes.com/svc/search/v2/articlesearch.json?&q=Barack+Obama
articles, err := nytClient.GetArticles("Barack Obama")
if err != nil {
  log.Printf("error getting articles %v\n", err)
}
// Print out the url of the first article from the results.
fmt.Println(articles[0].WebURL)

// Search articles with "Barack Obama" mentioned in them in a specified time range and sorted by newest articles first.
// https://api.nytimes.com/svc/search/v2/articlesearch.json?&q=Barack+Obama&begin_date=20090000&end_date=20110000
articles, err = nytClient.GetArticles(
  "Barack Obama",
  // Note how you can chain options.
  nyt.WithBeginDate("20090000"),
  nyt.WithEndDate("20110000"),
  nyt.SortedByNewest(),
)
if err != nil {
  log.Printf("error getting articles %v\n", err)
}
// Print out the url of the first article from the results.
fmt.Println(articles[0].WebURL)

About

Golang wrapper for New York Times API

License:MIT License


Languages

Language:Go 100.0%