api

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2021 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiKeyEnvName    = "STOCKER_API_KEY"
	ApiServerEnvName = "STOCKER_API_SERVER"

	DefaultClientTimeout = time.Second * 4

	DefaultRequestBackoffDelay = time.Millisecond * 125
	DefaultRequestBackoffLimit = time.Second
	DefaultRequestRetryLimit   = 10
)

Variables

View Source
var Client *http.Client = &http.Client{
	Timeout: DefaultClientTimeout,
	Transport: &http.Transport{
		DialContext: func(ctx context.Context, network, address string) (net.Conn, error) {
			dialer := net.Dialer{}
			return dialer.DialContext(ctx, network, address)
		},
	},
}

Functions

func GetApiKeyFromEnv

func GetApiKeyFromEnv() string

func GetApiResponseBody added in v1.3.0

func GetApiResponseBody(url, accessToken string, isRetryable func(*http.Response) bool) ([]byte, error)

func GetApiServerFromEnv

func GetApiServerFromEnv() string

func IsErrorRetryable

func IsErrorRetryable(err error) bool

func MakeApiRequestWithRetry

func MakeApiRequestWithRetry(client *http.Client, req *http.Request, retryCb func(res *http.Response, err error) bool)

Types

type OAuthCredentials

type OAuthCredentials struct {
	AccessToken  string
	ApiServer    string
	ExpiresIn    int
	RefreshToken string
	TokenType    string
}

type StockApi

type StockApi interface {
	GetCurrency(currency, currencyTo string) (stock.Currency, error)
	GetQuote(symbol string) (stock.Quote, error)
	GetSymbol(symbol string) (stock.Symbol, error)
	RefreshCredentials() (*OAuthCredentials, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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