api

package
v0.0.0-...-1cdef85 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

README

Wikimedia Enterprise APIs SDK

Intended to jump start you with the using of the API(s).

Getting started

To create the API client you can use the following code snippet:

clt := api.NewClient()

If you need to pass a custom options to the client you can use:


clt := api.NewClient(func(clt *api.Client) {
  // redefine the client properties here
  clt.UserAgent = "my agent"
})

Also, to use the api you need to set the access token:

clt := api.NewClient()
clt.SetAccessToken("my_token")

Please refer to the interface definitions to see the full list of APIs.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

API interface tha encapsulates the whole functionality of the client. Can be used with composition in unit testing.

func NewClient

func NewClient(ops ...func(clt *Client)) API

NewClient returns a new instance of the Client that implements the API interface. The function takes in optional functional options that allow the caller to configure the client with custom settings.

type AccessTokenSetter

type AccessTokenSetter interface {
	SetAccessToken(tkn string)
}

AccessTokenSetter is an interface for setting an access token.

type AllReader

type AllReader interface {
	ReadAll(ctx context.Context, rdr io.Reader, cbk ReadCallback) error
}

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

func (c *Client) DownloadSnapshot(ctx context.Context, idr string, wsk io.WriteSeeker) error

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) GetCode

func (c *Client) GetCode(ctx context.Context, idr string, req *Request) (*schema.Code, error)

GetCode retrieves a code by ID, and returns an error if any.

func (*Client) GetCodes

func (c *Client) GetCodes(ctx context.Context, req *Request) ([]*schema.Code, error)

GetCodes retrieves a list of codes, 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

func (c *Client) GetLanguages(ctx context.Context, req *Request) ([]*schema.Language, error)

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

func (c *Client) GetNamespaces(ctx context.Context, req *Request) ([]*schema.Namespace, error)

GetNamespaces retrieves a list of namespaces, and returns an error if any.

func (*Client) GetProject

func (c *Client) GetProject(ctx context.Context, idr string, req *Request) (*schema.Project, error)

GetProject retrieves a project by ID, and returns an error if any.

func (*Client) GetProjects

func (c *Client) GetProjects(ctx context.Context, req *Request) ([]*schema.Project, error)

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

func (c *Client) GetSnapshots(ctx context.Context, req *Request) ([]*schema.Snapshot, error)

GetSnapshots retrieves a list of all snapshots and returns an error if any.

func (*Client) GetThings

func (c *Client) GetThings(ctx context.Context, nme string, req *Request) ([]*schema.Thing, error)

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

func (c *Client) HeadSnapshot(ctx context.Context, idr string) (*schema.Headers, error)

HeadSnapshot retrieves only the headers of a single snapshot for a specific ID, and returns an error if any.

func (*Client) ReadAll

func (c *Client) ReadAll(ctx context.Context, rdr io.Reader, cbk ReadCallback) error

ReadAll reads the contents of the given io.Reader and calls the given ReadCallback function with each chunk of data read.

func (*Client) ReadBatch

func (c *Client) ReadBatch(ctx context.Context, dte *time.Time, idr string, cbk ReadCallback) error

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

func (c *Client) ReadSnapshot(ctx context.Context, idr string, cbk ReadCallback) error

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

func (c *Client) SetAccessToken(tkn string)

SetAccessToken sets the access token for the client.

func (*Client) StreamArticles

func (c *Client) StreamArticles(ctx context.Context, req *Request, cbk ReadCallback) error

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

type CodesGetter interface {
	GetCodes(ctx context.Context, req *Request) ([]*schema.Code, error)
}

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.

type SnapshotsGetter

type SnapshotsGetter interface {
	GetSnapshots(ctx context.Context, req *Request) ([]*schema.Snapshot, error)
}

SnapshotsGetter is an interface for getting multiple snapshots.

type ThingsGetter

type ThingsGetter interface {
	GetThings(ctx context.Context, nme string, req *Request) ([]*schema.Thing, error)
}

ThingsGetter is an interface for getting a lits of things by name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL