HTTP client that wraps the Publix services API with two endpoints: - /api/v4/savings — fetches weekly ad deals for a given store number - /api/v1/storelocation — finds nearby stores by ZIP code Includes request types (SavingsResponse, SavingItem, StoreResponse, Store) mapping directly to the Publix JSON schema. The client sends a PublixStore header for store-scoped requests and uses a 15-second timeout. Tests use httptest servers to verify header propagation, JSON decoding, and error handling for non-200 responses.
42 lines
1.5 KiB
Go
42 lines
1.5 KiB
Go
package api
|
|
|
|
// SavingsResponse is the top-level response from the Publix savings API.
|
|
type SavingsResponse struct {
|
|
Savings []SavingItem `json:"Savings"`
|
|
WeeklyAdLatestUpdatedDateTime string `json:"WeeklyAdLatestUpdatedDateTime"`
|
|
IsPersonalizationEnabled bool `json:"IsPersonalizationEnabled"`
|
|
LanguageID int `json:"LanguageId"`
|
|
}
|
|
|
|
// SavingItem represents a single deal/saving from the weekly ad.
|
|
type SavingItem struct {
|
|
ID string `json:"id"`
|
|
Title *string `json:"title"`
|
|
Description *string `json:"description"`
|
|
Savings *string `json:"savings"`
|
|
Department *string `json:"department"`
|
|
Brand *string `json:"brand"`
|
|
Categories []string `json:"categories"`
|
|
AdditionalDealInfo *string `json:"additionalDealInfo"`
|
|
ImageURL *string `json:"imageUrl"`
|
|
StartFormatted string `json:"wa_startDateFormatted"`
|
|
EndFormatted string `json:"wa_endDateFormatted"`
|
|
}
|
|
|
|
// StoreResponse is the top-level response from the store locator API.
|
|
type StoreResponse struct {
|
|
Stores []Store `json:"Stores"`
|
|
}
|
|
|
|
// Store represents a Publix store location.
|
|
type Store struct {
|
|
Key string `json:"KEY"`
|
|
Name string `json:"NAME"`
|
|
Addr string `json:"ADDR"`
|
|
City string `json:"CITY"`
|
|
State string `json:"STATE"`
|
|
Zip string `json:"ZIP"`
|
|
Distance string `json:"DISTANCE"`
|
|
Phone string `json:"PHONE"`
|
|
}
|