tripadvisor

package
v0.0.0-...-17a064a Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// EndPointURL is the URL to the TripAdvisor GraphQL endpoint
	EndPointURL string = "https://www.tripadvisor.com/data/graphql/ids"

	// HotelQueryID is the pre-registered query ID for hotel reviews
	HotelQueryID string = "b83d781ada1db6f2"

	// AirlineQueryID is the pre-registered query ID for airline reviews
	AirlineQueryID string = "83003f8d5a7b1762"

	// ReviewLimit is the maximum number of reviews that can be fetched in a single request
	ReviewLimit uint32 = 20
)

Variables

This section is empty.

Functions

func CalculateIterations

func CalculateIterations(reviewCount uint32) (iterations uint32)

CalculateIterations is a function that calculates the number of iterations required to fetch all reviews

func CalculateOffset

func CalculateOffset(iteration uint32) (offset uint32)

CalculateOffset is a function that calculates the offset for the given iteration

func CheckIP

func CheckIP(client *http.Client) (ip string, err error)

CheckIP takes in a http client and calls ipinfo.io/ip to check the current IP address

func FetchReviewCount

func FetchReviewCount(client *http.Client, locationID uint32, queryType string, lang string) (reviewCount int, err error)

FetchReviewCount is a function that fetches the review count for the given location ID and query type

func GetQueryID

func GetQueryID(queryType string) (queryID string)

GetQueryID is a function that returns the query ID for the given query type

func GetURLType

func GetURLType(url string) string

GetURLType is a function that validates the URL and returns the type of URL

func ParseURL

func ParseURL(url string, locationType string) (locationID uint32, locationName string, error error)

ParseURL is a function that parses the URL and returns the location ID and the location name

Types

type Extensions

type Extensions struct {
	PreRegisteredQueryID string `json:"preRegisteredQueryId"`
}

Extensions is a struct that represents the extensions object in the request body to TripAdvisor endpoints.

type Filter

type Filter struct {
	Axis       string   `json:"axis"`
	Selections []string `json:"selections"`
}

Filter is a struct that represents the filter object in the request body to TripAdvisor endpoints

type Filters

type Filters []Filter

Filters is a slice of Filter structs.

type Request

type Request struct {
	Variables  Variables  `json:"variables"`
	Extensions Extensions `json:"extensions"`
}

Request is a struct that represents the request body to query TripAdvisor endpoints

type Requests

type Requests []Request

Requests is a slice of Request structs

type Response

type Response struct {
	Data struct {
		Locations []struct {
			ReviewListPage struct {
				TotalCount int `json:"totalCount"`
				Reviews    []struct {
					CreatedDate     string `json:"createdDate"`
					PublishedDate   string `json:"publishedDate"`
					Rating          int    `json:"rating"`
					PublishPlatform string `json:"publishPlatform"`
					TripInfo        struct {
						StayDate string `json:"stayDate"`
						TripType string `json:"tripType"`
					} `json:"tripInfo"`
					LocationID int      `json:"locationId"`
					Labels     []string `json:"labels"`
					Title      string   `json:"title"`
					Text       string   `json:"text"`
				} `json:"reviews"`
			} `json:"reviewListPage"`
		} `json:"locations"`
	} `json:"data,omitempty"`
}

Response is a struct that represents the response body from TripAdvisor endpoints

type Responses

type Responses []Response

Responses is a slice of Response structs

func MakeRequest

func MakeRequest(client *http.Client, queryID string, language string, locationID uint32, offset uint32, limit uint32) (responses *Responses, err error)

MakeRequest is a function that sends a POST request to the TripAdvisor GraphQL endpoint

type Variables

type Variables struct {
	LocationID   uint32  `json:"locationId"`
	Offset       uint32  `json:"offset"`
	Prefs        any     `json:"prefs"` // null
	Filters      Filters `json:"filters"`
	InitialPrefs struct {
	} `json:"initialPrefs"` // empty struct
	Limit          uint32 `json:"limit"`
	FilterCacheKey any    `json:"filterCacheKey"` // null
	PrefsCacheKey  string `json:"prefsCacheKey"`  // format "locationReviewPrefs_<localtionID>"
	NeedKeywords   bool   `json:"needKeywords"`   // false
	KeywordVariant string `json:"keywordVariant"`
}

Variables is a struct that represents the variables object in the request body to TripAdvisor endpoints

Jump to

Keyboard shortcuts

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