ondemand

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: 7 Imported by: 0

README

Wikimedia Enterprise On-Demand API SDK

The SDK is for the following APIs: i) Article lookup - look up an article of a specific project.

ii) Available projects - get list of available projects with their identifier, language, url, etc.

Getting started
  1. First, create an ondemand client and associate an access token to it:

    ctx := context.Background()
    ath := auth.NewClient()
    
    lgn, err := ath.Login(ctx, &auth.LoginRequest{
    	Username: os.Getenv("WME_USERNAME"),
    	Password: os.Getenv("WME_PASSWORD"),
    })
    if err != nil {
    	log.Panic(err)
    }
    
    od := ondemand.NewClient()
    od.SetAccessToken(lgn.AccessToken)
    
  2. Article look up example:

	req := &ondemand.ArticleRequest{
  	Project: "enwiki",
  	Name:    "Steamship",
  }

  res, err := od.Article(ctx, req)
  if err != nil {
  	log.Println(err)
  }

  log.Printf("name: %s, identifier: %d\n wikitext: %s",
  	res.Name,
  	res.Identifier,
  	res.ArticleBody.Wikitext,
  )
  1. Getting total number of available projects example:
  	res, err := od.Projects(ctx)
	if err != nil {
		log.Println(err)
	}

	fmt.Println("Total number of projects: ", len(res))

Documentation

Overview

SDK for on-demand APIs. Includes article lookup API and projects API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArticleRequest

type ArticleRequest struct {
	Project string `json:"project"`
	Name    string `json:"name"`
}

ArticleRequest parameters required for article request.

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client to simplify work with WME on-demand API.

func NewClient

func NewClient() *Client

NewClient creates new on-demand client.

func (*Client) Article

func (c *Client) Article(ctx context.Context, req *ArticleRequest) (*schema.Page, error)

Article triggers /pages/meta/{project}/{name} endpoint and returns current revision of an article.

func (*Client) GetAccessToken

func (c *Client) GetAccessToken() string

GetAccessToken returns value of the access token.

func (*Client) Projects

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

Projects triggers /projects endpoint and returns list of available projects.

func (*Client) SetAccessToken

func (c *Client) SetAccessToken(accessToken string)

SetAccessToken sets access token for authentication.

Jump to

Keyboard shortcuts

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