Skip to content

Commit cb73243

Browse files
committed
updated readme
1 parent f44c46e commit cb73243

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

README.md

+93
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,95 @@
11
# combocurve-api-go
22
Simple go project, meant to replicate the light ComboCurve API Python SDK to allow for auth and pagination
3+
4+
5+
### Imports
6+
these are the main imports needed to complete authorization, and pagination with combocurve
7+
8+
```
9+
"github.com/agaddis02/combocurve-api-go/auth/combocurve_auth"
10+
"github.com/agaddis02/combocurve-api-go/auth/service_account"
11+
"github.com/agaddis02/combocurve-api-go/pagination"
12+
```
13+
14+
15+
### Example Usage
16+
```
17+
import (
18+
"fmt"
19+
"io"
20+
"log"
21+
"net/http"
22+
"os"
23+
24+
"github.com/joho/godotenv"
25+
26+
"github.com/agaddis02/combocurve-api-go/auth/combocurve_auth"
27+
"github.com/agaddis02/combocurve-api-go/auth/service_account"
28+
"github.com/agaddis02/combocurve-api-go/pagination"
29+
)
30+
31+
func main() {
32+
33+
// Load .env file
34+
err := godotenv.Load(".env")
35+
if err != nil {
36+
log.Fatalf("Error loading .env file")
37+
}
38+
39+
xApiKey := os.Getenv("X_API_KEY")
40+
41+
// Load in Service Account Json - Currently only supports from file
42+
sa, err := service_account.FromFile("./api-service-account-key.json")
43+
if err != nil {
44+
log.Fatalf("Failed to load service account: %v", err)
45+
}
46+
47+
// Create ComboCurveAuth
48+
auth, err := combocurve_auth.NewComboCurveAuth(&sa, xApiKey, 60, 60*60)
49+
if err != nil {
50+
log.Fatalf("Failed to create ComboCurveAuth: %v", err)
51+
}
52+
53+
// Get auth headers
54+
headers, err := auth.GetAuthHeaders()
55+
if err != nil {
56+
log.Fatalf("Failed to get auth headers: %v", err)
57+
}
58+
fmt.Printf("Auth headers: %v\n", headers)
59+
60+
// Make request
61+
url := "https://api.combocurve.com/v1/monthly-productions?take=1"
62+
method := "GET"
63+
64+
client := &http.Client{}
65+
req, err := http.NewRequest(method, url, nil)
66+
67+
if err != nil {
68+
fmt.Println(err)
69+
return
70+
}
71+
req.Header.Add("x-api-key", headers["x-api-key"])
72+
req.Header.Add("Authorization", headers["Authorization"])
73+
74+
res, err := client.Do(req)
75+
if err != nil {
76+
fmt.Println(err)
77+
return
78+
}
79+
defer res.Body.Close()
80+
81+
// Print response
82+
body, err := io.ReadAll(res.Body)
83+
if err != nil {
84+
fmt.Println(err)
85+
return
86+
}
87+
fmt.Println(string(body))
88+
89+
// Get next page url - similar to python library, this will just be an empty string is nothing further availble to proceed
90+
nextLink := pagination.GetNextPageURL(res.Header)
91+
92+
fmt.Println(nextLink)
93+
}
94+
95+
```

0 commit comments

Comments
 (0)