|
1 | 1 | # plaid-go |
| 2 | + |
| 3 | +plaid-go is a Go client implementation of the [Plaid API](https://plaid.com/docs). |
| 4 | + |
| 5 | +Install via `go get github.com/plaid/plaid-go`. |
| 6 | + |
| 7 | +TODO: |
| 8 | +- Complete README |
| 9 | +- Complete testing |
| 10 | +- Add CI |
| 11 | + |
| 12 | + |
| 13 | +## Examples |
| 14 | + |
| 15 | +### Adding an Auth user |
| 16 | + |
| 17 | +```go |
| 18 | +client := plaid.NewClient("test_id", "test_secret", plaid.Tartan) |
| 19 | + |
| 20 | +// POST /auth |
| 21 | +postRes, mfaRes, err := client.AuthAddUser("plaid_test", "plaid_good", "", "bofa", nil) |
| 22 | +if err != nil { |
| 23 | + fmt.Println(err) |
| 24 | +} else if mfaRes != nil { |
| 25 | + // Need to switch on different MFA types. See https://plaid.com/docs/#mfa-auth. |
| 26 | + switch mfaRes.Type { |
| 27 | + case "device": |
| 28 | + fmt.Println("--Device MFA--") |
| 29 | + fmt.Println("Message:", mfaRes.Device.Message) |
| 30 | + case "list": |
| 31 | + fmt.Println("--List MFA--") |
| 32 | + fmt.Println("Mask:", mfaRes.List[0].Mask, "\nType:", mfaRes.List[0].Type) |
| 33 | + case "questions": |
| 34 | + fmt.Println("--Questions MFA--") |
| 35 | + fmt.Println("Question:", mfaRes.Questions[0].Question) |
| 36 | + case "selections": |
| 37 | + fmt.Println("--Selections MFA--") |
| 38 | + fmt.Println("Question:", mfaRes.Selections[1].Question) |
| 39 | + fmt.Println("Answers:", mfaRes.Selections[1].Answers) |
| 40 | + } |
| 41 | + |
| 42 | + postRes2, mfaRes2, err := client.AuthStepSendMethod(mfaRes.AccessToken, "type", "email") |
| 43 | + if err != nil { |
| 44 | + fmt.Println("Error submitting send_method", err) |
| 45 | + } |
| 46 | + fmt.Println(mfaRes2, postRes2) |
| 47 | + |
| 48 | + postRes2, mfaRes2, err = client.AuthStep(mfaRes.AccessToken, "tomato") |
| 49 | + if err != nil { |
| 50 | + fmt.Println("Error submitting mfa", err) |
| 51 | + } else { |
| 52 | + fmt.Println(mfaRes2, postRes2) |
| 53 | + } |
| 54 | +} else { |
| 55 | + fmt.Println(postRes.Accounts) |
| 56 | + fmt.Println("Auth Get") |
| 57 | + fmt.Println(client.AuthGet("test_bofa")) |
| 58 | + |
| 59 | + fmt.Println("Auth DELETE") |
| 60 | + fmt.Println(client.AuthDelete("test_bofa")) |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +### Querying a category |
| 65 | +```go |
| 66 | +// GET /categories/13001001 |
| 67 | +category, err := plaid.GetCategory(plaid.Tartan, "13001001") |
| 68 | +if err != nil { |
| 69 | + fmt.Println(err) |
| 70 | +} else { |
| 71 | + fmt.Println("category", category.ID, "is", strings.Join(category.Hierarchy, ", ")) |
| 72 | +} |
| 73 | +``` |
0 commit comments