Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Add a timestamp to every request to ensure that we're net being serve…
Browse files Browse the repository at this point in the history
…d cached responses
  • Loading branch information
ianmarmour committed Sep 22, 2020
1 parent bf7c2a0 commit ec8a04b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions internal/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ var session Session

const nvidiaAPIKey = "9485fa7b159e42edb08a83bde0d83dia"

func uniqueParam() string {
sec := time.Now().Unix()
return fmt.Sprintf("&=%v", sec)
}

//updateSession Updates the session variable.
func updateSession(sessionResponse string) {
jsonErr := json.Unmarshal([]byte(sessionResponse), &session)
Expand All @@ -60,15 +65,15 @@ func constructSessionURL(locale string) string {
localeParam := fmt.Sprintf("&locale=%s", locale)
apiKeyParam := fmt.Sprintf("&apiKey=%s", nvidiaAPIKey)

return baseURL + localeParam + apiKeyParam
return baseURL + localeParam + apiKeyParam + uniqueParam()
}

// GetInventoryStatus Retrieves sku inventory information from digitalriver
func GetInventoryStatus(ctx context.Context, sku string, locale string) (*InventoryStatus, error) {
baseURL := fmt.Sprintf("https://api.digitalriver.com/v1/shoppers/me/products/%s/inventory-status?", sku)
apiKeyParam := fmt.Sprintf("&apiKey=%s", nvidiaAPIKey)
localeParam := fmt.Sprintf("&locale=%s", locale)
stockURL := baseURL + apiKeyParam + localeParam
stockURL := baseURL + apiKeyParam + localeParam + uniqueParam()

var stockRequestID network.RequestID

Expand Down Expand Up @@ -116,7 +121,7 @@ func GetInventoryStatus(ctx context.Context, sku string, locale string) (*Invent

//Checkout Opens customer checkout
func Checkout(context context.Context, locale string) {
checkoutURL := fmt.Sprintf("https://api.digitalriver.com/v1/shoppers/me/carts/active/web-checkout?token=%s&locale=%s", session.AccessToken, locale)
checkoutURL := fmt.Sprintf("https://api.digitalriver.com/v1/shoppers/me/carts/active/web-checkout?token=%s&locale=%s", session.AccessToken, locale) + uniqueParam()

err := chromedp.Run(context,
chromedp.Navigate(checkoutURL),
Expand All @@ -133,7 +138,7 @@ func AddToCart(context context.Context, sku string, locale string) {
tokenParam := fmt.Sprintf("&token=%s", session.AccessToken)
quantityParam := "&quantity=1"
localeParam := fmt.Sprintf("&locale=%s", locale)
cartURL := baseURL + productIDParam + tokenParam + quantityParam + localeParam
cartURL := baseURL + productIDParam + tokenParam + quantityParam + localeParam + uniqueParam()

err := chromedp.Run(context,
chromedp.Navigate(cartURL),
Expand Down

0 comments on commit ec8a04b

Please sign in to comment.