forked from danopstech/octopusenergy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
98 lines (87 loc) · 3.33 KB
/
account.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package octopusenergy
import (
"context"
"fmt"
"net/http"
"net/url"
"time"
)
// AccountService handles communication with the tariff related Octopus API.
type AccountService service
// AccountGetOptions is the options for GetTariffCharges.
type AccountGetOptions struct {
// The octopus account number to be retrieved.
AccountNumber string `url:"-"`
}
// AccountGetOutput is the returned struct from GetTariffCharges.
type AccountGetOutput struct {
Number string `json:"number"`
Properties []struct {
ID int `json:"id"`
MovedInAt time.Time `json:"moved_in_at"`
MovedOutAt *time.Time `json:"moved_out_at"`
AddressLine1 string `json:"address_line_1"`
AddressLine2 string `json:"address_line_2"`
AddressLine3 string `json:"address_line_3"`
Town string `json:"town"`
County string `json:"county"`
Postcode string `json:"postcode"`
ElectricityMeterPoints []ElectricityMeterPoints `json:"electricity_meter_points"`
GasMeterPoints []GasMeterPoints `json:"gas_meter_points"`
} `json:"properties"`
}
type ElectricityMeterPoints struct {
MPAN string `json:"mpan"`
ProfileClass int `json:"profile_class"`
ConsumptionStandard int `json:"consumption_standard"`
Meters []struct {
SerialNumber string `json:"serial_number"`
Registers []struct {
Identifier string `json:"identifier"`
Rate string `json:"rate"`
IsSettlementRegister bool `json:"is_settlement_register"`
} `json:"registers"`
} `json:"meters"`
Agreements []struct {
TariffCode string `json:"tariff_code"`
ValidFrom time.Time `json:"valid_from"`
ValidTo *time.Time `json:"valid_to"`
} `json:"agreements"`
}
type GasMeterPoints struct {
MPRN string `json:"mprn"`
ProfileClass int `json:"profile_class"`
ConsumptionStandard int `json:"consumption_standard"`
Meters []struct {
SerialNumber string `json:"serial_number"`
Registers []struct {
Identifier string `json:"identifier"`
Rate string `json:"rate"`
IsSettlementRegister bool `json:"is_settlement_register"`
} `json:"registers"`
} `json:"meters"`
Agreements []struct {
TariffCode string `json:"tariff_code"`
ValidFrom time.Time `json:"valid_from"`
ValidTo *time.Time `json:"valid_to"`
} `json:"agreements"`
}
// Get retrieves the details of an account.
func (s *AccountService) Get(options *AccountGetOptions) (*AccountGetOutput, error) {
return s.GetWithContext(context.Background(), options)
}
// GetWithContext same as Get except it takes a Context
func (s *AccountService) GetWithContext(ctx context.Context, options *AccountGetOptions) (*AccountGetOutput, error) {
path := fmt.Sprintf("/v1/accounts/%s/", options.AccountNumber)
rel := &url.URL{Path: path}
url := s.client.BaseURL.ResolveReference(rel)
req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
if err != nil {
return nil, err
}
res := AccountGetOutput{}
if err := s.client.sendRequest(req, true, &res); err != nil {
return nil, err
}
return &res, nil
}