Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antonnagorniy/raindrop-io-api-client
https://github.com/antonnagorniy/raindrop-io-api-client
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/antonnagorniy/raindrop-io-api-client
- Owner: antonnagorniy
- License: apache-2.0
- Created: 2021-02-25T08:05:02.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-20T03:06:11.000Z (5 months ago)
- Last Synced: 2024-08-01T21:47:15.423Z (4 months ago)
- Language: Go
- Size: 95.7 KB
- Stars: 5
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- project-awesome - antonnagorniy/raindrop-io-api-client - (Go)
README
# Unofficial Raindrop.io API client
## Work in progress[![Actions Status](https://github.com/kattaris/raindrop-io-api-client/workflows/CI/badge.svg)](https://github.com/kattaris/raindrop-io-api-client/actions)
[![Coverage Status](https://codecov.io/github/kattaris/raindrop-io-api-client/coverage.svg?branch=master)](https://codecov.io/gh/kattaris/raindrop-io-api-client)
[![Releases](https://img.shields.io/github/v/release/kattaris/raindrop-io-api-client.svg?include_prereleases&style=flat-square)](https://github.com/kattaris/raindrop-io-api-client/releases)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)### Example usage:
```
package mainimport (
"fmt"
"github.com/kattaris/errhand"
"github.com/kattaris/raindrop-io-api-client/pkg/raindrop"
"net/http"
"net/url"
"os"
"os/exec"
"runtime"
"time"
)var log *errhand.Errhand
func init() {
log = errhand.New()
logPath := os.Getenv("LOGS") + "/raindrop/main.log"
log.CustomLogger(logPath, "debug")
}func main() {
client, err := raindrop.NewClient("5478394jfkdlsf843u430",
"e46b6a8a-018d-43b1-8b28-543kjl32ghj",
"http://localhost:8080/oauth")
log.HandleError(err, true)go func() {
http.HandleFunc("/oauth", client.GetAuthorizationCodeHandler)
err = http.ListenAndServe(":8080", nil)
log.HandleError(err, true)
}()// Step 1: The authorization request
authUrl, err := client.GetAuthorizationURL()
log.HandleError(err, true)// Step 2: The redirection to your application site
u, err := url.QueryUnescape(authUrl.String())
log.HandleError(err, true)
err = openBrowser(u)
log.HandleError(err, true)// Step 3: The token exchange
for client.ClientCode == "" {
log.Infoln("Waiting for client to authorize")
time.Sleep(3 * time.Second)
}accessTokenResp, err := client.GetAccessToken(client.ClientCode)
log.HandleError(err, true)
accessToken := accessTokenResp.AccessToken// Step 4: Check API's methods
result, err := client.CreateCollection(accessToken, true, "list",
"Test", 1, false, 0, nil)
log.HandleError(err, false)fmt.Printf("Create collection result: %v\n", result)
rootCollections, err := client.GetRootCollections(accessToken)
log.HandleError(err, false)
fmt.Printf("Root Collections: %v\n", rootCollections)childCollections, err := client.GetChildCollections(accessToken)
log.HandleError(err, false)
fmt.Printf("Child Collections: %v\n", childCollections)
}func openBrowser(url string) error {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}if err != nil {
log.Errorln(err)
}return err
}
```