mwapi

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 11 Imported by: 0

README

mwapi

GoDoc rcard FOSSA Status

MediaWiki API for Go

License

FOSSA Status

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JoinValues

func JoinValues(dst Values, srcs ...Values)

JoinValues joins maps of arguments

Types

type Client

type Client struct {
	LoginType
	// contains filtered or unexported fields
}

Client handles all requests to MediaWiki API

func NewClient

func NewClient(apiphp string, user string, pass string) (*Client, error)

NewClient creates a new Client

func (*Client) Block

func (mw *Client) Block(user, expiry, reason string, v Values) (*Response, error)

Block sends a block action

func (*Client) Delete

func (mw *Client) Delete(title, reason string, v Values) (*Response, error)

Delete sends a delete action

func (*Client) Edit

func (mw *Client) Edit(title string, txt string, summ string, minor, create bool) (*Response, error)

Edit sends an edit action

func (*Client) Get

func (mw *Client) Get(v Values) (*Response, error)

Get handles GET request with specified values

func (*Client) Login

func (mw *Client) Login() error

Login handles user login via an API

func (*Client) Move

func (mw *Client) Move(from, to, reason string, v Values) (*Response, error)

Move sends a move action

func (*Client) Post

func (mw *Client) Post(v Values) (*Response, error)

Post handles POST request with specified values

func (*Client) Protect added in v0.3.0

func (mw *Client) Protect(title, protection, expiry, reason string, v Values) (*Response, error)

func (*Client) Query

func (mw *Client) Query() *Query

Query gets a fresh query builder from a pool

func (*Client) Read

func (mw *Client) Read() *Query

Read creates a query which allows user to obtain page content

func (*Client) Token

func (mw *Client) Token(names ...string) (tokens map[string]string, e error)

Token returns tokens for specified actions

type Error

type Error struct {
	Code string `json:"code"`
	Info string `json:"info"`
}

Error handles error information returned from MediaWiki API

func (Error) Error

func (e Error) Error() string

type Gen

type Gen struct {
	Name   string
	Values Values
}

Gen is used as a generator in query requests

func (Gen) Generate

func (g Gen) Generate() Values

Generate creates values to add to an API call

type LoginType

type LoginType int

LoginType specifies which login method should be used

const (
	LoginLegacy LoginType = iota
	LoginToken
	LoginClient
)

type Query

type Query struct {
	// contains filtered or unexported fields
}

Query builds a query action for API call

func (*Query) Continue

func (q *Query) Continue(cont ...string) bool

Continue handles "continue" tokens from response

func (*Query) Do

func (q *Query) Do() (e error)

Do prepares request data and sends them to MediaWiki server

func (*Query) List

func (q *Query) List(list string, v Values) *Query

List adds a "list" argument for a query request

func (*Query) Pages

func (q *Query) Pages(v interface{}) error

Pages saves information about queried pages to a value

func (*Query) Prop

func (q *Query) Prop(prop string, v Values) *Query

Prop adds a "prop" argument for a query request

func (*Query) Response

func (q *Query) Response() *Response

Response returns recently received response

func (*Query) ReturnToPool

func (q *Query) ReturnToPool()

ReturnToPool sets all contained data to default end adds a query builder to a pool

func (*Query) With

func (q *Query) With(v ...interface{}) *Query

With adds arrays of page titles, page IDs and a generator for a query request

type QueryPage

type QueryPage struct {
	PageID  int64  `json:"pageid"`
	NS      int    `json:"ns"`
	Title   string `json:"title"`
	Missing bool   `json:"missing,omitempty"`
}

QueryPage holds basic data returned by a query request

type ReadPage

type ReadPage struct {
	QueryPage
	Revisions []struct {
		Slots struct {
			Main struct {
				ContentModel string `json:"contentmodel"`
				Content      string `json:"content"`
			} `json:"main"`
		} `json:"slots"`
	} `json:"revisions"`
}

ReadPage holds returned data with page content

func (*ReadPage) Content

func (rp *ReadPage) Content() string

Content gets page content from a current revision

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response contains json-encoded API result

func (*Response) Get

func (r *Response) Get(to interface{}, path ...interface{}) error

Get saves decoded response to a value with specified prefixed path

func (*Response) GetRaw

func (r *Response) GetRaw(to interface{}, path ...interface{}) error

Get saves decoded response to a value with raw path

func (*Response) ReturnToPool added in v0.3.0

func (r *Response) ReturnToPool()

ReturnToPool sets all contained data to default end adds a response to a pool

type Values

type Values map[string]string

Values hold query arguments for an API call

Jump to

Keyboard shortcuts

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