|
| 1 | +package edgegrid |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | + "net/http" |
| 7 | + "os" |
| 8 | + "time" |
| 9 | +) |
| 10 | + |
| 11 | +// PropertyService represents exposed services to manage properties |
| 12 | +// |
| 13 | +// Akamai API docs: https://developer.akamai.com/api/luna/papi |
| 14 | +type ReportingAPIService struct { |
| 15 | + client *Client |
| 16 | +} |
| 17 | + |
| 18 | +type ReportingAPIGroup struct { |
| 19 | + GroupName string `json:"groupName"` |
| 20 | + GroupID string `json:"groupId"` |
| 21 | + ContractIds []string `json:"contractIds"` |
| 22 | +} |
| 23 | + |
| 24 | +type ReportingAPIGroups struct { |
| 25 | + AccountID string `json:"accountId"` |
| 26 | + AccountName string `json:"accountName"` |
| 27 | + Groups struct { |
| 28 | + Items []ReportingAPIGroup `json:"items"` |
| 29 | + } `json:"groups"` |
| 30 | +} |
| 31 | + |
| 32 | +type ReportingAPIContract struct { |
| 33 | + ContractID string `json:"contractId"` |
| 34 | + ContractTypeName string `json:"contractTypeName"` |
| 35 | +} |
| 36 | + |
| 37 | +type ReportingAPIContracts struct { |
| 38 | + AccountID string `json:"accountId"` |
| 39 | + Contracts struct { |
| 40 | + Items []ReportingAPIContract `json:"items"` |
| 41 | + } `json:"contracts"` |
| 42 | +} |
| 43 | + |
| 44 | +type ReportingAPIProduct struct { |
| 45 | + ProductName string `json:"productName"` |
| 46 | + ProductID string `json:"productId"` |
| 47 | +} |
| 48 | + |
| 49 | +type ReportingAPIProducts struct { |
| 50 | + AccountID string `json:"accountId"` |
| 51 | + ContractID string `json:"contractId"` |
| 52 | + Products struct { |
| 53 | + Items []ReportingAPIProduct `json:"items"` |
| 54 | + } `json:"products"` |
| 55 | +} |
| 56 | + |
| 57 | +type ReportingAPICPCodeNew struct { |
| 58 | + ProductID string `json:"productId"` |
| 59 | + CpcodeName string `json:"cpcodeName"` |
| 60 | +} |
| 61 | + |
| 62 | +type ReportingAPICPCode struct { |
| 63 | + CpcodeID string `json:"cpcodeId"` |
| 64 | + CpcodeName string `json:"cpcodeName"` |
| 65 | + ProductIds []string `json:"productIds"` |
| 66 | + CreatedDate time.Time `json:"createdDate"` |
| 67 | +} |
| 68 | + |
| 69 | +type ReportingAPICPCodes struct { |
| 70 | + AccountID string `json:"accountId"` |
| 71 | + ContractID string `json:"contractId"` |
| 72 | + GroupID string `json:"groupId"` |
| 73 | + Cpcodes struct { |
| 74 | + Items []ReportingAPICPCode `json:"items"` |
| 75 | + } `json:"cpcodes"` |
| 76 | +} |
| 77 | + |
| 78 | +type ReportingAPICPEdgehost struct { |
| 79 | + EdgeHostnameID string `json:"edgeHostnameId"` |
| 80 | + EdgeHostnameDomain string `json:"edgeHostnameDomain"` |
| 81 | + ProductID string `json:"productId"` |
| 82 | + DomainPrefix string `json:"domainPrefix"` |
| 83 | + DomainSuffix string `json:"domainSuffix"` |
| 84 | + Secure bool `json:"secure"` |
| 85 | + IPVersionBehavior string `json:"ipVersionBehavior"` |
| 86 | + MapDetailsSerialNumber int `json:"mapDetails:serialNumber"` |
| 87 | + MapDetailsMapDomain string `json:"mapDetails:mapDomain"` |
| 88 | +} |
| 89 | + |
| 90 | +type ReportingAPICPEdgehosts struct { |
| 91 | + AccountID string `json:"accountId"` |
| 92 | + ContractID string `json:"contractId"` |
| 93 | + GroupID string `json:"groupId"` |
| 94 | + EdgeHostnames struct { |
| 95 | + Items []ReportingAPICPEdgehost `json:"items"` |
| 96 | + } `json:"edgeHostnames"` |
| 97 | +} |
| 98 | + |
| 99 | +func (pas *ReportingAPIService) GenerateReportRequest() { |
| 100 | + req, err := http.NewRequest("GET", "http://api.themoviedb.org/3/tv/popular", nil) |
| 101 | + if err != nil { |
| 102 | + log.Print(err) |
| 103 | + os.Exit(1) |
| 104 | + } |
| 105 | + |
| 106 | + q := req.URL.Query() |
| 107 | + q.Add("api_key", "key_from_environment_or_flag") |
| 108 | + q.Add("another_thing", "foo & bar") |
| 109 | + req.URL.RawQuery = q.Encode() |
| 110 | + |
| 111 | + fmt.Println(req.URL.String()) |
| 112 | + // Output: |
| 113 | + // http://api.themoviedb.org/3/tv/popular?another_thing=foo+%26+bar&api_key=key_from_environment_or_flag |
| 114 | +} |
| 115 | + |
| 116 | +// ListReportingAPIContracts This operation provides a read-only list of contract names and identifiers |
| 117 | +// |
| 118 | +// Akamai API docs: https://developer.akamai.com/api/luna/papi/resources.html#getcontracts |
| 119 | +func (pas *ReportingAPIService) ListReportingAPIContracts() (*ReportingAPIContracts, *ClientResponse, error) { |
| 120 | + |
| 121 | + apiURI := fmt.Sprintf("%s/contracts", apiPaths["papi_v1"]) |
| 122 | + |
| 123 | + var k *ReportingAPIContracts |
| 124 | + resp, err := pas.client.NewRequest("GET", apiURI, nil, &k) |
| 125 | + if err != nil { |
| 126 | + return nil, resp, err |
| 127 | + } |
| 128 | + |
| 129 | + return k, resp, err |
| 130 | + |
| 131 | +} |
| 132 | + |
| 133 | +// ListReportingAPIGroups This operation provides a read-only list of groups, which may contain properties. |
| 134 | +// |
| 135 | +// Akamai API docs: https://developer.akamai.com/api/luna/papi/resources.html#getgroups |
| 136 | +func (pas *ReportingAPIService) ListReportingAPIGroups() (*ReportingAPIGroups, *ClientResponse, error) { |
| 137 | + |
| 138 | + apiURI := fmt.Sprintf("%s/groups", apiPaths["papi_v1"]) |
| 139 | + |
| 140 | + var k *ReportingAPIGroups |
| 141 | + resp, err := pas.client.NewRequest("GET", apiURI, nil, &k) |
| 142 | + if err != nil { |
| 143 | + return nil, resp, err |
| 144 | + } |
| 145 | + |
| 146 | + return k, resp, err |
| 147 | + |
| 148 | +} |
| 149 | + |
| 150 | +// ListReportingAPICPCodes This operation lists CP codes available within your contract/group pairing. |
| 151 | +// |
| 152 | +// Akamai API docs: https://developer.akamai.com/api/luna/papi/resources.html#getcpcodes |
| 153 | +func (pas *ReportingAPIService) ListReportingAPICPCodes(contractID, groupID string) (*ReportingAPICPCodes, *ClientResponse, error) { |
| 154 | + |
| 155 | + apiURI := fmt.Sprintf("%s/cpcodes?contractId=%s&groupId=%s", |
| 156 | + apiPaths["papi_v1"], |
| 157 | + contractID, |
| 158 | + groupID) |
| 159 | + |
| 160 | + var k *ReportingAPICPCodes |
| 161 | + resp, err := pas.client.NewRequest("GET", apiURI, nil, &k) |
| 162 | + if err != nil { |
| 163 | + return nil, resp, err |
| 164 | + } |
| 165 | + |
| 166 | + return k, resp, err |
| 167 | + |
| 168 | +} |
| 169 | + |
| 170 | +// ListReportingAPIProducts ListReportingAPIProducts. |
| 171 | +// |
| 172 | +// Akamai API docs: https://developer.akamai.com/api/luna/papi/resources.html#getcpcodes |
| 173 | +func (pas *ReportingAPIService) ListReportingAPIProducts(contractId string) (*ReportingAPIProducts, *ClientResponse, error) { |
| 174 | + |
| 175 | + apiURI := fmt.Sprintf("%s/products?contractId=%s", |
| 176 | + apiPaths["papi_v1"], |
| 177 | + contractId) |
| 178 | + |
| 179 | + var k *ReportingAPIProducts |
| 180 | + resp, err := pas.client.NewRequest("GET", apiURI, nil, &k) |
| 181 | + if err != nil { |
| 182 | + return nil, resp, err |
| 183 | + } |
| 184 | + |
| 185 | + return k, resp, err |
| 186 | + |
| 187 | +} |
| 188 | + |
| 189 | +// NewReportingAPICPcode Creates new CP Code |
| 190 | +// |
| 191 | +// Akamai API docs: https://developer.akamai.com/api/luna/papi/resources.html#postcpcodes |
| 192 | +func (pas *ReportingAPIService) NewReportingAPICPcode(newCPcode *ReportingAPICPCodeNew, contractID, groupID string) (*ClientResponse, error) { |
| 193 | + |
| 194 | + apiURI := fmt.Sprintf("%s/cpcodes?contractId=%s&groupId=%s", |
| 195 | + apiPaths["papi_v1"], |
| 196 | + contractID, |
| 197 | + groupID) |
| 198 | + |
| 199 | + resp, err := pas.client.NewRequest("POST", apiURI, newCPcode, nil) |
| 200 | + if err != nil { |
| 201 | + return resp, err |
| 202 | + } |
| 203 | + |
| 204 | + return resp, err |
| 205 | + |
| 206 | +} |
| 207 | + |
| 208 | +// ListReportingAPICPEdgehosts This lists all edge hostnames available under a contract.. |
| 209 | +// |
| 210 | +// Akamai API docs: https://developer.akamai.com/api/luna/papi/resources.html#getedgehostnames |
| 211 | +func (pas *ReportingAPIService) ListReportingAPICPEdgehosts(contractId string) (*ReportingAPICPEdgehosts, *ClientResponse, error) { |
| 212 | + |
| 213 | + apiURI := fmt.Sprintf("%s/edgehostnames?contractId=%s&groupId=%s&options=mapDetails", |
| 214 | + apiPaths["papi_v1"], |
| 215 | + contractId) |
| 216 | + |
| 217 | + var k *ReportingAPICPEdgehosts |
| 218 | + resp, err := pas.client.NewRequest("GET", apiURI, nil, &k) |
| 219 | + if err != nil { |
| 220 | + return nil, resp, err |
| 221 | + } |
| 222 | + |
| 223 | + return k, resp, err |
| 224 | + |
| 225 | +} |
0 commit comments