yandexmapclient

package module
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: MIT Imports: 12 Imported by: 0

README

yandexmapclient

A HTTP client to communication with Yandex Map API and retrieve information about public transport stops.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckErrorType

func CheckErrorType(err error, EType ErrorTypes) bool

Types

type Brief

type Brief struct {
	DepartureTime *string   `json:"departureTime"`
	Events        []Events  `json:"Events"`
	Frequency     Frequency `json:"Frequency"`
}

Brief contains unit's schedule info. It may or may not have DepartureTime

type Client

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

Client interacts with yandex maps API

func New

func New(opts ...ClientOption) (*Client, error)

New creates new yandexClient and gets csrfToken to be able to perform requests

func (*Client) FetchStopInfo

func (c *Client) FetchStopInfo(ctx context.Context, stopID string, prognosis bool) (response StopInfo, err error)

FetchStopInfo gets stop info by specific stop id. If first request gets `invalid csrf token` response it applies it and retries

func (*Client) UpdateToken

func (c *Client) UpdateToken() error

UpdateToken gets new csrfToken if needed

type ClientOption

type ClientOption func(*Client) error

ClientOption applies options to client

func WithCsrfToken

func WithCsrfToken(token string) ClientOption

func WithHost

func WithHost(host string) ClientOption

func WithLocale

func WithLocale(locale string) ClientOption

func WithLogger

func WithLogger(l Logger) ClientOption

func WithTimeout

func WithTimeout(t time.Duration) ClientOption

type Data

type Data struct {
	Properties Properties `json:"properties"`
}

Data model

type ErrorTypes

type ErrorTypes int
const (
	ErrorUnknown ErrorTypes = iota
	ErrorWrongStatusCode
	ErrorEmptyToken
)

func ExtractErrorType

func ExtractErrorType(err error) ErrorTypes

type Events

type Events struct {
	Scheduled TimeInfo `json:"scheduled"`
	Estimated TimeInfo `json:"estimated"`
}

type Frequency

type Frequency struct {
	Value int64    `json:"value"`
	Begin TimeInfo `json:"begin"`
	End   TimeInfo `json:"end"`
}

type Logger

type Logger interface {
	Debug(msg string)
	Debugf(format string, args ...interface{})
}

Logger interface for logging some things

type Properties

type Properties struct {
	StopMetaData StopMetaData `json:"StopMetaData"`
	CurrentTime  int64        `json:"currentTime"`
}

Properties model

type StopInfo

type StopInfo struct {
	CsrfToken string          `json:"csrfToken,omitempty"`
	Error     *YandexMapError `json:"error,omitempty"`
	Data      *Data           `json:"data,omitempty"`
}

StopInfo contains information about incoming transport for stop and csrfToken in case server responded with refresh token demand

type StopMetaData

type StopMetaData struct {
	Transport []TransportInfo `json:"Transport"`
}

StopMetaData model

type Thread added in v1.1.6

type Thread struct {
	BriefSchedule Brief `json:"BriefSchedule"`
}

type TimeInfo

type TimeInfo struct {
	Time time.Time
}

func (*TimeInfo) UnmarshalJSON

func (t *TimeInfo) UnmarshalJSON(data []byte) (err error)

type TimeInfoYandex

type TimeInfoYandex struct {
	Value string `json:"value"`
}

type TransportInfo

type TransportInfo struct {
	Name    string   `json:"name"`
	Type    string   `json:"type"`
	Threads []Thread `json:"threads"`
}

TransportInfo contains departure time and route name

type YandexClientError

type YandexClientError struct {
	Message string
	// contains filtered or unexported fields
}

YandexClientError is an error returned by client

func NewEmptyTokenError

func NewEmptyTokenError() YandexClientError

func NewWrongStatusCodeError

func NewWrongStatusCodeError(gotCode int) YandexClientError

func (YandexClientError) Cause

func (err YandexClientError) Cause() error

func (YandexClientError) Error

func (err YandexClientError) Error() string

type YandexMapError

type YandexMapError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

YandexMapError reports error from service

func (*YandexMapError) Error

func (e *YandexMapError) Error() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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