-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
48 lines (39 loc) · 861 Bytes
/
client.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
48
package main
import (
"io/ioutil"
"net/http"
)
// Client represents a Meetup API v3 client.
type Client struct {
APIKey string
APIURL string
client http.Client
}
// FindGroups searches for groups in Meetup.
func (c *Client) FindGroups(country, text string) (string, error) {
r, err := http.NewRequest("GET", c.APIURL+"/find/groups", nil)
if err != nil {
return "", err
}
q := r.URL.Query()
q.Add("key", c.APIKey)
q.Add("country", country)
q.Add("text", text)
r.URL.RawQuery = q.Encode()
response, err := c.client.Do(r)
if err != nil {
return "", err
}
groups, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
return string(groups), nil
}
// NewClient creates a new Client with an API key.
func NewClient(apiKey string) *Client {
return &Client{
APIKey: apiKey,
APIURL: "https://api.meetup.com",
}
}