-
Notifications
You must be signed in to change notification settings - Fork 0
/
countries.go
46 lines (41 loc) · 1.01 KB
/
countries.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
package openaq
import (
"context"
"fmt"
"net/url"
)
type CountryArgs struct {
//
BaseArgs BaseArgs
}
func (countryArgs CountryArgs) QueryParams() (url.Values, error) {
q := make(url.Values)
q, err := countryArgs.BaseArgs.Values(q)
if err != nil {
return nil, err
}
return q, nil
}
// GetCountries fetches all countries filtered by any params passed.
func (c *Client) GetCountries(ctx context.Context, countryArgs CountryArgs) (*CountriesResponse, error) {
resp := &CountriesResponse{}
queryParams, err := countryArgs.QueryParams()
if err != nil {
return nil, err
}
err = c.request(ctx, "GET", "/countries", queryParams, resp)
if err != nil {
return nil, err
}
return resp, err
}
// GetCountry fetches a single country by ID.
func (c *Client) GetCountry(ctx context.Context, countriesID int64) (*CountriesResponse, error) {
path := fmt.Sprintf("/countries/%d", countriesID)
resp := &CountriesResponse{}
err := c.request(ctx, "GET", path, nil, resp)
if err != nil {
return nil, err
}
return resp, err
}