-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
grid_supply_point.go
52 lines (43 loc) · 1.55 KB
/
grid_supply_point.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
49
50
51
52
package octopusenergy
import (
"context"
"net/http"
"net/url"
)
// GridSupplyPointService handles communication with the grid supply point related Octopus API.
type GridSupplyPointService service
// GridSupplyPointGetOptions is the options for GetGridSupplyPoint.
type GridSupplyPointGetOptions struct {
// A postcode to filter on.
// If Octopus are unable to map the passed postcode to a GSP, an empty list will be returned.
Postcode *string `url:"postcode,omitempty" optional:"true"`
}
// GridSupplyPointGetOutput is the returned struct from GetGridSupplyPoint.
type GridSupplyPointGetOutput struct {
Count int `json:"count"`
Results []struct {
GroupID string `json:"group_id"`
} `json:"results"`
}
// Get gets the GSP and group ID, filtered by postcode if one is given.
func (s *GridSupplyPointService) Get(options *GridSupplyPointGetOptions) (*GridSupplyPointGetOutput, error) {
return s.GetWithContext(context.Background(), options)
}
// GetWithContext same as Get except it takes a Context.
func (s *GridSupplyPointService) GetWithContext(ctx context.Context, options *GridSupplyPointGetOptions) (*GridSupplyPointGetOutput, error) {
rel := &url.URL{Path: "v1/industry/grid-supply-points"}
u := s.client.BaseURL.ResolveReference(rel)
url, err := addParameters(u, options)
if err != nil {
return nil, err
}
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
if err != nil {
return nil, err
}
res := GridSupplyPointGetOutput{}
if err := s.client.sendRequest(req, false, &res); err != nil {
return nil, err
}
return &res, nil
}