vote

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: GPL-3.0 Imports: 7 Imported by: 4

Documentation

Overview

Methods interacting with the AUR website.

Client creation elements

Errors

Example

Vote for a single package

package main

import (
	"context"
	"log"

	"github.com/Jguer/votar/pkg/vote"
)

func main() {
	client, err := vote.NewClient()
	if err != nil {
		log.Println("Failed to create client")
	}

	client.SetCredentials("user", "password")

	if err = client.Vote(context.Background(), "package"); err != nil {
		log.Println("Failed to vote for", "package")
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoCredentials = fmt.Errorf("no credentials provided")

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(opts ...ClientOption) (*Client, error)

NewClient creates a new AURWebClient.

func (*Client) SetCredentials

func (a *Client) SetCredentials(username, password string)

SetCredentials sets the username and password for the client.

func (*Client) Unvote

func (a *Client) Unvote(ctx context.Context, pkgbase string) error

Unvote unvotes for the given package.

func (*Client) Vote

func (a *Client) Vote(ctx context.Context, pkgbase string) error

Vote votes for the given package.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL allows overriding the default base URL of the client.

func WithHTTPClient

func WithHTTPClient(doer HTTPRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithUserAgent

func WithUserAgent(userAgent string) ClientOption

WithUserAgent allows overriding the default user agent of the client.

type ErrLoginFailed

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

func (*ErrLoginFailed) Error

func (e *ErrLoginFailed) Error() string

type ErrVoteFailed

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

func (*ErrVoteFailed) Error

func (e *ErrVoteFailed) Error() string

type HTTPRequestDoer

type HTTPRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPRequestDoer performs HTTP requests. The standard http.Client implements this interface.

Jump to

Keyboard shortcuts

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