isutrain

package
v0.0.0-...-f1a69a6 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColumnA TrainSeatColumn = "A"
	ColumnB                 = "B"
	ColumnC                 = "C"
	ColumnD                 = "D"
	ColumnE                 = "E"
)

Variables

View Source
var (
	ErrCommitReservation = errors.New("存在しない予約IDの予約Commitを実施しようとしました")
	ErrCancelReservation = errors.New("存在しない予約IDの予約Cancelを実施しようとしました")
	ErrCanNotReserve     = errors.New("予約済みの座席が指定されたため予約できません")
)
View Source
var (
	ErrInvalidStationName = errors.New("駅名が不正です")
)
View Source
var (
	ErrNoSeats = errors.New("座席がありません")
)
View Source
var (
	ErrRedirect = errors.New("redirectが検出されました")
)
View Source
var (
	// RCache は、webappの予約に関する情報が適切か検証するために用いられるキャッシュです
	ReservationCache = newReservationCache()
)

Functions

func IsValidCarNumber

func IsValidCarNumber(carNum int) bool

func IsValidSeatClass

func IsValidSeatClass(seatClass string) bool

func IsValidStation

func IsValidStation(station string) bool

func IsValidStations

func IsValidStations(gotStations []*Station) bool

func IsValidTrainClass

func IsValidTrainClass(trainClass string) bool

func IsValidTrainSeatColumn

func IsValidTrainSeatColumn(seatColumn string) bool

Types

type CancelReservationResponse

type CancelReservationResponse struct {
	IsOK bool `json:"is_ok"`
}

予約キャンセルAPI

type Client

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

func NewClient

func NewClient() (*Client, error)

func NewClientForInitialize

func NewClientForInitialize() (*Client, error)

func (*Client) CancelReservation

func (c *Client) CancelReservation(ctx context.Context, reservationID int, opt ...ClientOption) error

func (*Client) CommitReservation

func (c *Client) CommitReservation(ctx context.Context, reservationID int, cardToken string, opt ...ClientOption) error

func (*Client) DownloadAsset

func (c *Client) DownloadAsset(ctx context.Context, path string) ([]byte, error)

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context)

func (*Client) ListReservations

func (c *Client) ListReservations(ctx context.Context, opt ...ClientOption) (ListReservationsResponse, error)

func (*Client) ListStations

func (c *Client) ListStations(ctx context.Context, opt ...ClientOption) (ListStationsResponse, error)

ListStations は駅一覧列挙APIです

func (*Client) Login

func (c *Client) Login(ctx context.Context, email, password string, opt ...ClientOption) error

func (*Client) Logout

func (c *Client) Logout(ctx context.Context, opt ...ClientOption) error

func (*Client) ReplaceMockTransport

func (c *Client) ReplaceMockTransport()

ReplaceMockTransport は、clientの利用するhttp.RoundTripperを、DefaultTransportに差し替えます NOTE: httpmockはhttp.DefaultTransportを利用するため、モックテストの時この関数を利用する

func (*Client) Reserve

func (c *Client) Reserve(
	ctx context.Context,
	trainClass, trainName string,
	seatClass string,
	seats TrainSeats,
	departure, arrival string,
	useAt time.Time,
	carNum int,
	child, adult int,
	opt ...ClientOption,
) (*ReserveResponse, error)

func (*Client) SearchTrainSeats

func (c *Client) SearchTrainSeats(ctx context.Context, date time.Time, trainClass, trainName string, carNum int, departure, arrival string, opt ...ClientOption) (*SearchTrainSeatsResponse, error)

func (*Client) SearchTrains

func (c *Client) SearchTrains(ctx context.Context, useAt time.Time, from, to, trainClass string, adult, child int, opt ...ClientOption) (SearchTrainsResponse, error)

SearchTrains は 列車検索APIです

func (*Client) Settings

func (c *Client) Settings(ctx context.Context) (*SettingsResponse, error)

func (*Client) ShowReservation

func (c *Client) ShowReservation(ctx context.Context, reservationID int, opt ...ClientOption) (ShowReservationResponse, error)

func (*Client) Signup

func (c *Client) Signup(ctx context.Context, email, password string, opt ...ClientOption) error

type ClientOption

type ClientOption func(o *ClientOptions)

func DisableAssertOpt

func DisableAssertOpt() ClientOption

func EnableAssertSeatCountOpt

func EnableAssertSeatCountOpt(count int) ClientOption

func IsOKOpt

func IsOKOpt(isOK bool) ClientOption

func StatusCodeOpt

func StatusCodeOpt(statusCode int) ClientOption

type ClientOptions

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

type CommitReservationRequest

type CommitReservationRequest struct {
	ReservationID int    `json:"reservation_id"`
	CardToken     string `json:"card_token"`
}

予約確定API

type CommitReservationResponse

type CommitReservationResponse struct {
	IsOK bool `json:"is_ok"`
}

予約確定API

type FareInformation

type FareInformation string
const (
	FiPremium       FareInformation = "premium"
	FiPremiumSmoke  FareInformation = "premium_smoke"
	FiReserved      FareInformation = "reserved"
	FiReservedSmoke FareInformation = "reserved_smoke"
	FiNonReserved   FareInformation = "non_reserved"
)

func (FareInformation) String

func (fi FareInformation) String() string

func (FareInformation) Value

func (fi FareInformation) Value() int

type InitializeResponse

type InitializeResponse struct {
	AvailableDays int    `json:"available_days"`
	Language      string `json:"language"`
}

type ListReservationsResponse

type ListReservationsResponse []*Reservation

予約詳細・列挙API

type ListStationsResponse

type ListStationsResponse []*Station

ListStationsResponse は /api/stations のレスポンス形式です

type Reservation

type Reservation struct {
	ReservationID int              `json:"reservation_id"`
	Date          string           `json:"date"`
	TrainClass    string           `json:"train_class"`
	TrainName     string           `json:"train_name"`
	CarNumber     int              `json:"car_number"`
	SeatClass     string           `json:"seat_class"`
	Amount        int              `json:"amount"`
	Adult         int              `json:"adult"`
	Child         int              `json:"child"`
	Departure     string           `json:"departure"`
	Arrival       string           `json:"arrival"`
	DepartureTime string           `json:"departure_time"`
	ArrivalTime   string           `json:"arrival_time"`
	Seats         ReservationSeats `json:"seats"`
}

予約詳細・列挙API

type ReservationCacheEntry

type ReservationCacheEntry struct {
	// ユーザ情報
	User *User

	// 予約情報
	ID int

	Date                  time.Time
	Departure, Arrival    string
	TrainClass, TrainName string
	CarNum                int

	SeatClass string
	Seats     TrainSeats

	Adult, Child int
}

func (*ReservationCacheEntry) Amount

func (r *ReservationCacheEntry) Amount() (int, error)

Amount は、大人と子供を考慮し、合計の運賃を算出します

func (*ReservationCacheEntry) SeatCount

func (r *ReservationCacheEntry) SeatCount() int

type ReservationSeat

type ReservationSeat struct {
	ReservationID int    `json:"reservation_id,omitempty" db:"reservation_id"`
	CarNumber     int    `json:"car_number,omitempty" db:"car_number"`
	SeatRow       int    `json:"seat_row" db:"seat_row"`
	SeatColumn    string `json:"seat_column" db:"seat_column"`
}

予約詳細・列挙API

type ReservationSeats

type ReservationSeats []*ReservationSeat

予約詳細・列挙API

func (ReservationSeats) GetNeighborSeatsBonus

func (seats ReservationSeats) GetNeighborSeatsBonus() int

隣り合うパターンを見つけたら加算する

type ReserveRequest

type ReserveRequest struct {
	Date          string     `json:"date"`
	TrainName     string     `json:"train_name"`
	TrainClass    string     `json:"train_class"`
	CarNum        int        `json:"car_number"`
	IsSmokingSeat bool       `json:"is_smoking_seat"`
	SeatClass     string     `json:"seat_class"`
	Departure     string     `json:"departure"`
	Arrival       string     `json:"arrival"`
	Child         int        `json:"child"`
	Adult         int        `json:"adult"`
	Column        string     `json:"Column"`
	Seats         TrainSeats `json:"seats"`
}

予約API /api/train/reserve

type ReserveResponse

type ReserveResponse struct {
	ReservationID int  `json:"reservation_id"`
	Amount        int  `json:"amount"`
	IsOk          bool `json:"is_ok"`
}

予約API /api/train/reserve

type SearchTrainSeatsResponse

type SearchTrainSeatsResponse struct {
	Date       string     `json:"date"`
	TrainClass string     `json:"train_class"`
	TrainName  string     `json:"train_name"`
	CarNumber  int        `json:"car_number"`
	Seats      TrainSeats `json:"seats"`
	Cars       TrainCars  `json:"cars"`
}

/api/train/seats のレスポンス形式

type SearchTrainsResponse

type SearchTrainsResponse []*Train

/api/train/search のレスポンス形式

type SeatAvailability

type SeatAvailability string
const (
	SaPremium       SeatAvailability = "premium"
	SaPremiumSmoke  SeatAvailability = "premium_smoke"
	SaReserved      SeatAvailability = "reserved"
	SaReservedSmoke SeatAvailability = "reserved_smoke"
	SaNonReserved   SeatAvailability = "non_reserved"
)

func (SeatAvailability) String

func (sa SeatAvailability) String() string

func (SeatAvailability) Value

func (sa SeatAvailability) Value() string

type Session

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

func NewSession

func NewSession() (*Session, error)

type SettingsResponse

type SettingsResponse struct {
	PaymentAPI string `json:"payment_api"`
}

type ShowReservationResponse

type ShowReservationResponse *Reservation

予約詳細・列挙API

type Station

type Station struct {
	ID                int     `json:"id"`
	Name              string  `json:"name"`
	Distance          float64 `json:"distance"`
	IsStopExpress     bool    `json:"is_stop_express"`
	IsStopSemiExpress bool    `json:"is_stop_semi_express"`
	IsStopLocal       bool    `json:"is_stop_local"`
}

type Train

type Train struct {
	Class            string            `json:"train_class"`
	Name             string            `json:"train_name"`
	Start            string            `json:"start"`
	Last             string            `json:"last"`
	Departure        string            `json:"departure"`
	Arrival          string            `json:"arrival"`
	DepartedAt       string            `json:"departure_time"`
	ArrivedAt        string            `json:"arrival_time"`
	SeatAvailability map[string]string `json:"seat_availability"`
	FareInformation  map[string]int    `json:"seat_fare"`
}

/api/train/search のレスポンス形式

type TrainCar

type TrainCar struct {
	CarNumber int    `json:"car_number"`
	SeatClass string `json:"seat_class"`
}

/api/train/seats のレスポンス形式

type TrainCars

type TrainCars []*TrainCar

/api/train/seats のレスポンス形式

func (TrainCars) IsSame

func (cars TrainCars) IsSame(gotCars TrainCars) bool

type TrainSeat

type TrainSeat struct {
	Row           int    `json:"row"`
	Column        string `json:"column"`
	Class         string `json:"class"`
	IsSmokingSeat bool   `json:"is_smoking_seat,omitempty"`
	IsOccupied    bool   `json:"is_occupied,omitempty"`
}

/api/train/seats のレスポンス形式

type TrainSeatColumn

type TrainSeatColumn string

func (TrainSeatColumn) Int

func (c TrainSeatColumn) Int() int

func (TrainSeatColumn) IsNeighbor

func (c TrainSeatColumn) IsNeighbor(c2 TrainSeatColumn) bool

type TrainSeats

type TrainSeats []*TrainSeat

/api/train/seats のレスポンス形式

func (TrainSeats) IsSame

func (seats TrainSeats) IsSame(gotSeats TrainSeats) bool

type User

type User struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

Jump to

Keyboard shortcuts

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