forked from tmc/openfec
/
openfec_test.go
47 lines (43 loc) · 913 Bytes
/
openfec_test.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
39
40
41
42
43
44
45
46
47
package openfec_test
import (
"fmt"
"log"
"os"
"github.com/tmc/openfec"
)
func ExampleNewClient() {
apiKey := os.Getenv("DATA_GOV_API_KEY")
client, err := openfec.NewClient(apiKey)
if err != nil {
log.Fatalln(client)
}
candidates, err := client.GetCandidates(nil)
fmt.Printf("err:%v\ntype1:%T\n", err, candidates)
// output:
// err:<nil>
// type1:*openfec.CandidateIter
}
func ExampleClient_GetCandidates() {
apiKey := os.Getenv("DATA_GOV_API_KEY")
client, err := openfec.NewClient(apiKey)
if err != nil {
log.Fatalln(client)
}
query := &openfec.CandidateQuery{
Sort: "name",
Office: []openfec.Office{openfec.President},
Cycle: []int{2016},
}
candidates, err := client.GetCandidates(query)
if err != nil {
log.Fatalln(err)
}
for candidates.Next() {
c := candidates.Value()
_ = c
// do something with each candidate here
}
fmt.Println(err)
// output:
// <nil>
}