api

package
v0.0.0-...-e08e008 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Author: Bruce Jagid Created On: Aug 21, 2023

Author: Bruce Jagid Created On: Aug 12, 2023

**********************************************************************

General Purpose:

The api pkg is the abstraction layer for interacting with
external reservation services, such as resy and opentable.
All services implementing the API interface
are sub-pkgs of api

**********************************************************************

API:

The API interface specifies 3 methods:

    Login(params LoginParam) (*LoginResponse, error)
    Reserve(params ReserveParam) (*ReserveResponse, error)
    Search(params SearchParam) (*SearchResponse, error)

**********************************************************************

Login:

The Login function takes in a set of login credentials and returns
a response. The login credentials vary by external service, with
each defining its own set of necessary fields in each sub-pkg.
The output of the Login function is a LoginResponse, which should
be used as a token in the input params to a Reserve function
call. Login should always be used before a set of reservation
calls and is only used for the purpose of making reservations.

**********************************************************************

Reserve:

The Reserve function takes in a set of reserve parameters which
specify the date and a priority list of times to try and reserve
at and produces a response indicating the time made or an error.
This function's input parameters specifies a 'LoginResp' which
must be obtained by a 'Login' api function call, though such a
value only needs to be obtained before a series of Reserve calls.

**********************************************************************

Search:

The Search function takes in a set of query parameters which
specify the name of a restaurant and limit on responses and
produces a response with a slice of search results. These results
contain necessary and helpful data both for identifying the
intended restaurant to reserve at and also for making a
reservation request.

**********************************************************************

AuthMinExpire:

The AuthMinExpire function provides the minimum time irresepective
of time zone that a login token from the Login function is valid.
This function returns a constant value. If a null value is
returned, the login token is valid indefinitely.

**********************************************************************

Index

Constants

View Source
const (
	DiningRoom TableType = "dining"
	Indoor               = "indoor"
	Outdoor              = "outdoor"
	Patio                = "patio"
	Bar                  = "bar"
	Lounge               = "lounge"
	Booth                = "booth"
)

Variables

View Source
var (
	ErrLoginWrong = errors.New("invalid login credentials")
	ErrNoTable    = errors.New("no tables available matching reservation requests")
	ErrNetwork    = errors.New("unknown network error")
	ErrPastDate   = errors.New("latest reservation time has passed")
	ErrTimeNull   = errors.New("times list empty")
	ErrNoOffer    = errors.New("table is not offered on given date")
	ErrNoPayInfo  = errors.New("no payment info on account")
)

Functions

This section is empty.

Types

type API

type API interface {
	Login(params LoginParam) (*LoginResponse, error)
	Search(params SearchParam) (*SearchResponse, error)
	Reserve(params ReserveParam) (*ReserveResponse, error)
	AuthMinExpire() time.Duration
}

Name: API Type: Interface Purpose: Provide a minimal enough abstraction of common behavior among external reservation services to allow cross-platform application production

type LoginParam

type LoginParam struct {
	FirstName string
	LastName  string
	Mobile    string
	Email     string
	Password  string
}

Name: LoginParam Type: API Func Input Struct Purpose: Input parameters for the api function 'Login' Note: LoginParam is meant to hide login details from the app layer, but each individual external service has different login requirements.

Field Requirements for Resy:

  • Email: string
  • Password: string

Field Requirements for Opentable:

  • FirstName: string
  • LastName: string
  • Email: string
  • Mobile: string, omitting dashes and region indicator(i.e. the +1 for US)

type LoginResponse

type LoginResponse struct {
	ID              int64
	FirstName       string
	LastName        string
	Mobile          string
	Email           string
	PaymentMethodID int64
	AuthToken       string
}

Name: LoginResponse Type: API Func Output Struct Purpose: Output information for the api function 'Login' Note: LoginResponse is only meant to be used as an input to the 'Reserve' api function, and its internals are subject to change with any update, so no code should be written on another layer relying on the fields of this data structure

type ReserveParam

type ReserveParam struct {
	VenueID          int64
	ReservationTimes []time.Time
	PartySize        int
	TableTypes       []TableType
	LoginResp        LoginResponse
}

Name: ReserveParam Type: API Func Input Struct Purpose: Input information to the 'Reserve' api function

type ReserveResponse

type ReserveResponse struct {
	ReservationTime time.Time
}

Name: ReserveResponse Type: API Func Output Struct Purpose: Output information from the 'Reserve' api function

type SearchParam

type SearchParam struct {
	Name  string
	Limit int
}

Name: SeachParam Type: API Func Input Struct Purpose: Input information to the 'Search' api function

type SearchResponse

type SearchResponse struct {
	Results []SearchResult
}

Name: SeachResponse Type: API Func Output Struct Purpose: Output information from 'Search' api function

func (*SearchResponse) ToString

func (sr *SearchResponse) ToString() string

Name: SearchResponse.ToString Type: Stringify Func Purpose: Provide a default string representation of search responses amongst consumers of this layer

type SearchResult

type SearchResult struct {
	VenueID      int64
	Name         string
	Region       string
	Locality     string
	Neighborhood string
}

Name: SeachResult Type: API Output Struct Purpose: Output specific results from 'Search' api function

type TableType

type TableType string

Name: TableType Type: API Input Struct Purpose: Allow an opaque interface for choosing table/seating type

Directories

Path Synopsis
package opentable is an implementation of the api interface using opentable
package opentable is an implementation of the api interface using opentable

Jump to

Keyboard shortcuts

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