hotellook

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

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

Go to latest
Published: Mar 26, 2017 License: MIT Imports: 13 Imported by: 0

README

Hotellook API

Simple implementation of this API.

Make sure you have set valid marker and token before running tests.

If you don't have a token, you should pass searchID = -1 to FetchSearchResults - library will use real saved response from server.

Installation:

go get github.com/awskii/hotellook

Docs:

GoDoc or run

$ godoc github.com/awskii/hotellook

Example:

Getting hotels in Saint-Petersburg, Russia

package main

import (
    "log"
    "github.com/awskii/hotellook"
)

const (
    marker = 1234
    token = "your_api_token"
)

func main() {
    hl := hotellook.NewAPI(marker)
    hl.SetToken(token)
    lookupReq := &hotellook.LookupRequest{
        Query:   "Saint-Petersburg",
        Lang:    "en",
        LookFor: "both",
    }

    // Asking meta information about city (location, city ID and so on).
    res, err := hl.Lookup(lookupReq)
    if err != nil {
        log.Fatalln(err.Error())
    }
    if len(res.Results.Location) == 0 {
        log.Println("City not found")
        return
    }

    cityId := res.Results.Location[0].ID // 12196 = Saint-Petersburg, Russia 

    searchRequest := &hotellook.SearchRequest{
        CityID:        cityId,
        CheckIn:       "2016-12-31",
        CheckOut:      "2017-01-02",
        AdultsCount:   1,
        ChildrenCount: 0,
        Lang:          "en",
        Currency:      "usd",
    }
    searchID, err := hotellook.Search(searchRequest)
    if err != nil {
        log.Fatalln(err.Error())
    }

    resp, err := hl.FetchSearchResults(&hotellook.SearchResultsRequest{
        SearchID: searchID,
        SortBy:   "price",
        SortAsc:  1,
    })
    if err != nil {
        log.Fatalln(err.Error())
    }
    for _, h := range resp.Results{
        ...
    }

}

Documentation

Overview

Implements travelpayouts API for hotel searches. Some methods require valid marker and token. Some methods returns static data, so feel free to cache their response.

[Cities, Countries, Amenities, HotelList, RoomTypes, HotelTypes, Photos]

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAccess      = errors.New("You should specify valid token and marker to use this method")
	ErrEmptySearchID = errors.New("Empty search ID")
	ErrMissingParams = errors.New("Missing required parameters")
)

Functions

This section is empty.

Types

type API

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

func NewAPI

func NewAPI(marker int) *API

func (*API) Amenities

func (this *API) Amenities() ([]Amenity, error)

Fetch available facilities. Watch https://support.travelpayouts.com/hc/ru/articles/203956133-API-поиска-отелей#43

func (*API) Cities

func (this *API) Cities() (*[]Cities, error)

Fetch city list. Very long request. Watch https://support.travelpayouts.com/hc/ru/articles/203956133-API-поиска-отелей#42

func (*API) Countries

func (this *API) Countries() (*[]Countries, error)

Fetch contry list. Watch https://support.travelpayouts.com/hc/ru/articles/203956133-API-поиска-отелей#41

func (*API) FetchHotelList

func (this *API) FetchHotelList(locationId string) (*HotelList, error)

Fetch hotel list Watch https://support.travelpayouts.com/hc/ru/articles/203956133-API-поиска-отелей#44

func (*API) FetchSearchResults

func (this *API) FetchSearchResults(req *SearchResultsRequest) (*SearchResults, error)

func (*API) Lookup

func (this *API) Lookup(req *LookupRequest) (*LookupResponse, error)

Watch https://support.travelpayouts.com/hc/ru/articles/203956133-API-поиска-отелей#31

func (this *API) PhotoLink(hotelId, photoId int, size string) string

func (*API) Price

func (this *API) Price(req *PriceRequest) (*[]PriceResponse, error)

Watch https://support.travelpayouts.com/hc/ru/articles/203956133-API-поиска-отелей#34

func (*API) RequestsLimit

func (this *API) RequestsLimit() int

Returns numeric value of API rate limit. (X-Ratelimit-Limit )

func (*API) RequestsRemains

func (this *API) RequestsRemains() int

Return number of remaining requests to HotelLook API. (X-Ratelimit-Remaining )

func (*API) RoomTypes

func (this *API) RoomTypes() (*interface{}, error)

Fetch room types. Watch https://support.travelpayouts.com/hc/ru/articles/203956133-API-поиска-отелей#45

func (*API) Search

func (this *API) Search(req *SearchRequest) (int, error)

func (*API) SetToken

func (this *API) SetToken(token string)

type Amenity

type Amenity struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	GroupName string `json:"groupName"`
}

type Cities

type Cities struct {
	ID        string           `json:"id"` //locationID
	Code      string           `json:"code"`
	CountryID string           `json:"countryId"`
	Latitude  string           `json:"latitude"`
	Longitude string           `json:"longitude"`
	EN        []VariationBlock `json:"EN"`
	RU        []VariationBlock `json:"RU"`
}

type Countries

type Countries struct {
	ID   string           `json:"id"`
	Code string           `json:"code"`
	EN   []VariationBlock `json:"EN"`
	RU   []VariationBlock `json:"RU"`
}

type Hotel

type Hotel struct {
	ID            int     `json:"id"`
	CityID        int     `json:"cityId"`
	Stars         int     `json:"stars"`
	PriceFrom     int     `json:"pricefrom"`
	Rating        int     `json:"rating"`
	Popularity    int     `json:"popularity"`
	PropertyType  int     `json:"propertyType"`
	CheckIn       string  `json:"checkIn"`
	CheckOut      string  `json:"checkOut"`
	Distance      float64 `json:"distance"`
	YearOpened    int     `json:"yearOpened"`
	YearRenovated int     `json:"yearRenovated"`
	PhotoCount    int     `json:"photoCount"`
	Photos        []struct {
		URL    string `json:"url"`
		Width  int    `json:"width"`
		Height int    `json:"height"`
	} `json:"photos"`
	Facilities      []int    `json:"facilities"`
	ShortFacilities []string `json:"shortFacilities"`
	Location        struct {
		Latitude float64 `json:"lat"`
		Logitude float64 `json:"lon"`
	} `json:"location"`
	Name struct {
		EN string `json:"en"`
		RU string `json:"ru,omitempty"`
	} `json:"name"`
	CountFloors int `json:"cntFloors"`
	CountRooms  int `json:"cntRooms"`
	Address     struct {
		EN string `json:"en"`
		RU string `json:"ru,omitempty"`
	}
	Link string `json:"link"`
}

type HotelList

type HotelList struct {
	Timestamp float64 `json:"gen_timestamp"`
	Hotels    []Hotel `json:"hotels"`
}

type LookupRequest

type LookupRequest struct {
	Query string
	// Any ISO language code (fr, de, ru...). Default is en.
	Lang string
	// city/hotel/both
	// City - cities and islands
	// Hotel - only hotels
	// Both - all values. Default.
	LookFor string
	// 10 by default.
	Limit int
	// Automatically change of keyboard map (actual for russian users). Default 1.
	ConvertCase int
}

type LookupResponse

type LookupResponse struct {
	Status  string `json:"status"`
	Results struct {
		Locations []struct {
			CityName    string   `json:"cityName"`
			FullName    string   `json:"fullName"`
			CountryCode string   `json:"countryCode,omitempty"`
			CountryName string   `json:"countryName,omitempty"`
			Iata        []string `json:"iata"`
			ID          string   `json:"id"`
			HotelsCount string   `json:"hotelsCount"`
			Location    struct {
				Lat string `json:"lat"`
				Lon string `json:"lon"`
			} `json:"location"`
			Score float64 `json:"_score,omitempty"`
		} `json:"locations"`
		Hotels []struct {
			ID           interface{} `json:"id"`
			FullName     string      `json:"fullName"`
			LocationName string      `json:"locationName"`
			Label        string      `json:"label"`
			LocationID   int         `json:"locationId"`
			Location     struct {
				Lat float64 `json:"lat"`
				Lon float64 `json:"lon"`
			} `json:"location"`
			Score float64 `json:"_score"`
		} `json:"hotels"`
	} `json:"results"`
}

type PriceRequest

type PriceRequest struct {
	Location   string
	CheckIn    string // 2016-12-10
	CheckOut   string // 2016-12-10
	Currency   string
	LocationID int
	HotelID    int
	Hotel      string
	Adults     int // Number of adults. By default, it equals 2.
	Children   int // Childrens, age 2-18.
	Infants    int // Infants, ag 0-2.
	Limit      int
	CustomerIP net.IP
}

type PriceResponse

type PriceResponse struct {
	Stars      int     `json:"stars"`
	HotelID    int     `json:"hotelId"`
	HotelName  string  `json:"hotelName"`
	PriceAvg   float64 `json:"priceAvg"`
	PriceFrom  float64 `json:"priceFrom"`
	LocationID int     `json:"locationId"`
	Location   struct {
		Country string `json:"country"`
		State   string `json:"state"`
		Name    string `json:"name"`
		Geo     struct {
			Lon float64 `json:"lon"`
			Lat float64 `json:"lat"`
		} `json:"geo"`
	} `json:"location"`
}

type SearchRequest

type SearchRequest struct {
	CityID        int
	HotelID       int
	IATA          string
	CheckIn       string
	CheckOut      string
	AdultsCount   int
	ChildrenCount int
	ChildAges     [3]int
	CustomerIp    string
	Currency      string
	Lang          string
	WaitForResult int
}

type SearchResults

type SearchResults struct {
	Status  string `json:"status"`
	Results []struct {
		FullURL          string `json:"fullUrl"`          // ссылка на отель с вашим партнерским маркером
		MaxPricePerNight int    `json:"maxPricePerNight"` // максимальная цена за ночь;
		MinPriceTotal    int    `json:"minPriceTotal"`
		MaxPrice         int    `json:"maxPrice"`
		PhotoCount       int    `json:"photoCount"`
		GuestScore       int    `json:"guestScore"`
		Address          string `json:"address"`
		ID               int    `json:"id"`
		Price            int    `json:"price"` // средняя цена за номер;
		Name             string `json:"name"`
		URL              string `json:"url"`
		Popularity       int    `json:"popularity"`
		Location         struct {
			Lat float64 `json:"lat"`
			Lon float64 `json:"lon"`
		} `json:"location"`
		Stars    int     `json:"stars"`
		Distance float64 `json:"distance"` // расстояние от отеля до центра города;
		Rooms    []struct {
			AgencyID       string  `json:"agencyId"`
			AgencyName     string  `json:"agencyName"`
			BookingURL     string  `json:"bookingURL"`
			Type           string  `json:"type"`
			Tax            float64 `json:"tax"`
			Total          int     `json:"total"`
			Price          int     `json:"price"`
			FullBookingURL string  `json:"fullBookingURL"`
			Rating         int     `json:"rating"`
			Description    string  `json:"desc"`
			Options        struct {
				Available    int  `json:"available"`    // количество оставшихся комнат;
				Breakfast    bool `json:"breakfast"`    // включён ли завтрак;
				Refundable   bool `json":"refundable"`  // возможность возврата;
				Deposit      bool `json:"deposit"`      // оплата на сайте OTA (при бронировании);
				CardRequired bool `json:"cardRequired"` // обязательно наличие банковской карты;
				Smoking      bool `json:"smoking"`      // можно ли курить в номере;
				FreeWifi     bool `json:"freeWifi"`     // есть ли бесплатный wifi в номере;
				HotelWebsite bool `json:"hotelWebsite"` // предложение ведёт на официальный сайт отеля.
			} `json:"options"`
		} `json:"rooms"`
	} `json:"result"`
}

type SearchResultsRequest

type SearchResultsRequest struct {
	SearchID int // required
	Limit    int
	Offset   int
	// Sorty by [popularity|price|name|guestScore|stars]
	SortBy string
	// If you want to sort results by descending, set it equal to -1.
	SortAsc    int
	RoomsCount int
}

type VariationBlock

type VariationBlock struct {
	IsVariation string `json:"isVariation"`
	Name        string `json:"name"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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