forked from jsgoecke/go-wit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intents.go
38 lines (33 loc) · 837 Bytes
/
intents.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2014 Jason Goecke
// intents.go
package wit
import (
"encoding/json"
)
// Represents intents in the Wit API (https://wit.ai/docs/api#toc_13)
type Intents []struct {
Id string `json:"id"`
Name string `json:"name"`
Doc string `json:"doc"`
Metadata string `json:"metadata"`
}
// Lists intents configured in the Wit API (https://wit.ai/docs/api#toc_13)
//
// result, err := client.Intents()
func (client *WitClient) Intents() (*Intents, error) {
result, err := get(client.ApiBase + "/intents")
if err != nil {
return nil, err
}
intents, _ := parseIntents(result)
return intents, nil
}
// Parses the JSON for an Intent
func parseIntents(data []byte) (*Intents, error) {
intents := &Intents{}
err := json.Unmarshal(data, intents)
if err != nil {
return nil, err
}
return intents, nil
}