Documentation
¶
Overview ¶
Package buyproxy is the official Go SDK for BuyProxy — residential, mobile, ISP and datacenter proxies over a typed API.
client := buyproxy.New() // reads BUYPROXY_API_KEY
plans, _ := client.Plans.List(ctx)
res, _ := client.Plans.Generate(ctx, plans[0].ID, &buyproxy.GenerateParams{Country: "US", Count: 5})
resp, _ := res.Proxies[0].HTTPClient().Get("https://api.ipify.org")
Index ¶
- Constants
- Variables
- type APIError
- type Account
- type AccountService
- type AllocateParams
- type Allocation
- type AuthService
- type Balance
- type BalancesService
- type BillingInterval
- type CardCheckout
- type CardCheckoutParams
- type Catalog
- type Client
- type ConnectionError
- type CryptoCheckout
- type Customer
- type CustomerDetail
- type CustomerGenerateParams
- type CustomerPlan
- type CustomerStatus
- type CustomerUpdate
- type CustomerUsage
- type CustomersService
- func (s *CustomersService) Allocate(ctx context.Context, username string, p AllocateParams) (*Allocation, error)
- func (s *CustomersService) Create(ctx context.Context, label string) (*Customer, error)
- func (s *CustomersService) Generate(ctx context.Context, username string, p CustomerGenerateParams) (*GeneratedProxies, error)
- func (s *CustomersService) Get(ctx context.Context, username string) (*CustomerDetail, error)
- func (s *CustomersService) List(ctx context.Context, status CustomerStatus) ([]Customer, error)
- func (s *CustomersService) Update(ctx context.Context, username string, u CustomerUpdate) (*Customer, error)
- func (s *CustomersService) Usage(ctx context.Context, username string) (*CustomerUsage, error)
- type GenerateCapabilities
- type GenerateParams
- type GeneratedProxies
- type Option
- type PaidPlan
- type PendingAllocation
- type Plan
- type PlansService
- type PoolEntry
- type PoolService
- type PoolTopupParams
- type Product
- type ProductKey
- type ProductsService
- type Protocol
- type Proxy
- type ResellerService
- type ResellerSummary
- type SignupParams
- type SignupResult
- type TopupService
- type Transaction
- type TransactionsService
- type VerifyResult
Constants ¶
const DefaultBaseURL = "https://www.buyproxy.org"
DefaultBaseURL is the production API.
const Version = "1.0.0"
Version is the SDK version, sent in the User-Agent.
Variables ¶
var ( ErrValidation = errors.New("buyproxy: invalid request") ErrAuthentication = errors.New("buyproxy: authentication failed") ErrInsufficientBandwidth = errors.New("buyproxy: insufficient bandwidth") ErrForbidden = errors.New("buyproxy: forbidden") ErrNotFound = errors.New("buyproxy: not found") ErrRateLimited = errors.New("buyproxy: rate limited") ErrServer = errors.New("buyproxy: server error") )
Sentinel errors for use with errors.Is:
if errors.Is(err, buyproxy.ErrInsufficientBandwidth) { ... }
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
// HTTP status code.
Status int
// Message is the API's own error text.
Message string
// Body is the raw response body.
Body []byte
// RetryAfter is set on 429 when the API said how long to wait.
RetryAfter time.Duration
}
APIError is returned for every non-2xx response.
type Account ¶
type Account struct {
Email string `json:"email"`
Name string `json:"name"`
Plan string `json:"plan"`
PlanExpiresAt *string `json:"planExpiresAt"`
// BalanceGB is the lifetime GB credited. Spendable per-product balances come from Balances.List.
BalanceGB float64 `json:"balanceGb"`
CreatedAt string `json:"createdAt"`
}
Account is the account behind the API key.
type AccountService ¶
type AccountService struct {
// contains filtered or unexported fields
}
type AllocateParams ¶
type AllocateParams struct {
ProductKey ProductKey `json:"productKey"`
GB int `json:"gb"` // whole GB, at least the product's minimum
// IdempotencyKey makes retries safe: repeating a key returns AlreadyApplied and moves nothing.
IdempotencyKey string `json:"-"`
}
AllocateParams moves GB from your pool onto a customer.
type Allocation ¶
type Allocation struct {
ProductKey ProductKey `json:"productKey"`
ProductID string `json:"productId"`
GB int `json:"gb"`
AlreadyApplied bool `json:"alreadyApplied"`
PoolRemainingGB float64 `json:"poolRemainingGb"`
}
Allocation is the result of an allocation.
type AuthService ¶
type AuthService struct {
// contains filtered or unexported fields
}
AuthService creates an account without a browser: Signup, then VerifyOTP with the emailed code.
func (*AuthService) ResendOTP ¶
func (s *AuthService) ResendOTP(ctx context.Context, email string) error
func (*AuthService) Signup ¶
func (s *AuthService) Signup(ctx context.Context, p SignupParams) (*SignupResult, error)
func (*AuthService) VerifyOTP ¶
func (s *AuthService) VerifyOTP(ctx context.Context, email, code string) (*VerifyResult, error)
type Balance ¶
type Balance struct {
ProductKey *ProductKey `json:"productKey"`
ProductID string `json:"productId"`
// PlanID is what to pass to Plans.Generate; nil until the product has been funded once.
PlanID *string `json:"planId"`
ActiveGB float64 `json:"activeGb"`
PendingGB float64 `json:"pendingGb"` // paid for but still being added
TotalGB float64 `json:"totalGb"`
ExpiresAt *string `json:"expiresAt"`
}
Balance is the spendable bandwidth on one product.
type BalancesService ¶
type BalancesService struct {
// contains filtered or unexported fields
}
type BillingInterval ¶
type BillingInterval string
BillingInterval is "month" or "year".
const ( Monthly BillingInterval = "month" Yearly BillingInterval = "year" )
type CardCheckout ¶
type CardCheckout struct {
PayURL string `json:"payUrl"`
// TransactionID is nil when PayURL is the subscription portal rather than a new payment.
TransactionID *string `json:"transactionId"`
}
CardCheckout is a Stripe checkout to open in a browser.
type CardCheckoutParams ¶
type CardCheckoutParams struct {
Kind string `json:"kind"`
ProductKey ProductKey `json:"productKey,omitempty"`
GB int `json:"gb,omitempty"`
Plan PaidPlan `json:"plan,omitempty"`
Interval BillingInterval `json:"interval,omitempty"`
}
CardCheckoutParams starts a card checkout: either a top-up (Kind "topup", ProductKey, GB) or a subscription (Kind "plan", Plan, Interval). Use TopupCardParams / PlanCardParams to build one.
func PlanCardParams ¶
func PlanCardParams(plan PaidPlan, interval BillingInterval) CardCheckoutParams
PlanCardParams builds the params for a plan subscription. An empty interval means monthly.
func TopupCardParams ¶
func TopupCardParams(product ProductKey, gb int) CardCheckoutParams
TopupCardParams builds the params for a pay-as-you-go card top-up.
type Catalog ¶
type Catalog struct {
Products []Product `json:"products"`
VolumeBonus struct {
ThresholdGB int `json:"thresholdGb"`
Rate float64 `json:"rate"`
} `json:"volumeBonus"`
Plans []struct {
Plan PaidPlan `json:"plan"`
MonthlyPriceCents int `json:"monthlyPriceCents"`
IncludedGB float64 `json:"includedGb"`
} `json:"plans"`
}
Catalog is the public product catalog with live prices.
type Client ¶
type Client struct {
Products *ProductsService
Auth *AuthService
Account *AccountService
Balances *BalancesService
Plans *PlansService
Topup *TopupService
Transactions *TransactionsService
Reseller *ResellerService
// contains filtered or unexported fields
}
Client talks to the BuyProxy API. It is safe for concurrent use.
type ConnectionError ¶
type ConnectionError struct{ Err error }
ConnectionError means the request never got a response (DNS, reset, timeout, offline).
func (*ConnectionError) Error ¶
func (e *ConnectionError) Error() string
func (*ConnectionError) Unwrap ¶
func (e *ConnectionError) Unwrap() error
type CryptoCheckout ¶
CryptoCheckout is a crypto invoice to open in a browser.
type Customer ¶
type Customer struct {
Username string `json:"username"`
Label string `json:"label"`
Status CustomerStatus `json:"status"`
CreatedAt string `json:"createdAt"`
}
Customer is a reseller sub-account.
type CustomerDetail ¶
type CustomerDetail struct {
Customer
Plans []CustomerPlan `json:"plans"`
Pending []PendingAllocation `json:"pending"`
}
CustomerDetail is a customer with their plans.
type CustomerGenerateParams ¶
type CustomerGenerateParams struct {
PlanID string `json:"planId"`
GenerateParams
}
CustomerGenerateParams is GenerateParams plus the customer's plan.
type CustomerPlan ¶
CustomerPlan is a Plan plus the customer's remaining GB.
type CustomerStatus ¶
type CustomerStatus string
CustomerStatus is "active" or "suspended".
const ( CustomerActive CustomerStatus = "active" CustomerSuspended CustomerStatus = "suspended" )
type CustomerUpdate ¶
type CustomerUpdate struct {
Label string `json:"label,omitempty"`
Status CustomerStatus `json:"status,omitempty"`
}
CustomerUpdate renames and/or suspends/reactivates; empty fields are left unchanged.
type CustomerUsage ¶
type CustomerUsage struct {
Plans []struct {
ID string `json:"id"`
ProductID string `json:"productId"`
ProductKey *ProductKey `json:"productKey"`
RemainingGB float64 `json:"remainingGb"`
TotalGB float64 `json:"totalGb"`
UsedGB float64 `json:"usedGb"`
ExpiresAt *string `json:"expiresAt"`
} `json:"plans"`
Pending []PendingAllocation `json:"pending"`
}
CustomerUsage is a snapshot of a customer's consumption.
type CustomersService ¶
type CustomersService struct {
// contains filtered or unexported fields
}
func (*CustomersService) Allocate ¶
func (s *CustomersService) Allocate(ctx context.Context, username string, p AllocateParams) (*Allocation, error)
Allocate moves GB from your pool onto a customer. Set IdempotencyKey to make retries safe.
func (*CustomersService) Create ¶
Create makes an isolated sub-account with no bandwidth — fund it with Allocate.
func (*CustomersService) Generate ¶
func (s *CustomersService) Generate(ctx context.Context, username string, p CustomerGenerateParams) (*GeneratedProxies, error)
func (*CustomersService) Get ¶
func (s *CustomersService) Get(ctx context.Context, username string) (*CustomerDetail, error)
func (*CustomersService) List ¶
func (s *CustomersService) List(ctx context.Context, status CustomerStatus) ([]Customer, error)
List returns your customers; pass a status ("active"/"suspended") to filter, or "" for all.
func (*CustomersService) Update ¶
func (s *CustomersService) Update(ctx context.Context, username string, u CustomerUpdate) (*Customer, error)
func (*CustomersService) Usage ¶
func (s *CustomersService) Usage(ctx context.Context, username string) (*CustomerUsage, error)
type GenerateCapabilities ¶
type GenerateCapabilities struct {
MaxCount int `json:"maxCount"`
MaxStickyMinutes int `json:"maxStickyMinutes"` // 0 means no sticky sessions on this product
Protocols []Protocol `json:"protocols"`
Targeting struct {
Country bool `json:"country"`
State bool `json:"state"`
City bool `json:"city"`
ISP bool `json:"isp"`
} `json:"targeting"`
}
GenerateCapabilities describes what a plan's generate call accepts.
type GenerateParams ¶
type GenerateParams struct {
Protocol Protocol `json:"protocol,omitempty"` // default "http"
Count int `json:"count,omitempty"` // 1–1000, default 1
Country string `json:"country,omitempty"` // ISO 3166-1 alpha-2, e.g. "US"
State string `json:"state,omitempty"`
City string `json:"city,omitempty"`
ISP string `json:"isp,omitempty"`
// StickyMinutes keeps the same IP for that long. Leave 0 for a fresh IP per request (rotating).
StickyMinutes int `json:"stickyMinutes,omitempty"`
}
GenerateParams controls proxy generation. Zero values are omitted, so the API's defaults apply.
type GeneratedProxies ¶
GeneratedProxies is the result of a Generate call: the raw lines plus parsed proxies.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithAPIKey ¶
WithAPIKey sets the key (bp_key_… personal, bp_live_… reseller). Default: $BUYPROXY_API_KEY.
func WithBaseURL ¶
WithBaseURL overrides the API origin (default https://www.buyproxy.org).
func WithHTTPClient ¶
WithHTTPClient supplies your own *http.Client (timeouts, tracing, proxies).
func WithMaxRetries ¶
WithMaxRetries sets retries for rate limits and transient failures (default 2).
type PendingAllocation ¶
type PendingAllocation struct {
ProductID string `json:"productId"`
ProductKey *ProductKey `json:"productKey"`
GB float64 `json:"gb"`
}
PendingAllocation is GB allocated but still being added to a plan.
type Plan ¶
type Plan struct {
ID string `json:"id"`
ProductID string `json:"productId"`
ProductKey *ProductKey `json:"productKey"`
Name string `json:"name"`
Label *string `json:"label"`
DataGBRemaining float64 `json:"dataGbRemaining"`
DataGBTotal float64 `json:"dataGbTotal"`
ExpiresAt *string `json:"expiresAt"`
CreatedAt string `json:"createdAt"`
Generate *GenerateCapabilities `json:"generate"`
}
Plan is bandwidth you hold on one product.
type PlansService ¶
type PlansService struct {
// contains filtered or unexported fields
}
func (*PlansService) Generate ¶
func (s *PlansService) Generate(ctx context.Context, planID string, p *GenerateParams) (*GeneratedProxies, error)
Generate creates proxy lines against one of your plans. Lines are on-demand — don't store them.
type PoolEntry ¶
type PoolEntry struct {
ProductKey ProductKey `json:"productKey"`
ProductID string `json:"productId"`
Label string `json:"label"`
GB float64 `json:"gb"`
}
PoolEntry is unallocated reseller bandwidth on one product.
type PoolService ¶
type PoolService struct {
// contains filtered or unexported fields
}
func (*PoolService) Get ¶
func (s *PoolService) Get(ctx context.Context) ([]PoolEntry, error)
Get returns your unallocated bandwidth, per product.
func (*PoolService) TopupCard ¶
func (s *PoolService) TopupCard(ctx context.Context, p PoolTopupParams) (*CardCheckout, error)
func (*PoolService) TopupCrypto ¶
func (s *PoolService) TopupCrypto(ctx context.Context, p PoolTopupParams) (*CryptoCheckout, error)
type PoolTopupParams ¶
type PoolTopupParams struct {
ProductKey ProductKey `json:"productKey"`
GB int `json:"gb"`
}
PoolTopupParams buys bandwidth into the reseller pool.
type Product ¶
type Product struct {
ProductKey ProductKey `json:"productKey"`
ProductID string `json:"productId"`
Name string `json:"name"`
Description string `json:"description"`
MinGB int `json:"minGb"`
PricePerGBCents *int `json:"pricePerGbCents"` // nil if pricing is momentarily unavailable
Currency string `json:"currency"`
}
Product is one item in the catalog.
type ProductKey ¶
type ProductKey string
ProductKey is accepted by every top-up and allocation call — see Products.List.
const ( ProductResidential ProductKey = "residential" ProductPremium ProductKey = "premium" ProductISP ProductKey = "isp" ProductMobile ProductKey = "mobile" ProductIPv4 ProductKey = "ipv4" ProductIPv6 ProductKey = "ipv6" )
type ProductsService ¶
type ProductsService struct {
// contains filtered or unexported fields
}
ProductsService is the public catalog.
type Proxy ¶
Proxy is one generated proxy. The API returns username:password@host:port lines.
func ParseProxy ¶
ParseProxy parses a username:password@host:port line. '@' and ':' are allowed inside the password.
func (Proxy) Curl ¶
Curl returns a ready-to-run curl command that prints your exit IP through this proxy.
func (Proxy) Env ¶
Env returns the environment variables understood by curl, wget, git and most CLIs.
func (Proxy) HTTPClient ¶
HTTPClient returns an *http.Client that sends every request through this proxy.
type ResellerService ¶
type ResellerService struct {
Customers *CustomersService
Pool *PoolService
// contains filtered or unexported fields
}
func (*ResellerService) Me ¶
func (s *ResellerService) Me(ctx context.Context) (*ResellerSummary, error)
type ResellerSummary ¶
type ResellerSummary struct {
Email string `json:"email"`
CustomerCount int `json:"customerCount"`
ActiveCustomerCount int `json:"activeCustomerCount"`
Pool []PoolEntry `json:"pool"`
}
ResellerSummary is the result of Reseller.Me.
type SignupParams ¶
type SignupParams struct {
Email string `json:"email"`
Password string `json:"password"`
Name string `json:"name,omitempty"`
}
SignupParams creates an account (no API key needed).
type SignupResult ¶
SignupResult is the result of Auth.Signup.
type TopupService ¶
type TopupService struct {
// contains filtered or unexported fields
}
func (*TopupService) Card ¶
func (s *TopupService) Card(ctx context.Context, p CardCheckoutParams) (*CardCheckout, error)
Card starts a Stripe checkout — a top-up or a plan subscription. Open PayURL to pay.
func (*TopupService) Crypto ¶
func (s *TopupService) Crypto(ctx context.Context, product ProductKey, gb int) (*CryptoCheckout, error)
Crypto starts a crypto top-up (pay-as-you-go only). Open URL to pay.
type Transaction ¶
type Transaction struct {
ID string `json:"id"`
Kind string `json:"kind"`
Status string `json:"status"` // pending | succeeded | failed
PaymentMethod string `json:"paymentMethod"`
Interval *BillingInterval `json:"interval"`
AmountCents int `json:"amountCents"`
Currency string `json:"currency"`
GB *float64 `json:"gb"` // including any volume bonus
ProductKey *ProductKey `json:"productKey"`
Plan *string `json:"plan"`
ResellerPool bool `json:"resellerPool"`
CreatedAt string `json:"createdAt"`
}
Transaction is one payment.
type TransactionsService ¶
type TransactionsService struct {
// contains filtered or unexported fields
}
func (*TransactionsService) Get ¶
func (s *TransactionsService) Get(ctx context.Context, id string) (*Transaction, error)
func (*TransactionsService) List ¶
func (s *TransactionsService) List(ctx context.Context, limit int) ([]Transaction, error)
List returns recent payments. limit <= 0 uses the API default.
func (*TransactionsService) Wait ¶
func (s *TransactionsService) Wait(ctx context.Context, id string, interval time.Duration) (*Transaction, error)
Wait polls until the payment settles (succeeded or failed) or ctx ends.