Debian Codegraph @

fastly/billing.go

raw symbols SCIP
1 package fastly
2
3 import (
4 "fmt"
5 "time"
6 )
7
8 // Billing is the top-level representation of a billing response from the Fastly
9 // API.
10 type Billing struct {
11 InvoiceID string `mapstructure:"invoice_id"`
12 StartTime *time.Time `mapstructure:"start_time"`
13 EndTime *time.Time `mapstructure:"end_time"`
14 Status *BillingStatus `mapstructure:"status"`
15 Total *BillingTotal `mapstructure:"total"`
16 }
17
18 // BillingStatus is a representation of the status of the bill from the Fastly
19 // API.
20 type BillingStatus struct {
21 InvoiceID string `mapstructure:"invoice_id"`
22 Status string `mapstructure:"status"`
23 SentAt *time.Time `mapstructure:"sent_at"`
24 }
25
26 // BillingTotal is a repsentation of the status of the usage for this bill from
27 // the Fastly API.
28 type BillingTotal struct {
29 PlanName string `mapstructure:"plan_name"`
30 PlanCode string `mapstructure:"plan_code"`
31 PlanMinimum string `mapstructure:"plan_minimum"`
32 Bandwidth float64 `mapstructure:"bandwidth"`
33 BandwidthCost float64 `mapstructure:"bandwidth_cost"`
34 Requests uint64 `mapstructure:"requests"`
35 RequestsCost float64 `mapstructure:"requests_cost"`
36 IncurredCost float64 `mapstructure:"incurred_cost"`
37 Overage float64 `mapstructure:"overage"`
38 Extras []*BillingExtra `mapstructure:"extras"`
39 ExtrasCost float64 `mapstructure:"extras_cost"`
40 CostBeforeDiscount float64 `mapstructure:"cost_before_discount"`
41 Discount float64 `mapstructure:"discount"`
42 Cost float64 `mapstructure:"cost"`
43 Terms string `mapstructure:"terms"`
44 }
45
46 // BillingExtra is a representation of extras (such as SSL addons) from the
47 // Fastly API.
48 type BillingExtra struct {
49 Name string `mapstructure:"name"`
50 Setup float64 `mapstructure:"setup"`
51 Recurring float64 `mapstructure:"recurring"`
52 }
53
54 // GetBillingInput is used as input to the GetBilling function.
55 type GetBillingInput struct {
56 Year uint16
57 Month uint8
58 }
59
60 // GetBilling returns the billing information for the current account.
61 func (c *Client) GetBilling(i *GetBillingInput) (*Billing, error) {
62 if i.Year == 0 {
63 return nil, ErrMissingYear
64 }
65
66 if i.Month == 0 {
67 return nil, ErrMissingMonth
68 }
69
70 path := fmt.Sprintf("/billing/year/%d/month/%02d", i.Year, i.Month)
71 resp, err := c.Get(path, nil)
72 if err != nil {
73 return nil, err
74 }
75
76 var b *Billing
77 if err := decodeJSON(&b, resp.Body); err != nil {
78 return nil, err
79 }
80 return b, nil
81 }