funpay

package module
v0.0.0-...-e8392b0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: MIT Imports: 14 Imported by: 0

README

Funpay

Go library for Funpay.

[!important] This library is currently developing! But may used to handle user and lots. Use [Funpay.Request] and [Funpay.RequestHTML] to make your own modules.

Installation

go get github.com/kostromin59/funpay

Example usage

Account handling
func main() {
	goldenKey := "gk"
	userAgent := "ua"

	fp := funpay.New(goldenKey, userAgent)

	// Update account info, csrf token and cookies
	// Should be called every 40-60 minutes
	if err := fp.Update(context.TODO()); err != nil {
		log.Println(err.Error())
		return
	}

	log.Printf("account id: %d", fp.UserID())
	log.Printf("username: %q", fp.Username())
	log.Printf("balance: %d", fp.Balance())
	log.Printf("locale: %q", fp.Locale())
}
Lots
func main() {
	fp := funpay.New("golden key", "user agent")
	if err := fp.Update(context.TODO()); err != nil {
		panic(err)
	}

	fpLots := lots.New(fp)

	// Load lots for current user
	if err := fpLots.Update(context.TODO()); err != nil {
		log.Println(err.Error())
		return
	}

	// Returns [nodeID]: []string{offerIDs...}
	lotsList := fpLots.List()
	log.Printf("count of nodes: %d", len(lotsList))

	// Returns all fields with values to update lot (offer)
	fields, err := fpLots.FieldsByOfferID(context.TODO(), "", "some_id")
	if err != nil {
		log.Println(err.Error())
		return
	}

	// Change field
	fields["price"] = lots.Field{
		Value: "1500",
	}

	// Save lot (offer)
	if err := fpLots.Save(context.Background(), fields); err != nil {
		log.Println(err.Error())
		return
	}

	// Returns all fields of lot by node (category) without values
	// 2852 - Accounts Call of Duty: Black Ops 6
	fields, err = fpLots.FieldsByNodeID(context.Background(), "2852")
	if err != nil {
		log.Println(err.Error())
		return
	}

	offerID := fields["offer_id"]
	log.Println(offerID.Value == "0") // true
}

To-Do

This list may grow while developing.

  • Other
    • Use single entrypoint as base (funpay.New)
    • Dedicated lots module
  • Requests
    • Request with account data
    • Proxy support
    • Locale support (setlocale query param and path param for en)
    • Auto load locale
  • Account
    • Info
      • Username
      • Balance (from badge)
    • Updating cookies
    • CSRF Token
    • Substituting base url (for testing)
    • Proxy support
  • Messages
    • Getting all messages
    • Getting new messages
    • Sending
  • Lots
    • Get fields
    • Get lots
    • Update lot
    • Delete lot
    • Create lot
  • Deploy
    • Deploy into pkg.go.dev
    • Improve documentation
    • Tests

Documentation

Index

Constants

View Source
const (
	Domain  = "funpay.com"
	BaseURL = "https://" + Domain
)
View Source
const (
	// CookieGoldenKey is the cookie name for golden key.
	CookieGoldenKey = "golden_key"

	// HeaderUserAgent is the header name for user agent.
	HeaderUserAgent = "User-Agent"

	FormCSRFToken = "csrf_token"
)

Variables

View Source
var (
	// ErrTooManyRequests indicates rate limiting (HTTP 429 Too Many Requests).
	// Returned when exceeding API request limits.
	ErrTooManyRequests = errors.New("too many requests")

	// ErrBadStatusCode indicates unexpected HTTP response status.
	// Returned for any non-2xx status code not covered by other errors.
	ErrBadStatusCode = errors.New("bad status code")
)
View Source
var (
	ErrAccountUnauthorized = errors.New("account unauthorized")
)
View Source
var (
	// RequestPostHeaders contains content-type, accept and x-requested-with headers. Copy these values to your headers if needed.
	RequestPostHeaders = map[string]string{
		"content-type":     "application/x-www-form-urlencoded; charset=UTF-8",
		"accept":           "*/*",
		"x-requested-with": "XMLHttpRequest",
	}
)

Functions

func WithBaseURL

func WithBaseURL(baseURL string) opt

func WithHTTPClient

func WithHTTPClient(httpClient HTTPClient) opt

Types

type AppData

type AppData struct {
	CSRFToken string `json:"csrf-token"`
	UserID    int64  `json:"userId"`
	Locale    Locale `json:"locale"`
}

AppData represents the object from data-app-data attribute inside the body element.

type Funpay

func New

func New(goldenKey, userAgent string, options ...opt) Funpay

type FunpayAuthHandler

type FunpayAuthHandler interface {
	CSRFToken() string
	GoldenKey() string
	UserAgent() string
}

type FunpayClient

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

func (*FunpayClient) Balance

func (fp *FunpayClient) Balance() int64

func (*FunpayClient) BaseURL

func (fp *FunpayClient) BaseURL() string

func (*FunpayClient) CSRFToken

func (fp *FunpayClient) CSRFToken() string

func (*FunpayClient) Cookies

func (fp *FunpayClient) Cookies() []*http.Cookie

func (*FunpayClient) GoldenKey

func (fp *FunpayClient) GoldenKey() string

func (*FunpayClient) Locale

func (fp *FunpayClient) Locale() Locale

func (*FunpayClient) Request

func (fp *FunpayClient) Request(ctx context.Context, requestURL string, opts ...RequestOpt) (*http.Response, error)

func (*FunpayClient) RequestHTML

func (fp *FunpayClient) RequestHTML(ctx context.Context, requestURL string, opts ...RequestOpt) (*goquery.Document, error)

func (*FunpayClient) Update

func (fp *FunpayClient) Update(ctx context.Context) error

func (*FunpayClient) UpdateLocale

func (fp *FunpayClient) UpdateLocale(ctx context.Context, locale Locale) error

func (*FunpayClient) UserAgent

func (fp *FunpayClient) UserAgent() string

func (*FunpayClient) UserID

func (fp *FunpayClient) UserID() int64

func (*FunpayClient) Username

func (fp *FunpayClient) Username() string

type FunpayRequester

type FunpayRequester interface {
	Cookies() []*http.Cookie
	Request(ctx context.Context, requestURL string, opts ...RequestOpt) (*http.Response, error)
	RequestHTML(ctx context.Context, requestURL string, opts ...RequestOpt) (*goquery.Document, error)
}

type FunpayUpdater

type FunpayUpdater interface {
	BaseURL() string
	Update(ctx context.Context) error
	UpdateLocale(ctx context.Context, locale Locale) error
}

type FunpayUser

type FunpayUser interface {
	UserID() int64
	Locale() Locale
	Username() string
	Balance() int64
}

type HTTPClient

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

type Locale

type Locale string

Locale represents the Funpay webiste locale.

const (
	LocaleRU Locale = "ru"
	LocaleEN Locale = "en"
)

type RequestOpt

type RequestOpt func(options *RequestOpts)

RequestOpt defines a function type for modifying request options.

func RequestWithBody

func RequestWithBody(body io.Reader) RequestOpt

RequestWithBody sets the request body.

func RequestWithCookies

func RequestWithCookies(cookies []*http.Cookie) RequestOpt

RequestWithCookies adds additional cookies to the request. Note: Session cookies are added automatically.

func RequestWithHeaders

func RequestWithHeaders(headers map[string]string) RequestOpt

RequestWithHeaders adds custom headers to the request. Headers are added in addition to default User-Agent.

func RequestWithMethod

func RequestWithMethod(method string) RequestOpt

RequestWithMethod sets the HTTP method for the request. Default: GET

type RequestOpts

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

RequestOpts contains configurable parameters for HTTP requests. Used internally by [Funpay.Request] to customize request behavior.

func NewRequestOpts

func NewRequestOpts() *RequestOpts

NewRequestOpts creates request options with defaults:

  • Method: GET

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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