tripadvisor

package
v0.0.0-...-5867f33 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: GPL-3.0 Imports: 14 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"

	// AttractionQueryID is the pre-registered query ID for attraction reviews
	AttractionQueryID string = "b83d781ada1db6f2"

	// 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 CheckProxyConnection

func CheckProxyConnection(proxyHost string, timeout time.Duration) bool

CheckProxyConnection attempts to establish a TCP connection to the proxy server to determine if it is operational.

func FetchReviewCount

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

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

func GetHTTPClientWithProxy

func GetHTTPClientWithProxy(proxyHost string) (*http.Client, error)

GetHTTPClientWithProxy returns an HTTP client that uses the proxy server

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

func SortReviewsByDate

func SortReviewsByDate(reviews []Review)

SortReviewsByDate is a function that sorts the reviews by date This function modifies the original slice

func WriteReviewsToJSONFile

func WriteReviewsToJSONFile(reviews []Review, location Location, fileHandle *os.File) error

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 Feedback

type Feedback struct {
	Location `json:"location"`
	Reviews  []Review `json:"reviews"`
}

Feedback is a struct that represents the feedback object in the response body from 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 Location

type Location struct {
	LocationID            int    `json:"locationId"`
	ParentGeoID           int    `json:"parentGeoId"`
	PlaceType             string `json:"placeType"`
	ReviewSummary         ReviewSummary
	AccommodationCategory string             `json:"accommodationCategory"`
	ReviewAggregations    ReviewAggregations `json:"reviewAggregations"`
}

Location is a struct that represents the location object in the response body from TripAdvisor endpoints

type Photo

type Photo struct {
	ID         int      `json:"id"`
	Statuses   []string `json:"statuses"`
	PhotoSizes []struct {
		Width  int    `json:"width"`
		Height int    `json:"height"`
		URL    string `json:"url"`
	} `json:"photoSizes"`
}

Photo is a struct that represents the photo object in the response body from TripAdvisor endpoints

type Photos

type Photos []Photo

Photos is a slice of Photo 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 {
			Location
			ReviewListPage struct {
				TotalCount int      `json:"totalCount"`
				Reviews    []Review `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 Review

type Review struct {
	ID              int    `json:"id"`
	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"`
	PhotoIds    []int       `json:"photoIds"`
	LocationID  int         `json:"locationId"`
	Labels      []string    `json:"labels"`
	Title       string      `json:"title"`
	Text        string      `json:"text"`
	URL         string      `json:"url"`
	Photos      Photos      `json:"photos"`
	UserProfile UserProfile `json:"userProfile"`
	Username    string      `json:"username"`
}

Review is a struct that represents the review object in the response body from TripAdvisor endpoints

type ReviewAggregations

type ReviewAggregations struct {
	RatingCounts     []int          `json:"ratingCounts"`
	LanguageCounts   map[string]int `json:"languageCounts"`
	AlertStatusCount int            `json:"alertStatusCount"`
}

ReviewAggregations is a struct that represents the review aggregations object in the response body from TripAdvisor endpoints

type ReviewSummary

type ReviewSummary struct {
	Rating float32 `json:"rating"`
	Count  int     `json:"count"`
}

ReviewSummary is a struct that represents the review summary object in the response body from TripAdvisor endpoints

type UserProfile

type UserProfile struct {
	IsMe               bool `json:"isMe"`
	IsVerified         bool `json:"isVerified"`
	ContributionCounts struct {
		SumAllUgc   int `json:"sumAllUgc"`
		SumAllLikes int `json:"sumAllLikes"`
	} `json:"contributionCounts"`
	IsFollowing bool   `json:"isFollowing"`
	ID          string `json:"id"`
	UserID      string `json:"userId"`
	DisplayName string `json:"displayName"`
	Username    string `json:"username"`
	Hometown    struct {
		LocationID     interface{} `json:"locationId"`
		Location       interface{} `json:"location"`
		FallbackString interface{} `json:"fallbackString"`
	} `json:"hometown"`
	Route struct {
		URL string `json:"url"`
	} `json:"route"`
	Avatar struct {
		ID         int `json:"id"`
		PhotoSizes []struct {
			Width  int    `json:"width"`
			Height int    `json:"height"`
			URL    string `json:"url"`
		} `json:"photoSizes"`
	} `json:"avatar"`
}

UserProfile is a struct that represents the user profile object in the response body from TripAdvisor endpoints

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