Skip to content

Commit

Permalink
Make OrganizationID config for API client public
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk committed Aug 28, 2018
1 parent 4cd0dc8 commit f1d2944
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type API struct {
APIEmail string
APIUserServiceKey string
BaseURL string
organizationID string
OrganizationID string
headers http.Header
httpClient *http.Client
authType int
Expand Down Expand Up @@ -239,8 +239,8 @@ func (api *API) request(method, uri string, reqBody io.Reader, authType int) (*h
// accountBase is the base URL for endpoints referring to the current user. It exists as a
// parameter because it is not consistent across APIs.
func (api *API) userBaseURL(accountBase string) string {
if api.organizationID != "" {
return "/accounts/" + api.organizationID
if api.OrganizationID != "" {
return "/accounts/" + api.OrganizationID
}
return accountBase
}
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Headers(headers http.Header) Option {
// Railguns) to an organization instead.
func UsingOrganization(orgID string) Option {
return func(api *API) error {
api.organizationID = orgID
api.OrganizationID = orgID
return nil
}
}
Expand Down
18 changes: 9 additions & 9 deletions workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func (api *API) DeleteWorker(requestParams *WorkerRequestParams) (WorkerScriptRe
//
// API reference: https://api.cloudflare.com/#worker-script-delete-worker
func (api *API) deleteWorkerWithName(scriptName string) (WorkerScriptResponse, error) {
if api.organizationID == "" {
if api.OrganizationID == "" {
return WorkerScriptResponse{}, errors.New("organization ID required for enterprise only request")
}
uri := "/accounts/" + api.organizationID + "/workers/scripts/" + scriptName
uri := "/accounts/" + api.OrganizationID + "/workers/scripts/" + scriptName
res, err := api.makeRequest("DELETE", uri, nil)
var r WorkerScriptResponse
if err != nil {
Expand Down Expand Up @@ -128,10 +128,10 @@ func (api *API) DownloadWorker(requestParams *WorkerRequestParams) (WorkerScript
//
// API reference: https://api.cloudflare.com/#worker-script-download-worker
func (api *API) downloadWorkerWithName(scriptName string) (WorkerScriptResponse, error) {
if api.organizationID == "" {
if api.OrganizationID == "" {
return WorkerScriptResponse{}, errors.New("organization ID required for enterprise only request")
}
uri := "/accounts/" + api.organizationID + "/workers/scripts/" + scriptName
uri := "/accounts/" + api.OrganizationID + "/workers/scripts/" + scriptName
res, err := api.makeRequest("GET", uri, nil)
var r WorkerScriptResponse
if err != nil {
Expand All @@ -147,10 +147,10 @@ func (api *API) downloadWorkerWithName(scriptName string) (WorkerScriptResponse,
//
// API reference: https://developers.cloudflare.com/workers/api/config-api-for-enterprise/
func (api *API) ListWorkerScripts() (WorkerListResponse, error) {
if api.organizationID == "" {
if api.OrganizationID == "" {
return WorkerListResponse{}, errors.New("organization ID required for enterprise only request")
}
uri := "/accounts/" + api.organizationID + "/workers/scripts"
uri := "/accounts/" + api.OrganizationID + "/workers/scripts"
res, err := api.makeRequest("GET", uri, nil)
if err != nil {
return WorkerListResponse{}, errors.Wrap(err, errMakeRequestError)
Expand Down Expand Up @@ -189,10 +189,10 @@ func (api *API) UploadWorker(requestParams *WorkerRequestParams, data string) (W
//
// API reference: https://api.cloudflare.com/#worker-script-upload-worker
func (api *API) uploadWorkerWithName(scriptName string, data string) (WorkerScriptResponse, error) {
if api.organizationID == "" {
if api.OrganizationID == "" {
return WorkerScriptResponse{}, errors.New("organization ID required for enterprise only request")
}
uri := "/accounts/" + api.organizationID + "/workers/scripts/" + scriptName
uri := "/accounts/" + api.OrganizationID + "/workers/scripts/" + scriptName
api.headers.Add("Content-Type", "application/javascript")
res, err := api.makeRequest("PUT", uri, []byte(data))
var r WorkerScriptResponse
Expand All @@ -207,7 +207,7 @@ func (api *API) uploadWorkerWithName(scriptName string, data string) (WorkerScri
}

func getRoutesPathComponent(api *API) string {
if api.organizationID == "" {
if api.OrganizationID == "" {
return "filters"
}
return "routes"
Expand Down

0 comments on commit f1d2944

Please sign in to comment.