Skip to content

Commit 7bee80a

Browse files
committed
[ADD] Examples for all handlers
1 parent b47186b commit 7bee80a

File tree

11 files changed

+389
-0
lines changed

11 files changed

+389
-0
lines changed

examples/article/article.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/plaenkler/booklooker/api/handler"
8+
"github.com/plaenkler/booklooker/api/models"
9+
)
10+
11+
func main() {
12+
// Authenticate to obtain a token
13+
authReq := models.AuthenticateRequest{
14+
APIKey: "your_api_key",
15+
}
16+
authResp, err := handler.Authenticate(authReq)
17+
if err != nil {
18+
fmt.Println(err)
19+
return
20+
}
21+
if authResp.Status != "success" {
22+
fmt.Println(authResp.Message)
23+
return
24+
}
25+
token := authResp.Token
26+
27+
//
28+
req := models.ArticleRequest{
29+
OrderNo: "123",
30+
}
31+
32+
resp, err := handler.DeleteArticle(token, req)
33+
if err != nil {
34+
log.Fatalf("failed to delete article: %v", err)
35+
}
36+
fmt.Println("Article Deletion Status:", resp.Status)
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/plaenkler/booklooker/api/handler"
8+
"github.com/plaenkler/booklooker/api/models"
9+
)
10+
11+
func main() {
12+
// Authenticate to obtain a token
13+
authReq := models.AuthenticateRequest{
14+
APIKey: "your_api_key",
15+
}
16+
authResp, err := handler.Authenticate(authReq)
17+
if err != nil {
18+
fmt.Println(err)
19+
return
20+
}
21+
if authResp.Status != "success" {
22+
fmt.Println(authResp.Message)
23+
return
24+
}
25+
token := authResp.Token
26+
27+
//
28+
req := models.ArticleListRequest{
29+
Field: "title",
30+
ShowPrice: true,
31+
ShowStock: false,
32+
}
33+
34+
resp, err := handler.GetArticleList(token, req)
35+
if err != nil {
36+
log.Fatalf("failed to get article list: %v", err)
37+
}
38+
fmt.Println("Article List:", resp.ArticleList)
39+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/plaenkler/booklooker/api/handler"
7+
"github.com/plaenkler/booklooker/api/models"
8+
)
9+
10+
func main() {
11+
// Authenticate to obtain a token
12+
authReq := models.AuthenticateRequest{
13+
APIKey: "your_api_key",
14+
}
15+
authResp, err := handler.Authenticate(authReq)
16+
if err != nil {
17+
fmt.Println(err)
18+
return
19+
}
20+
if authResp.Status != "success" {
21+
fmt.Println(authResp.Message)
22+
return
23+
}
24+
token := authResp.Token
25+
26+
//
27+
req := models.ArticleStatusRequest{OrderNo: "order_no_value"}
28+
29+
resp, err := handler.GetArticleStatus(token, req)
30+
if err != nil {
31+
fmt.Println("error:", err)
32+
return
33+
}
34+
fmt.Println("response:", resp)
35+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
11
package main
2+
3+
import (
4+
"log"
5+
6+
"github.com/plaenkler/booklooker/api/handler"
7+
"github.com/plaenkler/booklooker/api/models"
8+
)
9+
10+
func main() {
11+
req := models.AuthenticateRequest{APIKey: "YOUR_API_KEY"}
12+
authResp, err := handler.Authenticate(req)
13+
if err != nil {
14+
log.Fatalf("Error authenticating: %v", err)
15+
}
16+
log.Println("Authentication response:", authResp)
17+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,44 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/plaenkler/booklooker/api/handler"
7+
"github.com/plaenkler/booklooker/api/models"
8+
)
9+
10+
func main() {
11+
// Authenticate to obtain a token
12+
authReq := models.AuthenticateRequest{
13+
APIKey: "your_api_key",
14+
}
15+
authResp, err := handler.Authenticate(authReq)
16+
if err != nil {
17+
fmt.Println(err)
18+
return
19+
}
20+
if authResp.Status != "success" {
21+
fmt.Println(authResp.Message)
22+
return
23+
}
24+
token := authResp.Token
25+
26+
// Import a file
27+
file := []byte("your file content")
28+
fileImportReq := models.FileImportRequest{
29+
File: file,
30+
FileType: "your file type",
31+
DataType: 1,
32+
FormatID: 123,
33+
Encoding: "your encoding",
34+
}
35+
fileImportResp, err := handler.ImportFile(token, fileImportReq)
36+
if err != nil {
37+
fmt.Println(err)
38+
return
39+
}
40+
if fileImportResp.Status != "success" {
41+
fmt.Println(fileImportResp.Message)
42+
return
43+
}
44+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/plaenkler/booklooker/api/handler"
8+
"github.com/plaenkler/booklooker/api/models"
9+
)
10+
11+
func main() {
12+
// Authenticate to obtain a token
13+
authReq := models.AuthenticateRequest{
14+
APIKey: "your_api_key",
15+
}
16+
authResp, err := handler.Authenticate(authReq)
17+
if err != nil {
18+
fmt.Println(err)
19+
return
20+
}
21+
if authResp.Status != "success" {
22+
fmt.Println(authResp.Message)
23+
return
24+
}
25+
token := authResp.Token
26+
27+
// Get file status
28+
fileStatusResp, err := handler.GetFileStatus(token, models.FileStatusRequest{Filename: "your_filename"})
29+
if err != nil {
30+
log.Fatalf("error getting file status: %v", err)
31+
}
32+
log.Println("file status:", fileStatusResp.Status)
33+
}

examples/order/order.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/plaenkler/booklooker/api/handler"
7+
"github.com/plaenkler/booklooker/api/models"
8+
)
9+
10+
func main() {
11+
// Authenticate to obtain a token
12+
authReq := models.AuthenticateRequest{
13+
APIKey: "your_api_key",
14+
}
15+
authResp, err := handler.Authenticate(authReq)
16+
if err != nil {
17+
fmt.Println(err)
18+
return
19+
}
20+
if authResp.Status != "success" {
21+
fmt.Println(authResp.Message)
22+
return
23+
}
24+
token := authResp.Token
25+
26+
// Get orders for a specific date or time range
27+
req := models.OrderRequest{
28+
OrderID: "123",
29+
Date: "2022-12-31",
30+
DateFrom: "",
31+
DateTo: "",
32+
}
33+
34+
orderResp, err := handler.GetOrder(token, req)
35+
if err != nil {
36+
fmt.Println("Error getting order:", err)
37+
return
38+
}
39+
40+
fmt.Println("Order response:", orderResp)
41+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,38 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/plaenkler/booklooker/api/handler"
7+
"github.com/plaenkler/booklooker/api/models"
8+
)
9+
10+
func main() {
11+
// Authenticate to obtain a token
12+
authReq := models.AuthenticateRequest{
13+
APIKey: "your_api_key",
14+
}
15+
authResp, err := handler.Authenticate(authReq)
16+
if err != nil {
17+
fmt.Println(err)
18+
return
19+
}
20+
if authResp.Status != "success" {
21+
fmt.Println(authResp.Message)
22+
return
23+
}
24+
token := authResp.Token
25+
26+
// Cancel an order
27+
req := models.OrderCancelRequest{
28+
OrderID: "123",
29+
}
30+
31+
orderCancelResp, err := handler.CancelOrder(token, req)
32+
if err != nil {
33+
fmt.Println("Error cancelling order:", err)
34+
return
35+
}
36+
37+
fmt.Println("Order cancel response:", orderCancelResp)
38+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/plaenkler/booklooker/api/handler"
7+
"github.com/plaenkler/booklooker/api/models"
8+
)
9+
10+
func main() {
11+
// Authenticate to obtain a token
12+
authReq := models.AuthenticateRequest{
13+
APIKey: "your_api_key",
14+
}
15+
authResp, err := handler.Authenticate(authReq)
16+
if err != nil {
17+
fmt.Println(err)
18+
return
19+
}
20+
if authResp.Status != "success" {
21+
fmt.Println(authResp.Message)
22+
return
23+
}
24+
token := authResp.Token
25+
26+
// Cancel an order item
27+
req := &models.OrderItemCancelRequest{
28+
OrderItemId: "order_item_id",
29+
MediaType: 1,
30+
}
31+
orderItemCancelResp, err := handler.PutOrderItemCancel(token, req)
32+
if err != nil {
33+
fmt.Println("Error:", err)
34+
return
35+
}
36+
if orderItemCancelResp.Status != "success" {
37+
fmt.Println(orderItemCancelResp.Message)
38+
return
39+
}
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
11
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/plaenkler/booklooker/api/handler"
8+
"github.com/plaenkler/booklooker/api/models"
9+
)
10+
11+
func main() {
12+
// Authenticate to obtain a token
13+
authReq := models.AuthenticateRequest{
14+
APIKey: "your_api_key",
15+
}
16+
authResp, err := handler.Authenticate(authReq)
17+
if err != nil {
18+
fmt.Println(err)
19+
return
20+
}
21+
if authResp.Status != "success" {
22+
fmt.Println(authResp.Message)
23+
return
24+
}
25+
token := authResp.Token
26+
27+
// Send a message to the customer
28+
req := models.OrderMessageRequest{
29+
OrderID: "ORDER_ID",
30+
MessageType: "MESSAGE_TYPE",
31+
AdditionalText: "ADDITIONAL_TEXT",
32+
}
33+
resp, err := handler.PutOrderMessage(token, req)
34+
if err != nil {
35+
log.Fatalln(err)
36+
}
37+
fmt.Println("Status:", resp.Status)
38+
fmt.Println("Message:", resp.Message)
39+
}

0 commit comments

Comments
 (0)