Golang library for interacting with the Stop and Shop API.
$ go get github.com/blaskovicz/go-stopandshop
import (
sns "github.com/blaskovicz/go-stopandshop"
)
// initialize a default client
client := sns.New()
// log in must be called to access the api.
// this fetches an access token for bearer auth.
if err := client.Login("youremail@somewhere.com", "yourpassword"); err != nil {
panc(err)
}
// then fetch your profile info
profile, err := client.ReadProfile()
if err != nil {
panic(err)
}
// with the profile info, we can then check for coupons!
coupons, err := client.ReadCoupons(profile.CardNumber)
if err != nil {
panic(err)
}
fmt.Printf("Found %d coupons, maybe some free items?\n", len(coupons))
// and even load coupons to our card
for _, coupon := range coupons {
if coupon.Loaded {
continue
}
if err = client.LoadCoupon(profile.CardNumber, coupon.ID); err != nil {
panic(err)
}
}
// if any of the previous calls returned an error, we may need to refresh
// our access token:
if IsAccessTokenExpired(err) {
err = client.RefreshAccessToken()
if err != nil {
panic(err)
}
}
$ go test ./...