Socket
Socket
Sign inDemoInstall

github.com/ima666/go-mwclient

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/ima666/go-mwclient

Package mwclient provides functionality for interacting with the MediaWiki API. go-mwclient is intended for users who are already familiar with (or are willing to learn) the MediaWiki API. It is intended to make dealing with the API more convenient, but not to hide it. go-mwclient v1 uses version 2 of the MW JSON API. In the example below, basic usage of go-mwclient is shown. Create a new Client object with the New() constructor, and then you are ready to start making requests to the API. If you wish to make requests to multiple MediaWiki sites, you must create a Client for each of them. go-mwclient offers a few methods for making arbitrary requests to the API: Get, GetRaw, Post, and PostRaw (see documentation for the methods for details). They all offer the same basic interface: pass a params.Values map (from the cgt.name/pkg/go-mwclient/params package), receive a response and an error. For convenience, go-mwclient offers several methods for making common requests (login, edit, etc.), but these methods are implemented using the same interface. params.Values params.Values is similar to (and a fork of) the standard library's net/url.Values. The reason why params.Values is used instead is that url.Values is based on a map[string][]string, rather than a map[string]string. This is because url.Values must support multiple keys with the same name. The literal syntax for a map[string][]string is rather cumbersome because the value is a slice rather than just a string, and the MediaWiki API actually does not use multiple keys when multiple values for the same key is required. Instead, one key is used and the values are separated by pipes (|). It is therefore very simple to write multi-value values in params.Values literals while params.Values makes it simple to write multi-value values in literals while avoiding the cumbersome []string literals for the most common case where the is only value. See documentation for the params package for more information. Because of the way type identity works in Go, it is possible for callers to pass a plain map[string]string rather than a params.Values. It is only necessary for users to use params.Values directly if they wish to use params.Values's methods. It makes no difference to go-mwclient. If an API call fails it will return an error. Many things can go wrong during an API call: the network could be down, the API could return an unexpected response (if the API was changed), or perhaps there's an error in your API request. If the error is an API error or warning (and you used the "non-Raw" Get and Post methods), then the error/warning(s) will be parsed and returned in either an APIError or an APIWarnings object, both of which implement the error interface. The "Raw" request methods do not check for API errors or warnings. For more information about API errors and warnings, please see https://www.mediawiki.org/wiki/API:Errors_and_warnings. If maxlag is enabled, it may be that the API has rejected the requests and the amount of retries (3 by default) have been tried unsuccessfully. In that case, the error will be the variable mwclient.ErrAPIBusy. Other methods than the core ones (i.e., other methods than Get and Post) may return other errors.


Version published

Readme

Source

go-mwclient

go-mwclient is a Go package for interacting with the MediaWiki JSON API.

go-mwclient aims to be a thin wrapper around the MediaWiki API that takes care of the most tedious parts of interacting with the API (such as authentication and query continuation), but it does not aim to abstract away all the functionality of the API.

go-mwclient v1 uses version 2 of the MediaWiki JSON API.

The canonical import path for this package is

import cgt.name/pkg/go-mwclient // imports "mwclient"

Documentation:

As of v1.0.0, go-mwclient uses semantic versioning. The master branch contains the most recent v1.x.x release.

Installation

go get -u cgt.name/pkg/go-mwclient

Example

package main

import (
    "fmt"

    "cgt.name/pkg/go-mwclient"
)

func main() {
    // Initialize a *Client with New(), specifying the wiki's API URL
    // and your HTTP User-Agent. Try to use a meaningful User-Agent.
    w, err := mwclient.New("https://en.wikipedia.org/w/api.php", "myWikibot")
    if err != nil {
        panic(err)
    }

    // Log in.
    err = w.Login("USERNAME", "PASSWORD")
    if err != nil {
        panic(err)
    }

    // Specify parameters to send.
    parameters := map[string]string{
        "action":   "query",
        "list":     "recentchanges",
        "rclimit":  "2",
        "rctype":   "edit",
        "continue": "",
    }

    // Make the request.
    resp, err := w.Get(parameters)
    if err != nil {
        panic(err)
    }

    // Print the *jason.Object
    fmt.Println(resp)
}

Dependencies

Other than the standard library, go-mwclient depends on the following third party, open source packages:

To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.

params package

The params package is based on the net/url package from the Go standard library, which is released under a BSD-style license. See params/LICENSE.

Contributions to the params package as part of this project are released to the public domain via CC0, as noted above and specified in the COPYING file.

FAQs

Last updated on 03 Jul 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc