yandex

package module
v0.0.0-...-d18b0ec Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2020 License: MIT Imports: 11 Imported by: 0

README

ya-rasp

Client for Yandex rasp API

TODO

  • Add all method
  • Support XML

Documentation

Index

Constants

View Source
const (
	JsonFormat format = "json"
	XmlFormat  format = "xml"
)
View Source
const (
	Ru lang = "ru_RU" // Russian
	Ua lang = "uk_UA" // Ukraine
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Carrier

type Carrier struct {
	Code  int    `json:"code"`
	Title string `json:"title"`
}

type Client

type Client interface {
	// Расписание рейсов по станции
	Schedules(ctx context.Context, req SchedulesRequest) (*SchedulesResponse, error)
	// Список всех доступных станций
	StationsList(ctx context.Context) (*StationsListResponse, error)
	// Расписание рейсов между станциями
	Search(ctx context.Context, req SearchRequest) (*SearchResponse, error)
	// Список станций следования
	Thread(ctx context.Context, req ThreadRequest) (*ThreadResponse, error)
	// Список ближайших станций
	NearestStations(ctx context.Context, req NearestStationsRequest) (*NearestStationsResponse, error)
	//
	NearestCity(ctx context.Context, req NearestCityRequest) (*NearestCityResponse, error)
}

func New

func New(cfg *Config) Client

New return client

func NewWithDefaultConfig

func NewWithDefaultConfig(apiKey string) Client

NewWithDefaultConfig return client with default cfg

func NewWithPoolKey

func NewWithPoolKey(keys ...string) Client

type Config

type Config struct {
	Host    string
	Format  format
	Lang    lang
	Version string
	Timeout time.Duration
}

type Country

type Country struct {
	Regions []Region `json:"regions"`
	Name    string   `json:"title"`
}

type NearestCityRequest

type NearestCityRequest struct {
	Lat      float64
	Lng      float64
	Distance int
	Offset   int
	Limit    int
}

type NearestCityResponse

type NearestCityResponse struct {
	Distance     float64 `json:"distance"`
	Code         string  `json:"code"`
	Title        string  `json:"title"`
	PopularTitle string  `json:"popular_title"`
	ShortTitle   string  `json:"short_title"`
	Lat          float64 `json:"lat"`
	Lng          float64 `json:"lng"`
	Type         string  `json:"type"`
}

type NearestStationsRequest

type NearestStationsRequest struct {
	Lat         float64
	Lng         float64
	StationType string
	Distance    int
	Offset      int
	Limit       int
}

type NearestStationsResponse

type NearestStationsResponse struct {
	Pagination Pagination `json:"pagination"`
	Stations   []struct {
		Distance        float64       `json:"distance"`
		Code            string        `json:"code"`
		StationType     string        `json:"station_type"`
		TypeChoices     interface{}   `json:"type_choices"`
		Title           string        `json:"title"`
		TransportType   TransportType `json:"transport_type"`
		Lat             float64       `json:"lat"`
		Lng             float64       `json:"lng"`
		Type            string        `json:"type"`
		StationTypeName string        `json:"station_type_name"`
		Majority        int           `json:"majority"`
	} `json:"stations"`
}

type Pagination

type Pagination struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
	Total  int `json:"total"`
}

type Region

type Region struct {
	Settlements []Settlement `json:"settlements"`
	Name        string       `json:"title"`
}

Регион страны

type Schedule

type Schedule struct {
	ExceptDays string  `json:"except_days"` // Дни, в которые нитка не курсирует (даже если они входят в множество, описанное элементом days). Format "6, 7, 8, 9, 13, 14 февраля"
	Arrival    *string `json:"arrival"`     // Время прибытия
	Thread     Thread  `json:"thread"`      // Информация о нитке
	IsFuzzy    bool    `json:"is_fuzzy"`    // Признак неточности времени отправления и времени прибытия. Возможные значения: true — время прибытия и время отправления указаны неточно; false — время прибытия и время отправления указан точно.
	Days       string  `json:"days"`        // Дни курсирования нитки
	Stops      string  `json:"stops"`       // Станции следования рейса, на которых совершается остановка. Описывается в свободной форме. Например, значение везде значит, что остановка совершается на всех станциях следования. Пустая строка значит, что нитка нигде не останавливается между начальной и конечной станциями.
	Departure  *string `json:"departure"`   // Время отправления
	Terminal   string  `json:"terminal"`    // Терминал аэропорта (например, «D»). Принимает значение null, если информации о терминале нет.
	Platform   string  `json:"platform"`    // Платформа или путь, с которого отправляется рейс (например, «3 путь»). Пустая строка значит, что информации о платформе или пути нет.
}

type SchedulesRequest

type SchedulesRequest struct {
	Station       string        //
	Time          time.Time     //
	TransportType TransportType //
	Offset        int
	Limit         int
}

type SchedulesResponse

type SchedulesResponse struct {
	Pagination        Pagination  `json:"pagination"`         // Информация о постраничном выводе найденных рейсов.
	Date              string      `json:"date"`               // Дата, на которую получен список рейсов.
	Station           Station     `json:"station"`            // Информация об указанной в запросе станции.
	Schedule          []Schedule  `json:"schedule"`           // Список рейсов.
	ScheduleDirection interface{} `json:"schedule_direction"` // Код и название запрошенного направления рейсов.
	Directions        interface{} `json:"directions"`         // Коды и названия возможных направлений движения электричек по станции.
}

type SearchRequest

type SearchRequest struct {
	From   string
	To     string
	Date   time.Time
	Offset int
	Limit  int
}

type SearchResponse

type SearchResponse struct {
	Pagination       Pagination    `json:"pagination"`
	IntervalSegments []interface{} `json:"interval_segments"`
	Segments         []Segment     `json:"segments"`
	Search           interface{}   `json:"search"`
}

type Segment

type Segment struct {
	Arrival           string      `json:"arrival"`
	From              Station     `json:"from"`
	Thread            Thread      `json:"thread"`
	DeparturePlatform string      `json:"departure_platform"`
	Departure         string      `json:"departure"`
	Stops             string      `json:"stops"`
	DepartureTerminal interface{} `json:"departure_terminal"`
	To                Station     `json:"to"`
	HasTransfers      bool        `json:"has_transfers"`
	TicketsInfo       interface{} `json:"tickets_info"`
	Duration          float64     `json:"duration"`
	ArrivalTerminal   string      `json:"arrival_terminal"`
	StartDate         string      `json:"start_date"`
	ArrivalPlatform   string      `json:"arrival_platform"`
	Days              string      `json:"days"`
}

type Settlement

type Settlement struct {
	Name     string      `json:"title"`
	Codes    interface{} `json:"codes"`
	Stations []Station   `json:"stations"`
}

type Station

type Station struct {
	Direction     string            `json:"direction"`
	Codes         map[string]string `json:"codes"`
	Type          string            `json:"station_type"`
	Title         string            `json:"title"`
	Lng           interface{}       `json:"longitude"`
	Lat           interface{}       `json:"latitude"`
	TransportType string            `json:"transport_type"`
	Code          string            `json:"code"`

	Region string
	City   string
}

func (*Station) ExternalID

func (s *Station) ExternalID() (string, bool)

type StationsListResponse

type StationsListResponse struct {
	Countries []Country `json:"countries"`
}

type Stop

type Stop struct {
	Arrival   string  `json:"arrival"`
	Departure string  `json:"departure"`
	Terminal  string  `json:"terminal"`
	Station   Station `json:"station"`
	StopTime  int     `json:"stop_time"`
	Duration  float64 `json:"duration"`
}

type Thread

type Thread struct {
	UID              string  `json:"uid"`
	Title            string  `json:"title"`
	Number           string  `json:"number"`
	ShortTitle       string  `json:"short_title"`
	ThreadMethodLink string  `json:"thread_method_link"`
	Carrier          Carrier `json:"carrier"`
	Address          string  `json:"address"`
	Email            string  `json:"email"`
}

type ThreadRequest

type ThreadRequest struct {
	UID  string
	From string
	To   string
}

type ThreadResponse

type ThreadResponse struct {
	Days      string     `json:"days"`
	Stops     []Stop     `json:"stops"`
	Transport *Transport `json:"transport_subtype"`
}

type Transport

type Transport struct {
	// Основной цвет транспортного средства в шестнадцатеричном формате.
	Color string `json:"color"`
	// Код подтипа транспорта для типа, указанного в элементе transport_type. Подтип может совпадать с типом (например, для обычной электрички указывается тип suburban и подтип suburban).
	//
	// Другие возможные значения:
	//
	// helicopter — вертолет (для типа plane);
	// rex — экспресс РЭКС (для типа suburban);
	// sputnik — «Спутник» (для типа suburban);
	// skiarrow — «Лыжная стрела» (для типа suburban);
	// shezh — «Снежинка» (для типа suburban);
	// skirus — «Лыжня России» (для типа suburban);
	// city — городская электричка (для типа suburban);
	// kalina — «Калина красная» (для типа suburban);
	// vostok — «Восток» (для типа suburban);
	// prostoryaltaya — «Просторы Алтая» (для типа suburban);
	// 14vag — состав из 14 вагонов (для типа suburban);
	// last — «Ласточка» (для типа suburban);
	// exprdal — экспресс с билетами на конкретные места (для типа suburban);
	// volzhex — «Волжский экспресс» (для типа suburban);
	// stdplus — электрички типа «стандарт плюс» (для типа suburban);
	// express — экспресс (для типа suburban);
	// skor — ускоренный поезд (для типа suburban);
	// fiztekh — Физтех.Электричка (для типа suburban);
	// vag6 — состав из 6 вагонов (для типа suburban);
	// river— речной транспорт (для типа water);
	// sea — морской транспорт (для типа water).
	Code string `json:"code"`
	// Описание подтипа транспорта на естественном языке.
	Title string `json:"title"`
}

type TransportType

type TransportType string
const (
	Plane      TransportType = "plane"
	Train      TransportType = "train"
	Suburban   TransportType = "suburban"
	Bus        TransportType = "bus"
	Water      TransportType = "water"
	Helicopter TransportType = "helicopter"
)

func (TransportType) String

func (t TransportType) String() string

Jump to

Keyboard shortcuts

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