Documentation ¶
Index ¶
- func CheckResponseForErrors(r *http.Response) error
- type ActiveOrdersRequest
- type Address
- type ArgumentError
- type AuthService
- type AuthServiceOp
- func (s *AuthServiceOp) Login(ctx context.Context, loginRequest *LoginRequest) (*LoginResponse, *http.Response, error)
- func (s *AuthServiceOp) Poll(ctx context.Context, pollRequest *PollRequest) (*PollResponse, *http.Response, error)
- func (s *AuthServiceOp) Refresh(ctx context.Context, refreshRequest *RefreshTokensRequest) (*RefreshTokensResponse, *http.Response, error)
- func (s *AuthServiceOp) Signup(ctx context.Context, signupRequest *SignupRequest) (*SignupResponse, *http.Response, error)
- type AverageOverallRating
- type Badges
- type Client
- type ClientOption
- type Country
- type Error
- type ErrorResponse
- type FavoriteItemRequest
- type GetItemRequest
- type GetItemResponse
- type InactiveOrdersRequest
- type Item
- type ItemCoverImage
- type Items
- type ItemsService
- type ItemsServiceOp
- func (s *ItemsServiceOp) Favorite(ctx context.Context, favoriteItemRequest *FavoriteItemRequest, itemID string) (*http.Response, error)
- func (s *ItemsServiceOp) Get(ctx context.Context, getItemRequest *GetItemRequest, itemID string) (*GetItemResponse, *http.Response, error)
- func (s *ItemsServiceOp) List(ctx context.Context, listItemsRequest *ListItemsRequest) (*ListItemsResponse, *http.Response, error)
- type ListItemsRequest
- type ListItemsResponse
- type Location
- type Login
- type LoginRequest
- type LoginResponse
- type Milestones
- type Order
- type OrdersResponse
- type OrdersService
- type OrdersServiceOp
- type Origin
- type Paging
- type PickupInterval
- type PickupLocation
- type Picture
- type PollRequest
- type PollResponse
- type Price
- type RefreshTokensRequest
- type RefreshTokensResponse
- type SalesTaxes
- type SignupRequest
- type SignupResponse
- type StartupData
- type Store
- type StoreItems
- type StoreLocation
- type StoreLogo
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponseForErrors ¶
CheckResponseForErrors checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 2xx range. Error response is expected to have either no response body, or a JSON response body that maps to ErrorResponse or plain text. Either way Client will log out the message.
Types ¶
type ActiveOrdersRequest ¶
type ActiveOrdersRequest struct {
UserID string `json:"user_id"`
}
ActiveOrdersRequest represents a request body to obtain user's active orders.
type Address ¶
type Address struct { AddressLine string `json:"address_line"` City string `json:"city"` Country Country `json:"country"` PostalCode string `json:"postal_code"` }
Address represents a Too Good To Go Address details.
type ArgumentError ¶
type ArgumentError struct {
// contains filtered or unexported fields
}
ArgumentError is an error that represents an issue with an input to Too Good To Go API client. Identifies input parameter and the cause.
func NewArgumentError ¶
func NewArgumentError(argument, reason string) *ArgumentError
NewArgumentError creates an ArgumentError.
func (*ArgumentError) Error ¶
func (e *ArgumentError) Error() string
Error implements error interface's method.
type AuthService ¶
type AuthService interface { Login(context.Context, *LoginRequest) (*LoginResponse, *http.Response, error) Poll(context.Context, *PollRequest) (*PollResponse, *http.Response, error) Refresh(context.Context, *RefreshTokensRequest) (*RefreshTokensResponse, *http.Response, error) Signup(context.Context, *SignupRequest) (*SignupResponse, *http.Response, error) }
AuthService is an interface for interfacing with the Auth related endpoints of the Too Good To Go API.
type AuthServiceOp ¶
type AuthServiceOp struct {
// contains filtered or unexported fields
}
AuthServiceOp handles communication with the Auth related methods of the Too Good To Go API.
func (*AuthServiceOp) Login ¶
func (s *AuthServiceOp) Login(ctx context.Context, loginRequest *LoginRequest) (*LoginResponse, *http.Response, error)
Login handles initiating authentication process. It does not return tokens. After Login user have to manually finish logging process using received mail.
Calling this endpoint frequently will cause 429 TOO_MANY_REQUESTS HTTP error, which will decay after ~15mins.
func (*AuthServiceOp) Poll ¶
func (s *AuthServiceOp) Poll(ctx context.Context, pollRequest *PollRequest) (*PollResponse, *http.Response, error)
Poll handles checking current authentication status.
If the login was finished using email, it return tokens, otherwise it errors out with EOF, empty body HTTP 202 ACCEPTED response.
func (*AuthServiceOp) Refresh ¶
func (s *AuthServiceOp) Refresh(ctx context.Context, refreshRequest *RefreshTokensRequest) (*RefreshTokensResponse, *http.Response, error)
Refresh handles refreshing tokens.
If refreshRequest does not specify refresh token to use, client will attempt to use one already stored. For that to work authenticate client first using Login and Poll, or use SetAuthContext manually.
func (*AuthServiceOp) Signup ¶
func (s *AuthServiceOp) Signup(ctx context.Context, signupRequest *SignupRequest) (*SignupResponse, *http.Response, error)
Signup handles signing up a new account.
type AverageOverallRating ¶
type AverageOverallRating struct { AverageOverallRating float64 `json:"average_overall_rating"` MonthCount int `json:"month_count"` RatingCount int `json:"rating_count"` }
AverageOverallRating represents a Too Good To Go AverageOverallRating details.
type Badges ¶
type Badges struct { BadgeType string `json:"badge_type"` MonthCount int `json:"month_count"` Percentage int `json:"percentage"` RatingGroup string `json:"rating_group"` UserCount int `json:"user_count"` }
Badges represents a Too Good To Go Badges details.
type Client ¶
type Client struct { // AccessToken used in subsequent API requests, if set. AccessToken string // RefreshToken used in refresh API request, if set. RefreshToken string // UserID is set at the end on successful logging attempt ending with Poll. // It is required in multiple Too Good To Go API calls. UserID string // Base URL for API requests, has to end with "/". BaseURL *url.URL // User agent for client. UserAgent string // Services used for communicating with the Too Good To Go API. Auth AuthService Items ItemsService Orders OrdersService // contains filtered or unexported fields }
Client represents Too Good To Go client.
func New ¶
func New(httpClient *http.Client, options ...ClientOption) (*Client, error)
New returns a new Too Good To Go API client.
Multiple ClientOptions can be passed to configure client.
func (*Client) Do ¶
Do sends Too Good To Go API request and returns response. The response is JSON decoded and stored in the value pointed to by v, or returned as an error if occurred.
func (*Client) NewRequest ¶
NewRequest creates Too Good To Go API request. Relative URL has to be provided in url, which will be merged with BaseURL of the Client. URL has to start with no "/" prefix, only relative URL is handled. If specified, the value pointing at body would be JSON encoded and included in as the request body.
func (*Client) SetAuthContext ¶
SetAuthContext sets Too Good To Go API auth context: access token, refresh token and user id.
type ClientOption ¶
ClientOption are options for New.
func SetRequestHeaders ¶
func SetRequestHeaders(headers map[string]string) ClientOption
SetRequestHeaders sets optional HTTP headers on the client that are sent on each HTTP request.
func SetUserAgent ¶
func SetUserAgent(userAgent string) ClientOption
SetUserAgent is a ClientOption for setting the user agent.
type Error ¶
type Error struct { // Code field is always set by Too Good To Go API. Code string `json:"code"` // Message is optional and not always returned. Message string `json:"message"` }
An Error represent the error returned from Too Good to Go API.
type ErrorResponse ¶
type ErrorResponse struct { // HTTP response that caused this error. Response *http.Response // Error body from Too Good To Go API. Errors []Error `json:"errors"` }
ErrorResponse represents error response returned from Too Good To Go API.
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type FavoriteItemRequest ¶
type FavoriteItemRequest struct {
IsFavorite bool `json:"is_favorite"`
}
FavoriteItemRequest represents a request body to un/set favorite item.
type GetItemRequest ¶
GetItemRequest represents a request body to get item details.
type GetItemResponse ¶
type GetItemResponse struct { Item Item `json:"item"` Store Store `json:"store"` DisplayName string `json:"display_name"` Distance float64 `json:"distance"` Favorite bool `json:"favorite"` InSalesWindow bool `json:"in_sales_window"` ItemsAvailable int `json:"items_available"` NewItem bool `json:"new_item"` PickupInterval PickupInterval `json:"pickup_interval"` PickupLocation PickupLocation `json:"pickup_location"` PurchaseEnd string `json:"purchase_end"` SharingURL string `json:"sharing_url"` }
GetItemResponse represents a response body with detailed item info.
type InactiveOrdersRequest ¶
InactiveOrdersRequest represents a request body to obtain user's inactive orders.
type Item ¶
type Item struct { AverageOverallRating AverageOverallRating `json:"average_overall_rating"` Badges []Badges `json:"badges"` Buffet bool `json:"buffet"` CanUserSupplyPackaging bool `json:"can_user_supply_packaging"` CollectionInfo string `json:"collection_info"` CoverPicture Picture `json:"cover_picture"` Description string `json:"description"` DietCategories []string `json:"diet_categories"` FavoriteCount int `json:"favorite_count"` ItemCategory string `json:"item_category"` ItemID string `json:"item_id"` LogoPicture Picture `json:"logo_picture"` Name string `json:"name"` PackagingOption string `json:"packaging_option"` PositiveRatingReasons []string `json:"positive_rating_reasons"` Price Price `json:"price"` PriceExcludingTaxes Price `json:"price_excluding_taxes"` PriceIncludingTaxes Price `json:"price_including_taxes"` SalesTaxes []SalesTaxes `json:"sales_taxes"` ShowSalesTaxes bool `json:"show_sales_taxes"` TaxAmount Price `json:"tax_amount"` TaxationPolicy string `json:"taxation_policy"` ValueExcludingTaxes Price `json:"value_excluding_taxes"` ValueIncludingTaxes Price `json:"value_including_taxes"` }
Item represents a Too Good To Go Item details.
type ItemCoverImage ¶
type ItemCoverImage struct { PictureID string `json:"picture_id"` CurrentURL string `json:"current_url"` IsAutomaticallyCreated bool `json:"is_automatically_created"` }
ItemCoverImage represents Too Good To Go Cover Image.
type Items ¶
type Items struct { Item Item `json:"item"` Store Store `json:"store"` DisplayName string `json:"display_name"` PickupInterval PickupInterval `json:"pickup_interval"` PickupLocation Location `json:"pickup_location"` PurchaseEnd time.Time `json:"purchase_end"` ItemsAvailable int `json:"items_available"` SoldOutAt time.Time `json:"sold_out_at"` Distance float64 `json:"distance"` Favorite bool `json:"favorite"` InSalesWindow bool `json:"in_sales_window"` NewItem bool `json:"new_item"` }
Items represents a Too Good To Go Items details.
type ItemsService ¶
type ItemsService interface { List(context.Context, *ListItemsRequest) (*ListItemsResponse, *http.Response, error) Get(context.Context, *GetItemRequest, string) (*GetItemResponse, *http.Response, error) Favorite(context.Context, *FavoriteItemRequest, string) (*http.Response, error) }
ItemsService is an interface for interfacing with the Items endpoints of the Too Good To Go API.
type ItemsServiceOp ¶
type ItemsServiceOp struct {
// contains filtered or unexported fields
}
ItemsServiceOp handles communication with the Items related methods of the Too Good To Go API.
func (*ItemsServiceOp) Favorite ¶
func (s *ItemsServiceOp) Favorite(ctx context.Context, favoriteItemRequest *FavoriteItemRequest, itemID string) (*http.Response, error)
Favorite handles setting particular item entry as favorite.
func (*ItemsServiceOp) Get ¶
func (s *ItemsServiceOp) Get(ctx context.Context, getItemRequest *GetItemRequest, itemID string) (*GetItemResponse, *http.Response, error)
Get handles getting specific information about particular item entry.
func (*ItemsServiceOp) List ¶
func (s *ItemsServiceOp) List(ctx context.Context, listItemsRequest *ListItemsRequest) (*ListItemsResponse, *http.Response, error)
List handles listing all items.
type ListItemsRequest ¶
type ListItemsRequest struct { PageSize int `json:"page_size"` Page int `json:"page"` UserID string `json:"user_id"` Radius int `json:"radius"` Origin *Origin `json:"origin"` ItemCategories []string `json:"item_categories"` DietCategories []string `json:"diet_categories"` PickupEarliest string `json:"pickup_earliest"` PickupLatest string `json:"pickup_latest"` SearchPhrase string `json:"search_phrase"` Discover bool `json:"discover"` FavoritesOnly bool `json:"favorites_only"` WithStockOnly bool `json:"with_stock_only"` HiddenOnly bool `json:"hidden_only"` WeCareOnly bool `json:"we_care_only"` }
ListItemsRequest represents a request body to list all items.
type ListItemsResponse ¶
type ListItemsResponse struct {
Items []Items `json:"items"`
}
ListItemsResponse represents a response body with detailed items list.
type Location ¶
type Location Origin
Location represents a Too Good To Go Location details which has same structure as Origin.
type Login ¶
type Login struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` AccessTokenTTL int `json:"access_token_ttl_seconds"` StartupData StartupData `json:"startup_data"` }
Login is a part of SignupResponse and represents a response body in sucessful signup process.
type LoginRequest ¶
LoginRequest represents a request body to initiate authentication process.
type LoginResponse ¶
LoginResponse represents a response body in authentication process.
type Milestones ¶
Milestones represents a Too Good To Go Milestones details.
type Order ¶
type Order struct { OrderID string `json:"order_id"` State string `json:"state"` CancelUntil time.Time `json:"cancel_until"` RedeemInterval PickupInterval `json:"redeem_interval"` PickupInterval PickupInterval `json:"pickup_interval"` Quantity int `json:"quantity"` PriceIncludingTaxes Price `json:"price_including_taxes"` PriceExcludingTaxes Price `json:"price_excluding_taxes"` TotalAppliedTaxes Price `json:"total_applied_taxes"` SalesTaxes []SalesTaxes `json:"sales_taxes"` PickupLocation PickupLocation `json:"pickup_location"` IsRated bool `json:"is_rated"` TimeOfPurchase time.Time `json:"time_of_purchase"` StoreID string `json:"store_id"` StoreName string `json:"store_name"` StoreBranch string `json:"store_branch"` StoreLogo StoreLogo `json:"store_logo"` ItemID string `json:"item_id"` ItemName string `json:"item_name"` ItemCoverImage ItemCoverImage `json:"item_cover_image"` IsBuffet bool `json:"is_buffet"` CanUserSupplyPackaging bool `json:"can_user_supply_packaging"` PackagingOption string `json:"packaging_option"` IsStoreWeCare bool `json:"is_store_we_care"` CanShowBestBeforeExplainer bool `json:"can_show_best_before_explainer"` ShowSalesTaxes bool `json:"show_sales_taxes"` }
Order represents Too Good To Go Order.
type OrdersResponse ¶
type OrdersResponse struct { CurrentTime time.Time `json:"current_time"` HasMore bool `json:"has_more"` Orders []Order `json:"orders"` }
OrdersResponse represents a response body containing Orders details.
type OrdersService ¶
type OrdersService interface { Active(context.Context, *ActiveOrdersRequest) (*OrdersResponse, *http.Response, error) Inactive(context.Context, *InactiveOrdersRequest) (*OrdersResponse, *http.Response, error) }
OrdersService is an interface for interfacing with the Orders endpoints of the Too Good To Go API.
type OrdersServiceOp ¶
type OrdersServiceOp struct {
// contains filtered or unexported fields
}
OrdersServiceOp handles communication with the Orders related methods of the Too Good To Go API.
func (*OrdersServiceOp) Active ¶
func (s *OrdersServiceOp) Active(ctx context.Context, activeOrdersRequest *ActiveOrdersRequest) (*OrdersResponse, *http.Response, error)
Active handles getting active orders for given user.
func (*OrdersServiceOp) Inactive ¶
func (s *OrdersServiceOp) Inactive(ctx context.Context, inactiveOrdersRequest *InactiveOrdersRequest) (*OrdersResponse, *http.Response, error)
Inactive handles getting inactive/past orders for given user.
type PickupInterval ¶
PickupInterval represents a Too Good To Go Pickup Interval details.
type PickupLocation ¶
PickupLocation represents a Too Good To Go Pickup Location details.
type PollRequest ¶
type PollRequest struct { DeviceType string `json:"device_type"` Email string `json:"email"` PollingID string `json:"request_polling_id"` }
PollRequest represents a request to check current authentication status.
type PollResponse ¶
type PollResponse struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` AccessTokenTTL int `json:"access_token_ttl_seconds"` StartupData StartupData `json:"startup_data"` }
PollResponse represents a response body in polling process.
type Price ¶
type Price struct { Code string `json:"code"` Decimals int `json:"decimals"` MinorUnits int `json:"minor_units"` }
Price represents a Too Good To Go Price details.
type RefreshTokensRequest ¶
type RefreshTokensRequest struct {
RefreshToken string `json:"refresh_token"`
}
RefreshTokensRequest represents a request body to refresh Too Good To Go tokens.
type RefreshTokensResponse ¶
type RefreshTokensResponse struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` AccessTokenTTL int `json:"access_token_ttl_seconds"` }
RefreshTokensResponse represents Too Good To Go Tokens returned in authentication process.
type SalesTaxes ¶
type SalesTaxes struct { TaxDescription string `json:"tax_description"` TaxPercentage float64 `json:"tax_percentage"` TaxAmount Price `json:"tax_amount"` }
SalesTaxes represents Too Good To Go Sales Taxes.
type SignupRequest ¶
type SignupRequest struct { CountryID string `json:"country_id"` DeviceType string `json:"device_type"` Email string `json:"email"` Name string `json:"name"` NewsletterOptIn bool `json:"newsletter_opt_in"` PushNotificationOptIn bool `json:"push_notification_opt_in"` }
SignupRequest represents a request body to create a new account.
type SignupResponse ¶
type SignupResponse struct {
Login Login `json:"login_response"`
}
SignupResponse represents a response body in signup process.
type StartupData ¶
type StartupData struct {
User User `json:"user"`
}
StartupData contains info about freshly authnticated user.
type Store ¶
type Store struct { Branch string `json:"branch"` CoverPicture Picture `json:"cover_picture"` Description string `json:"description"` Distance float64 `json:"distance"` FavoriteCount int `json:"favorite_count"` Hidden bool `json:"hidden"` Items []StoreItems `json:"items"` LogoPicture Picture `json:"logo_picture"` Milestones []Milestones `json:"milestones"` StoreID string `json:"store_id"` StoreLocation StoreLocation `json:"store_location"` StoreName string `json:"store_name"` StoreTimeZone string `json:"store_time_zone"` TaxIdentifier string `json:"tax_identifier"` WeCare bool `json:"we_care"` Website string `json:"website"` }
Store represents a Too Good To Go Store details.
type StoreItems ¶
type StoreItems struct { DisplayName string `json:"display_name"` Distance float64 `json:"distance"` Favorite bool `json:"favorite"` InSalesWindow bool `json:"in_sales_window"` Item Item `json:"item"` ItemsAvailable int `json:"items_available"` NewItem bool `json:"new_item"` PickupInterval PickupInterval `json:"pickup_interval"` PickupLocation PickupLocation `json:"pickup_location"` PurchaseEnd string `json:"purchase_end"` }
StoreItems represents a Too Good To Go Store Items details.
type StoreLocation ¶
type StoreLocation PickupLocation
StoreLocation represents a Too Good To Go Store Location details which has same structure as PickupLocation.