funpay

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 12 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 represents the Funpay website domain.
	Domain = "funpay.com"

	// BaseURL is the base URL for the Funpay website.
	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 indicates authentication failure (HTTP 403 Forbidden).
	// Returned when golden key or session cookies are invalid/expired.
	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

This section is empty.

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) Funpay

New creates a new instanse of FunpayClient.

type FunpayAuthHandler added in v0.2.2

type FunpayAuthHandler interface {
	// CSRFToken returns CSRF token extracted from [AppData]. CSRF token updates every call [FunpayRequester.RequestHTML].
	CSRFToken() string

	// UserAgent returns the account's user agent provided into funpay (see [New]).
	GoldenKey() string

	// UserAgent returns the account's user agent provided into funpay (see [New]).
	UserAgent() string
}

type FunpayClient added in v0.2.2

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

func (*FunpayClient) Balance added in v0.2.2

func (fp *FunpayClient) Balance() int64

func (*FunpayClient) BaseURL added in v0.2.2

func (fp *FunpayClient) BaseURL() string

func (*FunpayClient) CSRFToken added in v0.2.2

func (fp *FunpayClient) CSRFToken() string

func (*FunpayClient) Cookies added in v0.2.2

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

func (*FunpayClient) GoldenKey added in v0.2.2

func (fp *FunpayClient) GoldenKey() string

func (*FunpayClient) Locale added in v0.2.2

func (fp *FunpayClient) Locale() Locale

func (*FunpayClient) Request added in v0.2.2

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

func (*FunpayClient) RequestHTML added in v0.2.2

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

func (*FunpayClient) SetBaseURL added in v0.2.2

func (fp *FunpayClient) SetBaseURL(baseURL string)

func (*FunpayClient) SetProxy added in v0.2.2

func (fp *FunpayClient) SetProxy(proxy *url.URL)

func (*FunpayClient) Update added in v0.2.2

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

func (*FunpayClient) UpdateLocale added in v0.2.2

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

func (*FunpayClient) UserAgent added in v0.2.2

func (fp *FunpayClient) UserAgent() string

func (*FunpayClient) UserID added in v0.2.2

func (fp *FunpayClient) UserID() int64

func (*FunpayClient) Username added in v0.2.2

func (fp *FunpayClient) Username() string

type FunpayRequester added in v0.2.2

type FunpayRequester interface {
	// Cookies returns a safe copy of all session cookies.
	Cookies() []*http.Cookie

	// SetProxy sets or updates the HTTP proxy for the requests.
	// To remove proxy and make direct connections, pass nil.
	SetProxy(proxy *url.URL)

	// Request executes an HTTP request using the account's session.
	//
	// It handles:
	//   - Proxy configuration (if set),
	//   - Locale settings (path or query param),
	//   - Cookie management (session and golden key),
	//   - User-Agent header,
	//   - Response status code validation,
	//
	// Specific returns:
	//   - [*http.Response] and [ErrAccountUnauthorized] if status code equals 403,
	//   - [*http.Response] and [ErrTooManyRequests] if status code equals 429,
	//   - [*http.Response] [ErrBadStatusCode] otherwise.
	Request(ctx context.Context, requestURL string, opts ...RequestOpt) (*http.Response, error)

	// RequestHTML calls [FunpayRequester.Request] and converting response as [*goquery.Document].
	// Updates [AppData] and account info (see [FunpayUser]).
	//
	// Returns nil and [ErrAccountUnauthorized] if [Funpay.UserID] is zero.
	RequestHTML(ctx context.Context, requestURL string, opts ...RequestOpt) (*goquery.Document, error)
}

type FunpayUpdater added in v0.2.2

type FunpayUpdater interface {
	// BaseURL returns clients baseURL. Needed for tests to substitute the [BaseURL] with test server.
	BaseURL() string

	// SetBaseURL updates clients baseURL. Needed for tests to substitute the [BaseURL] with test server.
	SetBaseURL(baseURL string)

	// Update calls [FunpayRequester.RequestHTML]. You should call it every 40-60 minutes to update PHPSESSIONID cookie.
	// [FunpayRequester.Request] saves all cookies from response if they are not empty.
	Update(ctx context.Context) error

	// UpdateLocale calls [FunpayRequester.RequestHTML] with setlocale query param.
	UpdateLocale(ctx context.Context, locale Locale) error
}

type FunpayUser added in v0.4.0

type FunpayUser interface {
	// UserID returns the unique identifier of the Funpay account.
	// Returns 0 if the account hasn't been updated yet.
	UserID() int64

	// Locale returns the account's locale (see [Locale]). Must be loaded after update.
	Locale() Locale

	// Username returns the account's username. Must be loaded after update.
	Username() string

	// Balance returns the account's balance. Must be loaded after update.
	Balance() int64
}

type Locale

type Locale string

Locale represents the Funpay webiste locale.

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

type RequestOpt added in v0.2.2

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

func RequestWithProxy

func RequestWithProxy(proxy *url.URL) RequestOpt

RequestWithProxy overrides the account-level proxy for this request. To disable proxy for single request: RequestWithProxy(nil)

type RequestOpts added in v0.2.2

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 added in v0.2.2

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