-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmeter_point.go
More file actions
57 lines (46 loc) · 1.45 KB
/
meter_point.go
File metadata and controls
57 lines (46 loc) · 1.45 KB
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
53
54
55
56
57
package octopusenergy
import (
"context"
"fmt"
"net/http"
"net/url"
)
// MeterPointService handles communication with the meter point related Octopus API.
type MeterPointService service
// MeterPointGetOptions is the options for GetMeterPoint.
type MeterPointGetOptions struct {
// The electricity meter-point’s MPAN.
MPAN string `url:"-"`
}
// MeterPointGetOutput is the returned struct from GetMeterPoint.
type MeterPointGetOutput struct {
// Grid Supply Point
GSP string `json:"gsp"`
// The electricity meter-point’s MPAN.
MPAN string `json:"mpan"`
// ProfileClass
ProfileClass int `json:"profile_class"`
}
// Get the GSP and profile of a given MPAN.
func (s *MeterPointService) Get(options *MeterPointGetOptions) (*MeterPointGetOutput, error) {
return s.GetWithContext(context.Background(), options)
}
// GetWithContext same as Get except it takes a Context
func (s *MeterPointService) GetWithContext(ctx context.Context, options *MeterPointGetOptions) (*MeterPointGetOutput, error) {
path := fmt.Sprintf("v1/electricity-meter-points/%s", options.MPAN)
rel := &url.URL{Path: path}
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 := MeterPointGetOutput{}
if err := s.client.sendRequest(req, true, &res); err != nil {
return nil, err
}
return &res, nil
}