mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-24 07:25:35 +00:00
Commit from m3o/m3o action
This commit is contained in:
65
news/news.go
Executable file
65
news/news.go
Executable file
@@ -0,0 +1,65 @@
|
||||
package news
|
||||
|
||||
import (
|
||||
"go.m3o.com/client"
|
||||
)
|
||||
|
||||
func NewNewsService(token string) *NewsService {
|
||||
return &NewsService{
|
||||
client: client.NewClient(&client.Options{
|
||||
Token: token,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
type NewsService struct {
|
||||
client *client.Client
|
||||
}
|
||||
|
||||
//
|
||||
func (t *NewsService) Headlines(request *HeadlinesRequest) (*HeadlinesResponse, error) {
|
||||
|
||||
rsp := &HeadlinesResponse{}
|
||||
return rsp, t.client.Call("news", "Headlines", request, rsp)
|
||||
|
||||
}
|
||||
|
||||
type Article struct {
|
||||
// categories
|
||||
Categories []string `json:"categories"`
|
||||
// article description
|
||||
Description string `json:"description"`
|
||||
// article id
|
||||
Id string `json:"id"`
|
||||
// image url
|
||||
ImageUrl string `json:"image_url"`
|
||||
// related keywords
|
||||
Keywords string `json:"keywords"`
|
||||
// the article language
|
||||
Language string `json:"language"`
|
||||
// the locale
|
||||
Locale string `json:"locale"`
|
||||
// time it was published
|
||||
PublishedAt string `json:"published_at"`
|
||||
// first 60 characters of article body
|
||||
Snippet string `json:"snippet"`
|
||||
// source of news
|
||||
Source string `json:"source"`
|
||||
// article title
|
||||
Title string `json:"title"`
|
||||
// url of the article
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type HeadlinesRequest struct {
|
||||
// date published on in YYYY-MM-DD format
|
||||
Date string `json:"date"`
|
||||
// comma separated list of languages to retrieve in e.g en,es
|
||||
Language string `json:"language"`
|
||||
// comma separated list of countries to include e.g us,ca
|
||||
Locale string `json:"locale"`
|
||||
}
|
||||
|
||||
type HeadlinesResponse struct {
|
||||
Articles []Article `json:"articles"`
|
||||
}
|
||||
Reference in New Issue
Block a user