Documentation
¶
Overview ¶
Package newtqnia provides the official Go client for the NewTqnia bilingual technology news API.
The public API is read-only and does not require authentication. Applications displaying API content must preserve returned article URLs and render the attribution included in each Digest.
Index ¶
- Constants
- type APIError
- type Article
- type Attribution
- type AuthenticationError
- type AuthorizationError
- type Category
- type Client
- type Collection
- type Config
- type ConflictError
- type Digest
- type LinkLabel
- type Locale
- type NetworkError
- type NewsListParams
- type NewsService
- type NotFoundError
- type RateLimitError
- type RetryConfig
- type ServerError
- type TimeoutError
- type ValidationError
Examples ¶
Constants ¶
const (
// Version is the semantic version of this SDK.
Version = "1.0.0"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
RequestID string
Code string
Message string
RetryAfter time.Duration
Body string
}
APIError is returned for a non-successful HTTP response.
type Article ¶
type Article struct {
ID int64 `json:"id"`
Title string `json:"title"`
Summary string `json:"summary"`
Category Category `json:"category"`
Image string `json:"image"`
URL string `json:"url"`
PublishedAt time.Time `json:"published_at"`
ReadTime int `json:"read_time"`
}
Article is one localized NewTqnia article summary.
type Attribution ¶
type Attribution struct {
Text string `json:"text"`
URL string `json:"url"`
Required bool `json:"required"`
}
Attribution contains the attribution that clients must display with API content.
type AuthenticationError ¶
type AuthenticationError struct{ *APIError }
AuthenticationError reports an HTTP 401 response.
func (*AuthenticationError) Unwrap ¶
func (e *AuthenticationError) Unwrap() error
type AuthorizationError ¶
type AuthorizationError struct{ *APIError }
AuthorizationError reports an HTTP 403 response.
func (*AuthorizationError) Unwrap ¶
func (e *AuthorizationError) Unwrap() error
type Client ¶
type Client struct {
// News exposes localized news collection operations.
News *NewsService
// contains filtered or unexported fields
}
Client is a concurrency-safe NewTqnia API client.
Example ¶
package main
import (
"context"
"fmt"
"log"
newtqnia "github.com/newtqnia/newtqnia-go"
)
func main() {
client := newtqnia.New()
digest, err := client.News.Latest(context.Background(), &newtqnia.NewsListParams{
Locale: newtqnia.LocaleEnglish,
Limit: 5,
})
if err != nil {
log.Fatal(err)
}
for _, article := range digest.Articles {
fmt.Println(article.Title, article.URL)
}
}
Output:
type Collection ¶
type Collection string
Collection identifies a news collection.
const ( CollectionToday Collection = "today" CollectionLatest Collection = "latest" )
type Config ¶
type Config struct {
APIKey string
Application string
Website string
BaseURL string
Timeout time.Duration
Retry RetryConfig
// DisableRetries makes the initial request the only attempt.
DisableRetries bool
HTTPClient *http.Client
UserAgent string
Headers http.Header
}
Config configures a Client. Zero values use documented defaults.
type ConflictError ¶
type ConflictError struct{ *APIError }
ConflictError reports an HTTP 409 response.
func (*ConflictError) Unwrap ¶
func (e *ConflictError) Unwrap() error
type Digest ¶
type Digest struct {
APIVersion string `json:"api_version"`
Collection Collection `json:"collection"`
Date string `json:"date,omitempty"`
Timezone string `json:"timezone"`
Locale Locale `json:"locale"`
Direction string `json:"direction"`
Publisher LinkLabel `json:"publisher"`
Attribution Attribution `json:"attribution"`
GeneratedAt time.Time `json:"generated_at"`
Articles []Article `json:"articles"`
Links map[string]string `json:"_links"`
}
Digest is a localized collection of news and its attribution metadata.
type NetworkError ¶
type NetworkError struct{ Err error }
NetworkError reports a transport failure after retries are exhausted.
func (*NetworkError) Error ¶
func (e *NetworkError) Error() string
func (*NetworkError) Unwrap ¶
func (e *NetworkError) Unwrap() error
type NewsListParams ¶
type NewsListParams struct {
// Locale defaults to LocaleEnglish.
Locale Locale
// Limit defaults to 10 and must be between 1 and 10 when set.
Limit int
// Category is an optional category slug.
Category string
}
NewsListParams filters either public news collection.
type NewsService ¶
type NewsService struct {
// contains filtered or unexported fields
}
NewsService provides the public news endpoints.
func (*NewsService) Latest ¶
func (s *NewsService) Latest(ctx context.Context, params *NewsListParams) (*Digest, error)
Latest gets the latest published articles.
func (*NewsService) Today ¶
func (s *NewsService) Today(ctx context.Context, params *NewsListParams) (*Digest, error)
Today gets articles published today using the Asia/Dubai day boundary.
type NotFoundError ¶
type NotFoundError struct{ *APIError }
NotFoundError reports an HTTP 404 response.
func (*NotFoundError) Unwrap ¶
func (e *NotFoundError) Unwrap() error
type RateLimitError ¶
type RateLimitError struct{ *APIError }
RateLimitError reports an HTTP 429 response.
func (*RateLimitError) Unwrap ¶
func (e *RateLimitError) Unwrap() error
type RetryConfig ¶
RetryConfig controls retries after the initial request.
type ServerError ¶
type ServerError struct{ *APIError }
ServerError reports an HTTP 5xx response.
func (*ServerError) Unwrap ¶
func (e *ServerError) Unwrap() error
type TimeoutError ¶
TimeoutError reports expiry of the client request timeout.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
func (*TimeoutError) Unwrap ¶
func (e *TimeoutError) Unwrap() error
type ValidationError ¶
type ValidationError struct{ Message string }
ValidationError reports invalid client configuration or request parameters.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string