add clientcredentials pkg for oauth2

This commit is contained in:
jybp
2019-05-29 21:20:49 +02:00
parent a63792e92f
commit b2dc7a86fd
5 changed files with 172 additions and 104 deletions

View File

@@ -0,0 +1,45 @@
// +build integration
package integration
import (
"context"
"os"
"testing"
_ "github.com/joho/godotenv/autoload"
"github.com/jybp/ebay"
"github.com/jybp/ebay/clientcredentials"
)
var client *ebay.Client
func init() {
clientID := os.Getenv("SANDBOX_CLIENT_ID")
clientSecret := os.Getenv("SANDBOX_CLIENT_SECRET")
if clientID == "" || clientSecret == "" {
panic("No SANDBOX_CLIENT_ID or SANDBOX_CLIENT_SECRET. Tests won't run.")
}
conf := clientcredentials.Config{
ClientID: clientID,
ClientSecret: clientSecret,
TokenURL: "https://api.sandbox.ebay.com/identity/v1/oauth2/token",
Scopes: []string{"https://api.ebay.com/oauth/api_scope"},
}
client = ebay.NewSandboxClient(conf.Client(context.Background()))
}
func TestAuthorization(t *testing.T) {
// https://developer.ebay.com/my/api_test_tool?index=0&api=browse&call=item_summary_search__GET&variation=json
req, err := client.NewRequest("GET", "buy/browse/v1/item_summary/search?q=test")
if err != nil {
t.Fatal(err)
}
into := map[string]interface{}{}
err = client.Do(context.Background(), req, &into)
if err != nil {
t.Fatal(err)
}
if testing.Verbose() {
t.Log(into)
}
}