Documentation
¶
Index ¶
- func DefaultCredentialsPath() (string, error)
- type APIError
- type Client
- func (c *Client) AvailableIcons(ctx context.Context) (json.RawMessage, error)
- func (c *Client) BalanceByDate(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) BaseURL() string
- func (c *Client) CredentialsPath() string
- func (c *Client) DownloadFile(ctx context.Context, fileURL, destDir, name string) (string, error)
- func (c *Client) Get(ctx context.Context, path string, query url.Values) (json.RawMessage, error)
- func (c *Client) GetCard(ctx context.Context, id string, expand []string) (json.RawMessage, error)
- func (c *Client) GetCardGrant(ctx context.Context, id string, expand []string) (json.RawMessage, error)
- func (c *Client) GetCheck(ctx context.Context, id string) (json.RawMessage, error)
- func (c *Client) GetCheckDeposit(ctx context.Context, id string) (json.RawMessage, error)
- func (c *Client) GetCurrentUser(ctx context.Context, expand []string, avatarSize int) (json.RawMessage, error)
- func (c *Client) GetInvitation(ctx context.Context, id string) (json.RawMessage, error)
- func (c *Client) GetInvoice(ctx context.Context, id string) (json.RawMessage, error)
- func (c *Client) GetOrganization(ctx context.Context, id string, expand []string) (json.RawMessage, error)
- func (c *Client) GetPage(ctx context.Context, path string, query url.Values) (*Page, error)
- func (c *Client) GetSponsor(ctx context.Context, id string) (json.RawMessage, error)
- func (c *Client) GetTag(ctx context.Context, id string) (json.RawMessage, error)
- func (c *Client) GetTransaction(ctx context.Context, id, org string) (json.RawMessage, error)
- func (c *Client) GetUser(ctx context.Context, id string) (json.RawMessage, error)
- func (c *Client) GetUserByEmail(ctx context.Context, email string) (json.RawMessage, error)
- func (c *Client) ListCardDesigns(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) ListCardGrantTransactions(ctx context.Context, id string, page PageOpts) (*Page, error)
- func (c *Client) ListCardTransactions(ctx context.Context, cardID string, missingReceipts bool, page PageOpts) (*Page, error)
- func (c *Client) ListCheckDeposits(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) ListChecks(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) ListComments(ctx context.Context, transactionID string) (json.RawMessage, error)
- func (c *Client) ListFollowers(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) ListInvoices(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) ListMissingReceiptTransactions(ctx context.Context, page PageOpts) (*Page, error)
- func (c *Client) ListMyCardGrants(ctx context.Context, expand []string) (json.RawMessage, error)
- func (c *Client) ListMyCards(ctx context.Context, expand []string) (json.RawMessage, error)
- func (c *Client) ListMyInvitations(ctx context.Context) (json.RawMessage, error)
- func (c *Client) ListMyOrganizations(ctx context.Context, expand []string) (json.RawMessage, error)
- func (c *Client) ListOrgCardGrants(ctx context.Context, org string, expand []string) (json.RawMessage, error)
- func (c *Client) ListOrgCards(ctx context.Context, org string, expand []string) (json.RawMessage, error)
- func (c *Client) ListOrgInvitations(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) ListOrgTransactions(ctx context.Context, org string, filters TransactionFilters, page PageOpts) (*Page, error)
- func (c *Client) ListReceipts(ctx context.Context, transactionID string) (json.RawMessage, error)
- func (c *Client) ListSponsors(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) ListSubOrganizations(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) ListTags(ctx context.Context, org string) (json.RawMessage, error)
- func (c *Client) MemoSuggestions(ctx context.Context, org, txn string) (json.RawMessage, error)
- func (c *Client) Refresh(ctx context.Context) error
- func (c *Client) TokenInfo(ctx context.Context) (json.RawMessage, error)
- type Credentials
- type LoginConfig
- type Page
- type PageOpts
- type TransactionFilters
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultCredentialsPath ¶
DefaultCredentialsPath is ~/.config/hcb/credentials.json.
Types ¶
type APIError ¶
APIError is a non-2xx response from the v4 API, decoded from the standard {"error": "...", "messages": [...]} envelope.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a read-only HCB v4 API client with automatic token refresh. Safe for concurrent use.
func NewClientFromDefaultPath ¶
NewClientFromDefaultPath loads ~/.config/hcb/credentials.json.
func NewClientWithToken ¶
NewClientWithToken returns a client that authenticates with a fixed access token supplied by the caller (e.g. per-request tokens on a multi-user HTTP server). It never refreshes and never persists anything.
func (*Client) AvailableIcons ¶
AvailableIcons returns the mobile-app icon flags the user has unlocked.
func (*Client) BalanceByDate ¶
BalanceByDate returns the org's daily running balance series (past year).
func (*Client) BaseURL ¶
BaseURL returns the API host (e.g. https://hcb.hackclub.com).
func (*Client) CredentialsPath ¶
func (*Client) DownloadFile ¶
DownloadFile fetches a signed file URL (receipt url/preview_url, check deposit images, comment attachments, org logos) and writes it into destDir. If name is empty, it uses the Content-Disposition filename, falling back to the URL's path basename. Signed URLs are self-authorizing, so no Authorization header is sent — deliberately, to avoid leaking the bearer token to blob/CDN hosts. Returns the saved file's path.
func (*Client) Get ¶
Get performs an authenticated GET and returns the raw JSON body. On 401 it refreshes once and retries with the fresh token.
func (*Client) GetCard ¶
GetCard returns one card (crd_…). expand: organization, user, last_frozen_by, total_spent_cents, balance_available.
func (*Client) GetCardGrant ¶
func (c *Client) GetCardGrant(ctx context.Context, id string, expand []string) (json.RawMessage, error)
GetCardGrant returns one grant (cdg_…). expand: user, organization, balance_cents, disbursements.
func (*Client) GetCheck ¶
GetCheck returns one mailed check (chk_…). NOTE: upstream bug — the server's policy has no show? so this currently returns 403 for everyone.
func (*Client) GetCheckDeposit ¶
GetCheckDeposit returns one check deposit (ckd_…).
func (*Client) GetCurrentUser ¶
func (c *Client) GetCurrentUser(ctx context.Context, expand []string, avatarSize int) (json.RawMessage, error)
GetCurrentUser returns the authenticated user's profile. expand: shipping_address, billing_address. avatarSize (px) sizes the avatar URL; 0 = default.
func (*Client) GetInvitation ¶
GetInvitation returns one of the user's invitations (ivt_…).
func (*Client) GetInvoice ¶
GetInvoice returns one invoice (inv_…).
func (*Client) GetOrganization ¶
func (c *Client) GetOrganization(ctx context.Context, id string, expand []string) (json.RawMessage, error)
GetOrganization returns one org by public id (org_…) or slug. expand: balance_cents, users, account_number, reporting.
func (*Client) GetSponsor ¶
GetSponsor returns one sponsor (spo_…).
func (*Client) GetTransaction ¶
GetTransaction returns one transaction (HcbCode). If org is non-empty the org-scoped route is used (amounts/memos are rendered from that org's view); otherwise the top-level route auto-expands the organization.
func (*Client) GetUser ¶
GetUser looks up any user by public id (requires admin:read + auditor role).
func (*Client) GetUserByEmail ¶
GetUserByEmail looks up any user by email (requires admin:read + auditor role).
func (*Client) ListCardDesigns ¶
ListCardDesigns lists card personalization designs; org ("" = common only) adds that org's designs.
func (*Client) ListCardGrantTransactions ¶
func (c *Client) ListCardGrantTransactions(ctx context.Context, id string, page PageOpts) (*Page, error)
ListCardGrantTransactions returns a page of spending on the grant's card.
func (*Client) ListCardTransactions ¶
func (c *Client) ListCardTransactions(ctx context.Context, cardID string, missingReceipts bool, page PageOpts) (*Page, error)
ListCardTransactions returns a page of a card's charges.
func (*Client) ListCheckDeposits ¶
ListCheckDeposits lists an org's check deposits.
func (*Client) ListChecks ¶
ListChecks lists an org's mailed checks.
func (*Client) ListComments ¶
ListComments lists a transaction's comments (oldest first).
func (*Client) ListFollowers ¶
ListFollowers returns the org's followers.
func (*Client) ListInvoices ¶
ListInvoices lists an org's invoices.
func (*Client) ListMissingReceiptTransactions ¶
ListMissingReceiptTransactions returns the user's own card charges still missing a receipt.
func (*Client) ListMyCardGrants ¶
ListMyCardGrants lists grants the user has received.
func (*Client) ListMyCards ¶
ListMyCards lists the user's cards across all orgs. expand: organization, user, total_spent_cents.
func (*Client) ListMyInvitations ¶
ListMyInvitations lists the user's pending org invitations.
func (*Client) ListMyOrganizations ¶
ListMyOrganizations returns the orgs the user belongs to. expand: balance_cents, users, account_number, reporting.
func (*Client) ListOrgCardGrants ¶
func (c *Client) ListOrgCardGrants(ctx context.Context, org string, expand []string) (json.RawMessage, error)
ListOrgCardGrants lists an org's card grants.
func (*Client) ListOrgCards ¶
func (c *Client) ListOrgCards(ctx context.Context, org string, expand []string) (json.RawMessage, error)
ListOrgCards lists an org's cards.
func (*Client) ListOrgInvitations ¶
ListOrgInvitations lists an org's pending invitations.
func (*Client) ListOrgTransactions ¶
func (c *Client) ListOrgTransactions(ctx context.Context, org string, filters TransactionFilters, page PageOpts) (*Page, error)
ListOrgTransactions returns a page of the org's ledger (pending + settled).
func (*Client) ListReceipts ¶
ListReceipts lists receipts on a transaction, or the user's Receipt Bin if transactionID is empty. Each receipt carries signed url/preview_url fields.
func (*Client) ListSponsors ¶
ListSponsors lists an org's sponsors.
func (*Client) ListSubOrganizations ¶
ListSubOrganizations returns the org's sub-organizations.
func (*Client) MemoSuggestions ¶
MemoSuggestions returns up to 4 suggested memos for a transaction.
type Credentials ¶
type Credentials struct {
BaseURL string `json:"base_url"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
Scope string `json:"scope,omitempty"`
CreatedAt int64 `json:"created_at"`
ExpiresIn int64 `json:"expires_in"`
}
Credentials is the on-disk auth state at ~/.config/hcb/credentials.json.
func LoadCredentials ¶
func LoadCredentials(path string) (*Credentials, error)
func Login ¶
func Login(ctx context.Context, cfg LoginConfig, out io.Writer) (*Credentials, error)
Login runs the OAuth authorization-code flow: starts a localhost callback listener, sends the user to the authorize page, exchanges the returned code, and returns credentials ready to Save. Progress is written to out.
func (*Credentials) Expired ¶
func (c *Credentials) Expired(now time.Time) bool
Expired reports whether the access token is expired (or within a 120s safety margin of expiring). ExpiresIn == 0 means a non-expiring token.
func (*Credentials) Save ¶
func (c *Credentials) Save(path string) error
Save writes the credentials atomically with 0600 permissions.
type LoginConfig ¶
type LoginConfig struct {
BaseURL string
ClientID string
ClientSecret string
Scope string
// ListenAddr for the local callback server. Default 127.0.0.1:8910 — the
// port must match the OAuth app's registered redirect URI.
ListenAddr string
// OpenBrowser opens the authorize URL; nil uses the OS default browser.
OpenBrowser func(url string) error
}
LoginConfig configures the authorization-code login flow. (HCB's device-flow endpoint 500s in production, so a localhost callback — the gh-style flow — is the supported way to log in.)
type Page ¶
type Page struct {
TotalCount int `json:"total_count"`
HasMore bool `json:"has_more"`
Data json.RawMessage `json:"data"`
}
Page is the cursor-pagination envelope used by v4 list endpoints.
type PageOpts ¶
type PageOpts struct {
Limit int // default 25, max 100
After string // cursor: public id of the last item of the previous page
}
PageOpts are cursor-pagination options for paginated list endpoints.
type TransactionFilters ¶
type TransactionFilters struct {
Search string
Type string // ach_transfer, mailed_check, hcb_transfer, card_charge, check_deposit, donation, invoice, refund, fiscal_sponsorship_fee, reimbursement, wire, paypal_transfer, wise_transfer
TagID string
Expenses bool
Revenue bool
MinimumAmount string // dollars, e.g. "1.50"
MaximumAmount string
StartDate string // YYYY-MM-DD
EndDate string
UserID string
MissingReceipts bool
Category string
Merchant string
OrderBy string
}
TransactionFilters mirror the v4 ledger's filters[…] and type params.