package giltpublicapi /** * Generated by API Builder - https://www.apibuilder.io * Service version: 1.0.1 * User agent: apibuilder app.apibuilder.io/gilt/gilt-public-api/1.0.1/go_1_5_client */ import ( "bytes" "encoding/json" "errors" "fmt" "html" "io" "net/http" "net/url" "strconv" "strings" ) const BaseUrl = "https://api.gilt.com/v1" const UserAgent = "apibuilder app.apibuilder.io/gilt/gilt-public-api/1.0.1/go_1_5_client" const Version = "1.0.1" const VersionMajor = 1 type Client struct { HttpClient *http.Client Username string Password string BaseUrl string Headers http.Header } /** * Gilt.com is divided into stores. Currently there are four stores exposed by the * API: Women, Men, Baby & Kids and Home. */ type Store string const ( StoreWomen Store = "women" StoreMen = "men" StoreKids = "kids" StoreHome = "home" StoreUNDEFINED = "UNDEFINED" ) func StoreFromString(value string) Store { switch strings.TrimSpace(strings.ToLower(value)) { case "women": return StoreWomen case "men": return StoreMen case "kids": return StoreKids case "home": return StoreHome default: return StoreUNDEFINED } } type Product struct { Name string `json:"name"` Product string `json:"product"` Id int64 `json:"id"` Brand string `json:"brand"` Url string `json:"url"` Content ProductContent `json:"content"` Categories []string `json:"categories"` ImageUrls map[string]interface{} `json:"image_urls"` Skus []Sku `json:"skus"` } func ProductFromMap(data interface{}) Product { b, err := json.Marshal(data) if err == nil { return ProductFromJson(bytes.NewReader(b)) } else { panic(err) } } func ProductFromJson(bytes io.Reader) Product { var product Product json.NewDecoder(bytes).Decode(&product) return product } type ProductCategories struct { Categories []string `json:"categories"` } func ProductCategoriesFromMap(data interface{}) ProductCategories { b, err := json.Marshal(data) if err == nil { return ProductCategoriesFromJson(bytes.NewReader(b)) } else { panic(err) } } func ProductCategoriesFromJson(bytes io.Reader) ProductCategories { var productCategories ProductCategories json.NewDecoder(bytes).Decode(&productCategories) return productCategories } type ProductContent struct { Description string `json:"description,omitempty"` FitNotes string `json:"fit_notes,omitempty"` Material string `json:"material,omitempty"` CareInstructions string `json:"care_instructions,omitempty"` Origin string `json:"origin,omitempty"` } func ProductContentFromMap(data interface{}) ProductContent { b, err := json.Marshal(data) if err == nil { return ProductContentFromJson(bytes.NewReader(b)) } else { panic(err) } } func ProductContentFromJson(bytes io.Reader) ProductContent { var productContent ProductContent json.NewDecoder(bytes).Decode(&productContent) return productContent } type SaleDetail struct { Name string `json:"name"` Sale string `json:"sale"` SaleKey string `json:"sale_key"` Store Store `json:"store"` Description string `json:"description,omitempty"` SaleUrl string `json:"sale_url"` Begins string `json:"begins"` Ends string `json:"ends,omitempty"` ImageUrls map[string]interface{} `json:"image_urls"` Products []string `json:"products,omitempty"` } func SaleDetailFromMap(data interface{}) SaleDetail { b, err := json.Marshal(data) if err == nil { return SaleDetailFromJson(bytes.NewReader(b)) } else { panic(err) } } func SaleDetailFromJson(bytes io.Reader) SaleDetail { var saleDetail SaleDetail json.NewDecoder(bytes).Decode(&saleDetail) return saleDetail } type SaleList struct { Sales []SaleDetail `json:"sales"` } func SaleListFromMap(data interface{}) SaleList { b, err := json.Marshal(data) if err == nil { return SaleListFromJson(bytes.NewReader(b)) } else { panic(err) } } func SaleListFromJson(bytes io.Reader) SaleList { var saleList SaleList json.NewDecoder(bytes).Decode(&saleList) return saleList } type Sku struct { Id int64 `json:"id"` InventoryStatus string `json:"inventory_status"` MsrpPrice float64 `json:"msrp_price"` SalePrice float64 `json:"sale_price"` ShippingSurcharge float64 `json:"shipping_surcharge,omitempty"` Attributes []map[string]interface{} `json:"attributes"` } func SkuFromMap(data interface{}) Sku { b, err := json.Marshal(data) if err == nil { return SkuFromJson(bytes.NewReader(b)) } else { panic(err) } } func SkuFromJson(bytes io.Reader) Sku { var sku Sku json.NewDecoder(bytes).Decode(&sku) return sku } type ProductsGetDetailJsonByProductIdParams struct { Apikey string } type ProductsGetDetailJsonByProductIdResponse struct { StatusCode int Response *http.Response Error error Product Product } func ProductsGetDetailJsonByProductId(client Client, productId string, params ProductsGetDetailJsonByProductIdParams) ProductsGetDetailJsonByProductIdResponse { requestUrl := fmt.Sprintf("%s/products/%s/detail.json", client.BaseUrl, html.EscapeString(productId)) urlValues := url.Values{} if "" != params.Apikey { urlValues.Add("apikey", params.Apikey) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl) if err != nil { return ProductsGetDetailJsonByProductIdResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ProductsGetDetailJsonByProductIdResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ProductsGetDetailJsonByProductIdResponse{StatusCode: resp.StatusCode, Response: resp, Product: ProductFromJson(resp.Body)} default: return ProductsGetDetailJsonByProductIdResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type ProductsGetCategoriesJsonParams struct { Apikey string } type ProductsGetCategoriesJsonResponse struct { StatusCode int Response *http.Response Error error ProductCategories ProductCategories } func ProductsGetCategoriesJson(client Client, params ProductsGetCategoriesJsonParams) ProductsGetCategoriesJsonResponse { requestUrl := fmt.Sprintf("%s/products/categories.json", client.BaseUrl) urlValues := url.Values{} if "" != params.Apikey { urlValues.Add("apikey", params.Apikey) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl) if err != nil { return ProductsGetCategoriesJsonResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return ProductsGetCategoriesJsonResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return ProductsGetCategoriesJsonResponse{StatusCode: resp.StatusCode, Response: resp, ProductCategories: ProductCategoriesFromJson(resp.Body)} default: return ProductsGetCategoriesJsonResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SaleDetailsGetDetailJsonParams struct { Apikey string } type SaleDetailsGetDetailJsonResponse struct { StatusCode int Response *http.Response Error error SaleDetail SaleDetail } func SaleDetailsGetDetailJson(client Client, store Store, sale string, params SaleDetailsGetDetailJsonParams) SaleDetailsGetDetailJsonResponse { requestUrl := fmt.Sprintf("%s/sales/%s/%sdetail.json", client.BaseUrl, string(store), html.EscapeString(sale)) urlValues := url.Values{} if "" != params.Apikey { urlValues.Add("apikey", params.Apikey) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl) if err != nil { return SaleDetailsGetDetailJsonResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SaleDetailsGetDetailJsonResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SaleDetailsGetDetailJsonResponse{StatusCode: resp.StatusCode, Response: resp, SaleDetail: SaleDetailFromJson(resp.Body)} default: return SaleDetailsGetDetailJsonResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SaleListGetActiveJsonParams struct { Apikey string } type SaleListGetActiveJsonResponse struct { StatusCode int Response *http.Response Error error SaleList SaleList } func SaleListGetActiveJson(client Client, params SaleListGetActiveJsonParams) SaleListGetActiveJsonResponse { requestUrl := fmt.Sprintf("%s/sales/active.json", client.BaseUrl) urlValues := url.Values{} if "" != params.Apikey { urlValues.Add("apikey", params.Apikey) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl) if err != nil { return SaleListGetActiveJsonResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SaleListGetActiveJsonResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SaleListGetActiveJsonResponse{StatusCode: resp.StatusCode, Response: resp, SaleList: SaleListFromJson(resp.Body)} default: return SaleListGetActiveJsonResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SaleListGetActiveJsonByStoreParams struct { Apikey string } type SaleListGetActiveJsonByStoreResponse struct { StatusCode int Response *http.Response Error error SaleList SaleList } func SaleListGetActiveJsonByStore(client Client, store string, params SaleListGetActiveJsonByStoreParams) SaleListGetActiveJsonByStoreResponse { requestUrl := fmt.Sprintf("%s/sales/%s/active.json", client.BaseUrl, html.EscapeString(store)) urlValues := url.Values{} if "" != params.Apikey { urlValues.Add("apikey", params.Apikey) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl) if err != nil { return SaleListGetActiveJsonByStoreResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SaleListGetActiveJsonByStoreResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SaleListGetActiveJsonByStoreResponse{StatusCode: resp.StatusCode, Response: resp, SaleList: SaleListFromJson(resp.Body)} default: return SaleListGetActiveJsonByStoreResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SaleListGetUpcomingJsonParams struct { Apikey string } type SaleListGetUpcomingJsonResponse struct { StatusCode int Response *http.Response Error error SaleList SaleList } func SaleListGetUpcomingJson(client Client, params SaleListGetUpcomingJsonParams) SaleListGetUpcomingJsonResponse { requestUrl := fmt.Sprintf("%s/sales/upcoming.json", client.BaseUrl) urlValues := url.Values{} if "" != params.Apikey { urlValues.Add("apikey", params.Apikey) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl) if err != nil { return SaleListGetUpcomingJsonResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SaleListGetUpcomingJsonResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SaleListGetUpcomingJsonResponse{StatusCode: resp.StatusCode, Response: resp, SaleList: SaleListFromJson(resp.Body)} default: return SaleListGetUpcomingJsonResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } type SaleListGetUpcomingJsonByStoreParams struct { Apikey string } type SaleListGetUpcomingJsonByStoreResponse struct { StatusCode int Response *http.Response Error error SaleList SaleList } func SaleListGetUpcomingJsonByStore(client Client, store string, params SaleListGetUpcomingJsonByStoreParams) SaleListGetUpcomingJsonByStoreResponse { requestUrl := fmt.Sprintf("%s/sales/%s/upcoming.json", client.BaseUrl, html.EscapeString(store)) urlValues := url.Values{} if "" != params.Apikey { urlValues.Add("apikey", params.Apikey) } encodedValues := urlValues.Encode() if encodedValues != "" { requestUrl += "?" + encodedValues } request, err := buildRequest(client, "GET", requestUrl) if err != nil { return SaleListGetUpcomingJsonByStoreResponse{Error: err} } resp, err := client.HttpClient.Do(request) if err != nil { return SaleListGetUpcomingJsonByStoreResponse{Error: err} } defer resp.Body.Close() switch resp.StatusCode { case 200: return SaleListGetUpcomingJsonByStoreResponse{StatusCode: resp.StatusCode, Response: resp, SaleList: SaleListFromJson(resp.Body)} default: return SaleListGetUpcomingJsonByStoreResponse{StatusCode: resp.StatusCode, Response: resp, Error: errors.New(resp.Status)} } } func buildRequest(client Client, method, urlStr string) (*http.Request, error) { request, err := http.NewRequest(method, urlStr, nil) if err != nil { return nil, err } request.Header.Add("User-Agent", UserAgent) request.Header.Add("X-Apidoc-Version", Version) request.Header.Add("X-Apidoc-Version-Major", strconv.Itoa(VersionMajor)) if client.Headers != nil { for key, values := range client.Headers { for _, value := range values { request.Header.Add(key, value) } } } if client.Username != "" { request.SetBasicAuth(client.Username, client.Password) } return request, nil }