Skip to content

Golang thin client to interact with Stop and Shop API.

Notifications You must be signed in to change notification settings

blaskovicz/go-stopandshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-stopandshop

Golang library for interacting with the Stop and Shop API.

Install

$ go get github.com/blaskovicz/go-stopandshop

Use

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)
  }
}

Test

$ go test ./...

About

Golang thin client to interact with Stop and Shop API.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages