Skip to content

Commit

Permalink
use refactored method #129
Browse files Browse the repository at this point in the history
  • Loading branch information
srinandan committed Dec 6, 2022
1 parent 9f6d3f2 commit 5b24eb5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions client/res/res.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/apigee/apigeecli/apiclient"
)

//Create
// Create
func Create(name string, resPath string, resourceType string) (respBody []byte, err error) {
if !validate(resourceType) {
return respBody, fmt.Errorf("invalid resource type")
Expand All @@ -35,11 +35,14 @@ func Create(name string, resPath string, resourceType string) (respBody []byte,
q.Set("name", name)
u.RawQuery = q.Encode()
}
respBody, err = apiclient.PostHttpOctet(true, false, u.String(), resPath)
formParams := map[string]string{
"file": resPath,
}
respBody, err = apiclient.PostHttpOctet(true, false, u.String(), formParams)
return respBody, err
}

//Delete
// Delete
func Delete(name string, resourceType string) (respBody []byte, err error) {
if !validate(resourceType) {
return respBody, fmt.Errorf("invalid resource type")
Expand All @@ -50,7 +53,7 @@ func Delete(name string, resourceType string) (respBody []byte, err error) {
return respBody, err
}

//Get
// Get
func Get(name string, resourceType string) (err error) {
if !validate(resourceType) {
return fmt.Errorf("invalid resource type")
Expand All @@ -61,18 +64,21 @@ func Get(name string, resourceType string) (err error) {
return
}

//Update
// Update
func Update(name string, resPath string, resourceType string) (err error) {
if !validate(resourceType) {
return fmt.Errorf("invalid resource type")
}
u, _ := url.Parse(apiclient.BaseURL)
u.Path = path.Join(u.Path, apiclient.GetApigeeOrg(), "environments", apiclient.GetApigeeEnv(), "resourcefiles", resourceType, name)
_, err = apiclient.PostHttpOctet(true, true, u.String(), resPath)
formParams := map[string]string{
"file": resPath,
}
_, err = apiclient.PostHttpOctet(true, true, u.String(), formParams)
return
}

//List
// List
func List(resourceType string) (respBody []byte, err error) {
if resourceType != "" {
if !validate(resourceType) {
Expand All @@ -92,7 +98,7 @@ func List(resourceType string) (respBody []byte, err error) {
return respBody, err
}

//validate returns true is the resource type is valid
// validate returns true is the resource type is valid
func validate(resType string) bool {
//validResourceTypes contains a list of valid resources
var validResourceTypes = [7]string{"js", "jsc", "properties", "java", "wsdl", "xsd", "py"}
Expand Down

0 comments on commit 5b24eb5

Please sign in to comment.