@@ -2,7 +2,7 @@ package api
22
33import (
44 "fmt"
5- "strings "
5+ "net/url "
66)
77
88//some of the api calls will be common for different objects
@@ -53,9 +53,9 @@ func (api *Api) GetObjectRefFromGroup(objectGroup, objectName string, groupID, o
5353
5454// GetObjectByName will return the object (json) specified by objectName and name
5555func (api * Api ) GetObjectByName (objectName string , name string ) (string , error ) {
56- // In go %% is % escaped, we need to escape the name to work with string fmt .
57- name = strings . Replace (name , "%" , "%%" , - 1 )
58- name = strings . Replace ( name , " " , "%20" , - 1 )
56+ // URL Encoded .
57+ name = url . QueryEscape (name )
58+
5959 var result string
6060 if err := api .makeCall ("GET" , fmt .Sprintf ("/api/v1/app/%s/%ss/?selectByName=%s" , api .AppID , objectName , name ), nil , true , & result ); err != nil {
6161 return "" , err
@@ -65,9 +65,9 @@ func (api *Api) GetObjectByName(objectName string, name string) (string, error)
6565
6666// GetObejctRefByName will put in result a reference to the oject specified by objectName and name
6767func (api * Api ) GetObejctRefByName (objectName string , name string , result Object ) error {
68- // In go %% is % escaped, we need to escape the name to work with string fmt .
69- name = strings . Replace (name , "%" , "%%" , - 1 )
70- name = strings . Replace ( name , " " , "%20" , - 1 )
68+ // URL Encoded .
69+ name = url . QueryEscape (name )
70+
7171 objects := []* Object {& result }
7272 if err := api .makeCall ("GET" , fmt .Sprintf ("/api/v1/app/%s/%ss/?selectByName=%s" , api .AppID , objectName , name ), nil , false , & objects ); err != nil {
7373 return err
@@ -81,9 +81,9 @@ func (api *Api) GetObejctRefByName(objectName string, name string, result Object
8181
8282// GetObejctRefByNameFromGroup will return the object specified by objectName from objectGroup that have a certain name
8383func (api * Api ) GetObejctRefByNameFromGroup (objectGroup , objectName string , groupID int64 , name string , result Object ) error {
84- // In go %% is % escaped, we need to escape the name to work with string fmt .
85- name = strings . Replace (name , "%" , "%%" , - 1 )
86- name = strings . Replace ( name , " " , "%20" , - 1 )
84+ // URL Encoded .
85+ name = url . QueryEscape (name )
86+
8787 objects := []* Object {& result }
8888 if err := api .makeCall ("GET" , fmt .Sprintf ("/api/v1/app/%s/%ss/%d/%ss/?selectByName=%s" , api .AppID , objectGroup , groupID , objectName , name ), nil , false , & objects ); err != nil {
8989 return err
0 commit comments