| 1 |
package fastly |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"time" |
| 6 |
) |
| 7 |
|
| 8 |
|
| 9 |
|
| 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 |
|
| 19 |
|
| 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 |
|
| 27 |
|
| 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 |
|
| 47 |
|
| 48 |
type BillingExtra struct { |
| 49 |
Name string `mapstructure:"name"` |
| 50 |
Setup float64 `mapstructure:"setup"` |
| 51 |
Recurring float64 `mapstructure:"recurring"` |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
type GetBillingInput struct { |
| 56 |
Year uint16 |
| 57 |
Month uint8 |
| 58 |
} |
| 59 |
|
| 60 |
|
| 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 |
} |