Documentation ¶
Overview ¶
Package api holds an API client for Wikimedia Enterprise API(s) version two. Here you can find helper function to get started. Not that this client is only in beta at them moment, and was not production tested.
Index ¶
- type API
- type AccessTokenSetter
- type AllReader
- type ArticlesGetter
- type ArticlesStreamer
- type BatchDownloader
- type BatchGetter
- type BatchHeader
- type BatchReader
- type BatchesGetter
- type Client
- func (c *Client) DownloadBatch(ctx context.Context, dte *time.Time, idr string, wsk io.WriteSeeker) error
- func (c *Client) DownloadSnapshot(ctx context.Context, idr string, wsk io.WriteSeeker) error
- func (c *Client) GetArticles(ctx context.Context, nme string, req *Request) ([]*schema.Article, error)
- func (c *Client) GetBatch(ctx context.Context, dte *time.Time, idr string, req *Request) (*schema.Batch, error)
- func (c *Client) GetBatches(ctx context.Context, dte *time.Time, req *Request) ([]*schema.Batch, error)
- func (c *Client) GetCode(ctx context.Context, idr string, req *Request) (*schema.Code, error)
- func (c *Client) GetCodes(ctx context.Context, req *Request) ([]*schema.Code, error)
- func (c *Client) GetLanguage(ctx context.Context, idr string, req *Request) (*schema.Language, error)
- func (c *Client) GetLanguages(ctx context.Context, req *Request) ([]*schema.Language, error)
- func (c *Client) GetNamespace(ctx context.Context, idr int, req *Request) (*schema.Namespace, error)
- func (c *Client) GetNamespaces(ctx context.Context, req *Request) ([]*schema.Namespace, error)
- func (c *Client) GetProject(ctx context.Context, idr string, req *Request) (*schema.Project, error)
- func (c *Client) GetProjects(ctx context.Context, req *Request) ([]*schema.Project, error)
- func (c *Client) GetSnapshot(ctx context.Context, idr string, req *Request) (*schema.Snapshot, error)
- func (c *Client) GetSnapshots(ctx context.Context, req *Request) ([]*schema.Snapshot, error)
- func (c *Client) GetThings(ctx context.Context, nme string, req *Request) ([]*schema.Thing, error)
- func (c *Client) HeadBatch(ctx context.Context, dte *time.Time, idr string) (*schema.Headers, error)
- func (c *Client) HeadSnapshot(ctx context.Context, idr string) (*schema.Headers, error)
- func (c *Client) ReadAll(ctx context.Context, rdr io.Reader, cbk ReadCallback) error
- func (c *Client) ReadBatch(ctx context.Context, dte *time.Time, idr string, cbk ReadCallback) error
- func (c *Client) ReadSnapshot(ctx context.Context, idr string, cbk ReadCallback) error
- func (c *Client) SetAccessToken(tkn string)
- func (c *Client) StreamArticles(ctx context.Context, req *Request, cbk ReadCallback) error
- type CodeGetter
- type CodesGetter
- type Filter
- type LanguageGetter
- type LanguagesGetter
- type NamespaceGetter
- type NamespacesGetter
- type ProjectGetter
- type ProjectsGetter
- type ReadCallback
- type Request
- type SnapshotDownloader
- type SnapshotGetter
- type SnapshotHeader
- type SnapshotReader
- type SnapshotsGetter
- type ThingsGetter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface { CodesGetter CodeGetter LanguagesGetter LanguageGetter ProjectsGetter ProjectGetter NamespacesGetter NamespaceGetter BatchesGetter BatchGetter BatchHeader BatchReader BatchDownloader SnapshotsGetter SnapshotGetter SnapshotHeader SnapshotDownloader SnapshotReader AllReader AccessTokenSetter ArticlesGetter ArticlesStreamer ThingsGetter }
API interface tha encapsulates the whole functionality of the client. Can be used with composition in unit testing.
type AccessTokenSetter ¶
type AccessTokenSetter interface {
SetAccessToken(tkn string)
}
AccessTokenSetter is an interface for setting an access token.
type AllReader ¶
AllReader is an interface for reading all the contents of a reader with a callback function.
type ArticlesGetter ¶
type ArticlesGetter interface {
GetArticles(ctx context.Context, nme string, req *Request) ([]*schema.Article, error)
}
ArticlesGetter is an interface for getting a lits of articles by name.
type ArticlesStreamer ¶
type ArticlesStreamer interface {
StreamArticles(ctx context.Context, req *Request, cbk ReadCallback) error
}
ArticlesStreamer is an interface for getting all the article changes in realtime.
type BatchDownloader ¶
type BatchDownloader interface {
DownloadBatch(ctx context.Context, dte *time.Time, idr string, wsk io.WriteSeeker) error
}
BatchDownloader is an interface that downloads a realtime batch `tar.gz` by ID file from the API.
type BatchGetter ¶
type BatchGetter interface {
GetBatch(ctx context.Context, dte *time.Time, idr string, req *Request) (*schema.Batch, error)
}
BatchGetter is an interface that retrieves a realtime batch by ID from the API.
type BatchHeader ¶
type BatchHeader interface {
HeadBatch(ctx context.Context, dte *time.Time, idr string) (*schema.Headers, error)
}
BatchHeader is an interface that retrieves the header of a realtime batch by ID from the API.
type BatchReader ¶
type BatchReader interface {
ReadBatch(ctx context.Context, dte *time.Time, idr string, cbk ReadCallback) error
}
BatchReader is an interface that reads a realtime batch data by ID from the API.
type BatchesGetter ¶
type BatchesGetter interface {
GetBatches(ctx context.Context, dte *time.Time, req *Request) ([]*schema.Batch, error)
}
BatchesGetter is an interface that retrieves batches from the API.
type Client ¶
type Client struct { HTTPClient *http.Client // HTTP client used to send requests. UserAgent string // User-agent header value sent with each request. BaseUrl string // Base URL for all API requests. RealtimeURL string // Streaming URL endpoint for streaming. AccessToken string // Access token used to authenticate requests. DownloadMinChunkSize int // Minimum chunk size used for downloading resources. DownloadChunkSize int // Chunk size used for downloading resources. DownloadConcurrency int // Number of simultaneous downloads allowed. }
Client is a struct that represents an HTTP client used to interact with the API.
func (*Client) DownloadBatch ¶
func (c *Client) DownloadBatch(ctx context.Context, dte *time.Time, idr string, wsk io.WriteSeeker) error
DownloadBatch downloads the contents of a single batch for a specific date and ID, and writes the data to the specified WriteSeeker.
func (*Client) DownloadSnapshot ¶
DownloadSnapshot downloads the contents of a single snapshot for a specific ID, and writes the data to the specified WriteSeeker.
func (*Client) GetArticles ¶
func (c *Client) GetArticles(ctx context.Context, nme string, req *Request) ([]*schema.Article, error)
GetArticles retrieves articles from the API based on the given name and request parameters.
func (*Client) GetBatch ¶
func (c *Client) GetBatch(ctx context.Context, dte *time.Time, idr string, req *Request) (*schema.Batch, error)
GetBatch retrieves a single batch for a specific date and ID, and returns an error if any.
func (*Client) GetBatches ¶
func (c *Client) GetBatches(ctx context.Context, dte *time.Time, req *Request) ([]*schema.Batch, error)
GetBatches retrieves a list of batches for a specific date and request, and returns an error if any.
func (*Client) GetLanguage ¶
func (c *Client) GetLanguage(ctx context.Context, idr string, req *Request) (*schema.Language, error)
GetLanguage retrieves a language by ID, and returns an error if any.
func (*Client) GetLanguages ¶
GetLanguages retrieves a list of languages, and returns an error if any.
func (*Client) GetNamespace ¶
func (c *Client) GetNamespace(ctx context.Context, idr int, req *Request) (*schema.Namespace, error)
GetNamespaces retrieves a namespaces by ID, and returns an error if any.
func (*Client) GetNamespaces ¶
GetNamespaces retrieves a list of namespaces, and returns an error if any.
func (*Client) GetProject ¶
GetProject retrieves a project by ID, and returns an error if any.
func (*Client) GetProjects ¶
GetProjects retrieves a list of projects, and returns an error if any.
func (*Client) GetSnapshot ¶
func (c *Client) GetSnapshot(ctx context.Context, idr string, req *Request) (*schema.Snapshot, error)
GetSnapshot retrieves a single snapshot for a specific ID and returns an error if any.
func (*Client) GetSnapshots ¶
GetSnapshots retrieves a list of all snapshots and returns an error if any.
func (*Client) GetThings ¶
GetThings retrieves "things" from the API based on the given name and request parameters.
func (*Client) HeadBatch ¶
func (c *Client) HeadBatch(ctx context.Context, dte *time.Time, idr string) (*schema.Headers, error)
HeadBatch retrieves only the headers of a single batch for a specific date and ID, and returns an error if any.
func (*Client) HeadSnapshot ¶
HeadSnapshot retrieves only the headers of a single snapshot for a specific ID, and returns an error if any.
func (*Client) ReadAll ¶
ReadAll reads the contents of the given io.Reader and calls the given ReadCallback function with each chunk of data read.
func (*Client) ReadBatch ¶
ReadBatch reads the contents of a single batch for a specific date and ID, and invokes the specified callback function for each chunk read.
func (*Client) ReadSnapshot ¶
ReadSnapshot reads the contents of a single snapshots for a specific ID, and invokes the specified callback function for each chunk read.
func (*Client) SetAccessToken ¶
SetAccessToken sets the access token for the client.
func (*Client) StreamArticles ¶
StreamArticles streams all available articles from the server and applies a callback function to each article as they arrive. The callback function must implement the ReadCallback interface.
type CodeGetter ¶
type CodeGetter interface {
GetCode(ctx context.Context, idr string, req *Request) (*schema.Code, error)
}
CodeGetter is an interface that retrieves a code by ID from the API.
type CodesGetter ¶
CodesGetter is an interface that retrieves codes from the API.
type Filter ¶
type Filter struct { // Field specifies the field in the dataset that the filter should be applied to. Field string `json:"field"` // Value specifies the value that the field should be compared to. Value interface{} `json:"value"` }
Filter represents a filter to be applied to a dataset.
type LanguageGetter ¶
type LanguageGetter interface {
GetLanguage(ctx context.Context, idr string, req *Request) (*schema.Language, error)
}
LanguageGetter is an interface that retrieves a language by ID from the API.
type LanguagesGetter ¶
type LanguagesGetter interface {
GetLanguages(ctx context.Context, req *Request) ([]*schema.Language, error)
}
LanguagesGetter is an interface that retrieves languages from the API.
type NamespaceGetter ¶
type NamespaceGetter interface {
GetNamespace(ctx context.Context, idr int, req *Request) (*schema.Namespace, error)
}
NamespaceGetter is an interface that retrieves a namespace by ID from the API.
type NamespacesGetter ¶
type NamespacesGetter interface {
GetNamespaces(ctx context.Context, req *Request) ([]*schema.Namespace, error)
}
NamespacesGetter is an interface that retrieves namespaces from the API.
type ProjectGetter ¶
type ProjectGetter interface {
GetProject(ctx context.Context, idr string, req *Request) (*schema.Project, error)
}
ProjectGetter is an interface that retrieves a project by ID from the API.
type ProjectsGetter ¶
type ProjectsGetter interface {
GetProjects(ctx context.Context, req *Request) ([]*schema.Project, error)
}
ProjectsGetter is an interface that retrieves projects from the API.
type ReadCallback ¶
type ReadCallback func(art *schema.Article) error
ReadCallback is a function that will be called with each Article object that is read from a batch or snapshot. You can return a custom error to stop the reading.
type Request ¶
type Request struct { // Since is a parameter used only for streaming endpoints. // Will pick up the reading of stream from this timestamp. // For the articles endpoint it will be restricted to 48h. Since *time.Time `json:"since,omitempty"` // Fields represents a list of fields to retrieve from the API. // This is an optional argument. Fields []string `json:"fields,omitempty"` // Filters represents a list of filters to apply to the response. // This is an optional argument. Filters []*Filter `json:"filters,omitempty"` // Limits the amount of results from the API (for now works only with Articles API). // This is an optional argument. Limit int `json:"limit,omitempty"` }
Request contains properties that are used to apply filters to the API.
type SnapshotDownloader ¶
type SnapshotDownloader interface {
DownloadSnapshot(ctx context.Context, idr string, wsk io.WriteSeeker) error
}
SnapshotDownloader is an interface for downloading a single snapshot by ID to a writer.
type SnapshotGetter ¶
type SnapshotGetter interface {
GetSnapshot(ctx context.Context, idr string, req *Request) (*schema.Snapshot, error)
}
SnapshotGetter is an interface for getting a single snapshot by ID.
type SnapshotHeader ¶
type SnapshotHeader interface {
HeadSnapshot(ctx context.Context, idr string) (*schema.Headers, error)
}
SnapshotHeader is an interface for getting the headers of a single snapshot by ID.
type SnapshotReader ¶
type SnapshotReader interface {
ReadSnapshot(ctx context.Context, idr string, cbk ReadCallback) error
}
SnapshotReader is an interface for reading the contents of a single snapshot by ID with a callback function.