Skip to content

Commit

Permalink
Merge pull request #6 from gandalf-network/feat/eb-docs-test
Browse files Browse the repository at this point in the history
Feat/eb docs test
  • Loading branch information
Bashorun97 authored Jun 15, 2024
2 parents 7ee8196 + 640f62f commit a412edc
Show file tree
Hide file tree
Showing 13 changed files with 5,374 additions and 94 deletions.
11 changes: 0 additions & 11 deletions .gitpod.yml

This file was deleted.

108 changes: 92 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ go get github.com/gandalf-network/gandalf-sdk-go/eyeofsauron
To generate the necessary files, use the following command:

```bash
go run github.com/gandalf-network/gandalf-sdk-go/eyeofsauron -f ./example/generated
go run github.com/gandalf-network/gandalf-sdk-go/eyeofsauron -f generated
```

#### Flags
Expand All @@ -38,7 +38,8 @@ package main
import (
"log"

"github.com/gandalf-network/gandalf-sdk-go/eyeofsauron/example/generated"
"github.com/gandalf-network/gandalf-sdk-go/connect"
"github.com/gandalf-network/gandalf-sdk-go/eyeofsauron/generated"
)

func main() {
Expand All @@ -60,20 +61,19 @@ import (
"fmt"
"log"

"github.com/gandalf-network/gandalf-sdk-go/eyeofsauron/example/generated"
"github.com/gandalf-network/gandalf-sdk-go/eyeofsauron/generated"
)

func getActivity() {
// Initialization
eye, err := generated.NewEyeOfSauron("<YOUR_GANDALF_PRIVATE_KEY")
if err != nil {
log.Fatalf("failed to initialize gandalf client: %s", err)
}
func main() {
// initialize eyeofsauron object
...


// Get activity
response, err := eye.GetActivity(
context.Background(),
"MY_DATA_KEY",
[]generated.ActivityType{generated.ActivityTypeWatch},
generated.SourceNetflix,
10,
1,
Expand Down Expand Up @@ -129,15 +129,12 @@ import (
"fmt"
"log"

"github.com/gandalf-network/gandalf-sdk-go/eyeofsauron/example/generated"
"github.com/gandalf-network/gandalf-sdk-go/eyeofsauron/generated"
)

func lookupActivity() {
// Initialization
eye, err := generated.NewEyeOfSauron("<YOUR_GANDALF_PRIVATE_KEY")
if err != nil {
log.Fatalf("failed to initialize gandalf client: %s", err)
}
func main() {
// initialize eyeofsauron object
...

// Lookup activity
response, err := eye.LookupActivity(
Expand Down Expand Up @@ -184,10 +181,55 @@ func printJSON(v interface{}) {
}
```


### Get Traits
```go
func main() {
// initialize eyeofsauron object
...

response, err := eye.GetTraits(context.Background(), "MY_DATA_KEY", generated.SourceNetflix, []generated.TraitLabel{generated.TraitLabelPlan})
if err != nil {
log.Fatalf("failed to get traits: %s", err)
}

fmt.Println("Get Traits", response.GetGetTraits())
}
```

### Lookup Traits
```go
func main() {
// initialize eyeofsauron object
...

traitID, err := uuid.Parse("MY_TRAIT_ID")
if err != nil {
log.Fatalf("failed to parse string to uuid")
}
response, err := eye.LookupTrait(context.Background(), "MY_DATA_KEY", traitID)
if err != nil {
log.Fatalf("failed to lookup trait: %s", err)
}

fmt.Println("Lookup Trait", response.GetLookupTrait())
}
```


## Connect

`Connect` is a library in Go that makes it easier to generate valid Connect URLs that let your users link their accounts to Gandalf. To use this library, follow the installation and usage instructions provided in the documentation.


### Connect installation

To install the `Connect` package, use the following command:

```bash
go get github.com/gandalf-network/gandalf-sdk-go/connect
```

```go
const publicKey = "0x036518f1c7a10fc77f835becc0aca9916c54505f771c82d87dd5943bb01ba5ca08";
const redirectURL = "https://example.com"
Expand Down Expand Up @@ -230,4 +272,38 @@ func main() {
}
fmt.Println("Base64 QR Code => ", qrCode)
}
```

#### Generate URL for Android
```go
import (
...
"github.com/gandalf-network/gandalf-sdk-go/eyeofsauron/generated"
)

func main() {
// Define the input data
services := connect.InputData{
"netflix": connect.Service{
Traits: []string{"rating"},
Activities: []string{"watch"},
},
}

// Define the config parameters
config := connect.Config{
PublicKey: publicKey,
RedirectURL: redirectURL,
Data: services,
Platform: connect.PlatformTypeAndroid,
}

// Call the GenerateURL method for Android
androidUrl, err := conn.GenerateURL()
if err != nil {
log.Fatalf("An error occurred generating url: %v", err)
}
fmt.Println("URL => ", androidUrl)
}

```
7 changes: 3 additions & 4 deletions connect/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"log"
"net/url"
"os"
"strings"

"github.com/gandalf-network/gandalf-sdk-go/eyeofsauron/constants"
Expand All @@ -17,8 +16,8 @@ import (

var (
IOS_APP_CLIP_BASE_URL = "https://appclip.apple.com/id?p=network.gandalf.connect.Clip"
ANDROID_APP_CLIP_BASE_URL = os.Getenv("ANDROID_APP_CLIP_BASE_URL")
UNIVERSAL_APP_CLIP_BASE_URL = os.Getenv("UNIVERSAL_APP_CLIP_BASE_URL")
ANDROID_APP_CLIP_BASE_URL = "https://auth.gandalf.network"
UNIVERSAL_APP_CLIP_BASE_URL = "https://auth.gandalf.network"
SAURON_BASE_URL = "https://sauron.gandalf.network/public/gql"
)

Expand Down Expand Up @@ -307,7 +306,7 @@ func (c *Connect) encodeComponents(data, redirectUrl string, publicKey string) (
encodedRedirectURL := url.QueryEscape(redirectUrl)
encodedPublicKey := url.QueryEscape(publicKey)

return fmt.Sprintf("%s&data=%s&redirectUrl=%s&publicKey=%s", baseURL, encodedServices, encodedRedirectURL, encodedPublicKey), nil
return fmt.Sprintf("%s?data=%s&redirectUrl=%s&publicKey=%s", baseURL, encodedServices, encodedRedirectURL, encodedPublicKey), nil
}

func servicesToJSON(services InputData) []byte {
Expand Down
19 changes: 18 additions & 1 deletion connect/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ func main() {
log.Fatalf("An error occurred with initializing connect: %v", err)
}


// Generate URL
url, err := conn.GenerateURL()
if err != nil {
log.Fatalf("An error occurred generating url: %v", err)
}
fmt.Println("URL => ", url)


// Generate QRCode
qrCode, err := conn.GenerateQRCode()
if err != nil {
log.Fatalf("An error occurred generating QR Code url: %v", err)
Expand All @@ -64,4 +65,20 @@ func main() {
}

fmt.Printf("Decoded QR code saved to %s\n", outputFile)


// Set Android Platform
config.Platform = connect.PlatformTypeAndroid

conn, err = connect.NewConnect(config)
if err != nil {
log.Fatalf("An error occurred with initializing connect: %v", err)
}

// GenerateURL method for Android
androidUrl, err := conn.GenerateURL()
if err != nil {
log.Fatalf("An error occurred generating url: %v", err)
}
fmt.Println("Android URL => ", androidUrl)
}
Loading

0 comments on commit a412edc

Please sign in to comment.