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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
// Copyright (c) 2015 Serge Gebhardt. All rights reserved.
//
// Use of this source code is governed by the ISC
// license that can be found in the LICENSE file.
package acd
import (
"net/http"
"net/url"
"time"
)
// AccountService provides access to the account related functions
// in the Amazon Cloud Drive API.
//
// See: https://developer.amazon.com/public/apis/experience/cloud-drive/content/account
type AccountService struct {
client *Client
}
// AccountEndpoints represents information about the current customer's endpoints
type AccountEndpoints struct {
CustomerExists bool `json:"customerExists"`
ContentURL string `json:"contentUrl"`
MetadataURL string `json:"metadataUrl"`
}
// GetEndpoints retrives the current endpoints for this customer
//
// It also updates the endpoints in the client
func (s *AccountService) GetEndpoints() (*AccountEndpoints, *http.Response, error) {
req, err := s.client.NewMetadataRequest("GET", "account/endpoint", nil)
if err != nil {
return nil, nil, err
}
endpoints := &AccountEndpoints{}
resp, err := s.client.Do(req, endpoints)
if err != nil {
return nil, resp, err
}
// Update the client endpoints
if endpoints.MetadataURL != "" {
u, err := url.Parse(endpoints.MetadataURL)
if err == nil {
s.client.MetadataURL = u
}
}
if endpoints.ContentURL != "" {
u, err := url.Parse(endpoints.ContentURL)
if err == nil {
s.client.ContentURL = u
}
}
return endpoints, resp, err
}
// AccountInfo represents information about an Amazon Cloud Drive account.
type AccountInfo struct {
TermsOfUse *string `json:"termsOfUse"`
Status *string `json:"status"`
}
// GetInfo provides information about the current user account like
// the status and the accepted “Terms Of Use”.
func (s *AccountService) GetInfo() (*AccountInfo, *http.Response, error) {
req, err := s.client.NewMetadataRequest("GET", "account/info", nil)
if err != nil {
return nil, nil, err
}
accountInfo := &AccountInfo{}
resp, err := s.client.Do(req, accountInfo)
if err != nil {
return nil, resp, err
}
return accountInfo, resp, err
}
// AccountQuota represents information about the account quotas.
type AccountQuota struct {
Quota *uint64 `json:"quota"`
LastCalculated *time.Time `json:"lastCalculated"`
Available *uint64 `json:"available"`
}
// GetQuota gets account quota and storage availability information.
func (s *AccountService) GetQuota() (*AccountQuota, *http.Response, error) {
req, err := s.client.NewMetadataRequest("GET", "account/quota", nil)
if err != nil {
return nil, nil, err
}
accountQuota := &AccountQuota{}
resp, err := s.client.Do(req, accountQuota)
if err != nil {
return nil, resp, err
}
return accountQuota, resp, err
}
// AccountUsage represents information about the account usage.
type AccountUsage struct {
LastCalculated *time.Time `json:"lastCalculated"`
Other *CategoryUsage `json:"other"`
Doc *CategoryUsage `json:"doc"`
Photo *CategoryUsage `json:"photo"`
Video *CategoryUsage `json:"video"`
}
// CategoryUsage defines Total and Billable UsageNumbers
type CategoryUsage struct {
Total *UsageNumbers `json:"total"`
Billable *UsageNumbers `json:"billable"`
}
// UsageNumbers defines Bytes and Count for a metered count
type UsageNumbers struct {
Bytes *uint64 `json:"bytes"`
Count *uint64 `json:"count"`
}
// GetUsage gets Account Usage information broken down by content category.
func (s *AccountService) GetUsage() (*AccountUsage, *http.Response, error) {
req, err := s.client.NewMetadataRequest("GET", "account/usage", nil)
if err != nil {
return nil, nil, err
}
accountUsage := &AccountUsage{}
resp, err := s.client.Do(req, accountUsage)
if err != nil {
return nil, resp, err
}
return accountUsage, resp, err
}
|