Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fareskato committed Mar 4, 2024
1 parent 181f67a commit 869566b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 135 deletions.
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,47 @@
- init your store like:

```golang
fStore := fkshopify.New("store user"), "store password", "store name", "api version", "web hook token")
myStore := fkshopify.New("store user"), "store password", "store name", "api version", "web hook token")
```

- then U can call resources functions like for example if U want to fetch all customers on store:

```golang
fStore.GetAllShopifyCustomers()
myStore.GetAllShopifyCustomers()
```

- ## Web Hooks

- the WebHookHandleActionEntity method handles create, update and delete
webhooks for all resources just need to pass the right data like the examples bellow:

```go
type Product struct {
ID int `json:"id"`
Title string `json:"title"`
BodyHTML string `json:"body_html,omitempty"`
}
type DeleteDate struct {
ID int `json:"id"`
}
// handle the create or update webhook
func yourHandler() {
var payload Product
body := ... //the request body
hmacHeader := .... // ge the X-Shopify-Hmac-SHA256 header
data, err := fkshopify.WebHookHandleActionEntity(myStore, payload, hmacHeader, body)
// handle the error
// U have the data sended via webhook
fmt.Printf("%#v\n", payload.Titlt)
}
// handle delete webhook
func anotherHandler() {
var payload DeleteDate
// the rest code is the same ....
}
```
3 changes: 3 additions & 0 deletions fkhttp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package fkhttp

import "regexp"

// ExtractPageInfoFromLinkHeader uses in case we have more than 250 items
// fetched from shopify (shopify limit) so we can use this function
// to gey the pagination link and get more than 250 items.
func ExtractPageInfoFromLinkHeader(linkHeader string) string {
re := regexp.MustCompile(`page_info=([^;&>]+)`)
matches := re.FindStringSubmatch(linkHeader)
Expand Down
52 changes: 0 additions & 52 deletions fkwebhooks/main.go

This file was deleted.

74 changes: 0 additions & 74 deletions fkwebhooks/product.go

This file was deleted.

7 changes: 0 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,3 @@ func (s Shopify) InitStoreHeaders() map[string]string {
"X-Shopify-Access-Token": s.storePassword,
}
}

// func (s Shopify) InitWebHook(hm, k string) fkwebhooks.WebHook {
// return fkwebhooks.WebHook{
// HmacHeader: hm,
// Key: k,
// }
// }
3 changes: 3 additions & 0 deletions webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"github.com/fareskato/fkshopify/fkutils"
)

// verifyWebHook takes the request bosdy and the X-Shopify-Hmac-SHA256 header sended
// by the web hook so U need to extract the X-Shopify-Hmac-SHA256 header
// from the request then pass it to the function
func (s Shopify) verifyWebHook(data []byte, hmacHeader string) bool {
secret := []byte(s.storeWebHookKey)
computedHMAC := hmac.New(sha256.New, secret)
Expand Down

0 comments on commit 869566b

Please sign in to comment.