@@ -15,15 +15,18 @@ import (
1515
1616// Client the picnic api client it is recommended to use the New method to create a new instance
1717type Client struct {
18- http * http.Client
19- baseURL string
20- version string
21- country string
22- token string
23- username string
24- secret string
18+ http * http.Client
19+ baseURL string
20+ version string
21+ country string
22+ token string
23+ parsedToken * token
24+ username string
25+ secret string
2526}
2627
28+ const appVersion = "1.15.243-18832"
29+
2730type ClientOption func (client * Client )
2831
2932// WithVersion specify the particular version of the picnic API you wish to use.
@@ -182,7 +185,13 @@ func (c *Client) get(url string, result interface{}) error {
182185 if requestErr != nil {
183186 return requestErr
184187 }
185- configureHeaders (request , c .token )
188+ c .configureHeaders (request )
189+ if strings .Contains (url , "deliveries" ) {
190+ headerErr := c .includeAgentHeader (request )
191+ if headerErr != nil {
192+ return headerErr
193+ }
194+ }
186195 res , httpErr := c .http .Do (request )
187196 if httpErr != nil {
188197 return httpErr
@@ -207,7 +216,7 @@ func (c *Client) post(url string, body any, result interface{}) error {
207216 if requestErr != nil {
208217 return requestErr
209218 }
210- configureHeaders (request , c . token )
219+ c . configureHeaders (request )
211220 res , httpErr := c .http .Do (request )
212221 if httpErr != nil {
213222 return httpErr
@@ -263,7 +272,19 @@ func makeUrl(countryCode string, version string) string {
263272 return fmt .Sprintf ("https://storefront-prod.%s.picnicinternational.com/api/%s" , countryCode , version )
264273}
265274
266- func configureHeaders (request * http.Request , token string ) {
267- request .Header .Set ("x-picnic-auth" , token )
275+ func ( c * Client ) configureHeaders (request * http.Request ) {
276+ request .Header .Set ("x-picnic-auth" , c . token )
268277 request .Header .Set ("Content-Type" , "application/json" )
269278}
279+
280+ func (c * Client ) includeAgentHeader (request * http.Request ) error {
281+ if c .parsedToken == nil {
282+ err := c .parseJwt ()
283+ if err != nil {
284+ return err
285+ }
286+ }
287+ request .Header .Set ("x-picnic-agent" , fmt .Sprintf ("%d;%s;" , c .parsedToken .PcClid , appVersion ))
288+ request .Header .Set ("x-picnic-did" , c .parsedToken .PcDid )
289+ return nil
290+ }
0 commit comments