gohever

package module
v0.0.0-...-981aeee Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2023 License: MIT Imports: 9 Imported by: 0

README

gohever

💳 An API for the Hever website, written in Go.

GitHub Actions

go get -u github.com/yardnsm/gohever

Overview

gohever is an API wrapper around Hever's website. I originally wanted to build a Telegram bot that allows me to load my cards without logging in to the website and waiting for the ENORMOUS assets to load, and so "gohever" was born.

This package provides the basic functionality that the website offers and some nice features, such as:

  • Card information retrieval: balance, monthly usage, leftovers from the previous month, information regarding the discounts, etc.
  • Card history
  • Load estimation using the retrieved card status.
  • Loading the card using your HEVER credit card.

Plus some nice things that I really like:

  • Nice testutils for making testing the client way easier;
  • Automatic handling of authentication - you don't need to call Authenticate() at all!

⚠️ This project was meant to be used for educational purposes only. I am not affiliated with Hever in any way.

A note on testdata

The thing is - some data that this package parse comes from the HTML or JavaScript response of the website. This content is not suitable for open-source (and if it is, I don't want to find out), so I keep it in a separate, private repo.


License

MIT © Yarden Sod-Moriah

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRedirectIsNotAllowed = errors.New("request redirect is not allowed")

	ErrNotAuthenticated    = errors.New("not authenticated to HEVER website")
	ErrAuthenticatedFailed = errors.New("failed to authenticate to HEVER website")

	ErrUnableToParseCardConfig = errors.New("failed to parse the card config")

	ErrNotEnoughToLoad       = errors.New("the amount to load should be above 5")
	ErrLoadAboveOnCardLimit  = errors.New("charging above the max on card limit")
	ErrLoadAboveMonthlyLimit = errors.New("charging above the max monthly limit")
	ErrLoadInvalidValue      = errors.New("invalid value was passed to load")
)

Errors

Functions

func BasicCredentials

func BasicCredentials(username, password string) func() (Credentials, error)

func BasicCreditCard

func BasicCreditCard(number, month, year string) func() (CreditCard, error)

Types

type Auth

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

func (*Auth) Authenticate

func (auth *Auth) Authenticate() error

func (*Auth) Deauthenticate

func (auth *Auth) Deauthenticate() error

type AuthInterface

type AuthInterface interface {
	Authenticate() error
	Deauthenticate() error
}

type Card

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

func (*Card) GetHistory

func (card *Card) GetHistory() (*[]CardHistoryItem, error)

func (*Card) GetStatus

func (card *Card) GetStatus() (*CardStatus, error)

func (*Card) Load

func (card *Card) Load(status CardStatus, amount int32) (*LoadResult, error)

func (*Card) Type

func (card *Card) Type() CardType

type CardAction

type CardAction int

Card history actions

const (
	ActionLoad CardAction = iota
	ActionPurchase
)

type CardEstimate

type CardEstimate struct {
	// The final estimation
	Total         float64
	TotalFactored float64

	// The amount needed to load in order to reach the desired estimation
	Required         float64
	RequiredFactored float64

	// Amount taken from leftovers, does not include the factors
	Leftovers float64

	// Amount taken from factors. The "Amount" property means the amount taken from the factor
	// in order to reach the total.
	Factors []CardFactor
}

The result of a load estimation

type CardFactor

type CardFactor struct {
	Factor float64
	Amount float64
}

Represents a factor in the card, for example 30% for 1000ILS

type CardHistoryItem

type CardHistoryItem struct {
	Id           string
	Date         string
	ActionType   CardAction
	BusinessName string
	Amount       float64
}

type CardInterface

type CardInterface interface {
	Type() CardType

	GetStatus() (*CardStatus, error)
	GetHistory() (*[]CardHistoryItem, error)
	Load(status CardStatus, amount int32) (*LoadResult, error)
}

type CardStatus

type CardStatus struct {
	// The factors "steps" in the card, ordered accordingly. The "Amount" property means the maximum
	// amount the factor can take.
	Factors []CardFactor

	// The maximum amount we can load the card monthly
	MaxMonthlyAmount int

	// The maximum amount that the card can hold at a given time
	MaxOnCardAmount int

	// The current load on the card
	CurrentBalance float64

	// The remaining load until the end of the month
	RemainingMonthlyAmount float64

	// The remaning load until the card will be full
	RemainingOnCardAmount float64

	// The total monthly usage
	MonthlyUsage float64

	// The balance left from previous month and does not count against the current mothly quota
	Leftovers float64

	// Serial number (internal, used for charging the card)
	SerialNumber string
}

The status of a card at a given time

func (*CardStatus) Estimate

func (status *CardStatus) Estimate(amount float64) (*CardEstimate, error)

type CardType

type CardType int

Card types

const (
	TypeKeva CardType = iota
	TypeTeamim
)

type Client

type Client struct {
	Auth  AuthInterface
	Cards struct {
		Keva   CardInterface
		Teamim CardInterface
	}
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config Config) *Client

type Config

type Config struct {
	InitResty   func(r *resty.Client)
	Credentials func() (Credentials, error)
	CreditCard  func() (CreditCard, error)
}

type Credentials

type Credentials struct {
	Username string
	Password string
}

type CreditCard

type CreditCard struct {
	Number string
	Month  string
	Year   string
}

type LoadResult

type LoadResult struct {
	Status     LoadStatus
	LoadNumber string
	RawMessage string
}

type LoadStatus

type LoadStatus int

The status of a card load

const (
	StatusNone LoadStatus = iota
	StatusError
	StatusSuccess
)

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

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